Sending messages to a window without focus

Started by
4 comments, last by Saandman 19 years, 10 months ago
I''m developing a small app that installs a system-wide keyboard hook and save screen shots when you press prt scr. It works great on Windows NT 4/XP (w/ WH_KEYBOARD_LL hook), but when I use it on an earlier OS such as Windows 98 or ME (WH_KEYBOARD hook) I''m only able to send messages from the hook dll to the mfc application when the app has FOCUS. Whenever I minimize the app or change focus to another window, the sendmessage call fails or isn''t called. I''ve tried setting focus back and forth between sendmessage calls with no success. I''ve also tried PostMessage, PostThreadMessage, CallWndProc, ... Ideas?
________________________________pro.gram.mer - an organism that turns caffeine into code
Advertisement
*bump*

I''ve searched my butt off here on the forums and on other sites, what''s the deal with windows 9x/ME? Need I go via the process'' thread? Is it in fact impossible to send messages to a background window? That sounds.. silly
________________________________pro.gram.mer - an organism that turns caffeine into code
I made a little program to send keyboard messages to notepad just for the hell of it awhile ago. (I'm on win98se) The window never had to be in focus.

int main(int argc, char *argv[]){    HWND RSHwnd = NULL;     //window handle    HWND SubHwnd = NULL;    //sub window handle    //find the notepad window    RSHwnd = FindWindow(NULL,"Untitled - Notepad");    SubHwnd = GetWindow(RSHwnd,GW_CHILD);    //if we couldn't find the notepad window,    //bail out    if (RSHwnd == NULL || SubHwnd == NULL)    {        cout << "Couldn't find a handle to the notepad window.\n\n" << endl;        system("PAUSE");        return 0;    }    //show starting message    cout << "This program will continually send messages to the notepad\n"    << "window until you quit, by pressing any key.\n\n" << endl;    int     nCount = 0;     //how many messages sent    //loop while no key is pressed    while (!kbhit())    {        //show count and message        cout << nCount << " - Sending message..." << endl;        //post the message        PostMessage(SubHwnd,WM_CHAR,0x31,0x20001);        nCount++;        Sleep(6000); //wait 6 seconds    }    return 0;}


[edited by - Vampyre_Dark on June 6, 2004 7:29:06 AM]
Thanks for your reply,

I wrote an app with a single window and a DLL file from within I send a WM_USER+101 message to the window every 2 seconds. And it works like your app, both when the window has focus and when it hasn''t.. In xp and 98/se. So the problem has got to be in my code.

It''s MFC dialog based btw. Does appwizard generated MFC apps go idle when they loose focus or summit? lol
________________________________pro.gram.mer - an organism that turns caffeine into code
i think the problem might be the difference between the hook types you''re using. WH_KEYBOARD_LL is low level and therefore gets all keyings before any other app, whereas WH_KEYBOARD only gets those keyings not already filtered out by other low level apps, such as the OS app that processes "special" keys like Alt+Tab and Print Screen. in NT-based versions of Windows this processing is handled by CSRSS; i''m not sure what app handles it in 9x-based versions.

have you tried switching to another key or key sequence to see if the problem goes away? there really is nothing which prevents a window from receiving a window message, whether it''s in focus or not, written in MFC or not.
AP,

Well I know for sure that I''m successfully intercepting the button press. I put message boxes and such to make sure, and they show up alright.

:l
________________________________pro.gram.mer - an organism that turns caffeine into code

This topic is closed to new replies.

Advertisement