Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Saandman

Sending messages to a window without focus

This topic is 5224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!