Computing.Net > Forums > Programming > GetMessage function

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

GetMessage function

Reply to Message Icon

Name: saddam (by lurker)
Date: February 15, 2006 at 20:20:56 Pacific
Comment:

Hi all,

Does the GetMesage function in Windows App retrives messages for windows created by the program (executable) it is used in or does it read the message queue from all programs running on the system?

Will this work

MSG msg;
HWND otherWnd;
..............

otherWnd = FindWindow(NULL, "My Window Title");

..............
while(GetMessage(&msg, otherWnd, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

So what it does is it processes messages from other windows by getting their handles (using FindWindow etc.) including those created by other executables. Is it possible?




Sponsored Link
Ads by Google

Response Number 1
Name: geohoffman49431
Date: February 16, 2006 at 02:52:46 Pacific
Reply:

"The GetMessage function retrieves a message from the calling thread's message queue. The function dispatches incoming sent messages until a posted message is available for retrieval. "

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/messagesandmessagequeues/messagesandmessagequeuesreference/messagesandmessagequeuesfunctions/getmessage.asp

Just the program or thread that is running - GetMessge does not get all system messages. There are few applications for a program getting all system messages. Like if you run your program and click in a different window that message should not be sent to your program, mostly because there is little reason to do so. It is possible to get messages from other threads but it has been a while since I did anything like that.

I think the general procedure to do that is something like get a handle to the seperate thread and then look into its message queue.
Something like that is usefull if you are trying to write a keylogger ;). But I was using it to take keyboard input and redirrect it to another program. It was sort of like a program that could be used to create shortcut keys for another aplication. For instance at a job I had to use wave editor software and save hundreds of small wave files using complex naming conventions. I wrote a program that scanned for keyboard input and when I pressed a specific combinaiton of keys it would place messages in the message queue for the wave editor program. So those messages would simulate hiting the save button, typing the name of the file, and hitting done. So with my program I was able to hit a combination of 3 keys instead of 30 keys for each wave file. Saved me from a lot of tedium.


0

Response Number 2
Name: saddam (by lurker)
Date: February 16, 2006 at 22:25:26 Pacific
Reply:

Thanks for that info.

Check this out

http://msdn.microsoft.com/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Windows/WindowReference/WindowFunctions/GetWindowThreadProcessId.asp

If I'm right perhaps the GetWindowThreadProcessId would do it or is it not as easy as I think?


0

Response Number 3
Name: geohoffman49431
Date: February 17, 2006 at 12:26:34 Pacific
Reply:

what exactly are you trying to do? It has been a while since I did any windows specific programming but if you tell me what functionality you want maybe I can help you with that. If you want a program to process other programs messages I thing you have to use a system hook, then insert those messages into your programs message queue.

http://www.codeproject.com/csharp/GlobalSystemHook.asp

"In case you are not familiar with the concept of system hooks in Windows, let me state a few brief descriptions:

A system hook allows you to insert a callback function which intercepts certain Windows messages (e.g., mouse related messages).
A local system hook is a system hook that is called only when the specified messages are processed by a single thread.
A global system hook is a system hook that is called when the specified messages are processed by any application on the entire system. "

Is that what you are looking for?

So a system hook is a dll that sort of waits for certain types of messages. When that message occurs you can set the dll up to call whatever function you want in your program or the dll can do processing just like any other windows program. For instance the user presses the space bar, the dll catches this message from inside the dll. The dll figure out what key was pressed and generates the string "The space bar has been pressed." It then it calls a function inside your program and passes it the string it generated. Or you could just pass to your program the ascii character code of the key that has been pressed. You could then do what ever you want with that information.


0

Response Number 4
Name: saddam (by lurker)
Date: February 17, 2006 at 22:58:55 Pacific
Reply:


Well to be honest actually I was wondering if I could prevent people from clicking the ZoneAlarm icon in the system tray by trapping mouse events and redirecting it to my program.

Very often users on my computer try to close it. (ie. right click -> Shutdown ZoneAlarm Pro)

I have search online for a simpler solution but to no avail.


0

Response Number 5
Name: saddam (by lurker)
Date: February 17, 2006 at 23:11:49 Pacific
Reply:

I would presume doing so would not affect the functionality of ZoneAlarm as its security mechanisms still run on as a seperate thread or a process in the background.

To enable me to access ZA's settings, I simply kill my process. My computer users are not smart enough to know that. In addition I can disable the task manager.


0

Related Posts

See More



Response Number 6
Name: geohoffman49431
Date: February 24, 2006 at 00:55:00 Pacific
Reply:

There has to be a better solution or a setting rather than writing a program. Does zone alarm work if you log on as administrator, and then switch to a different user account? They should not be able to stop the program if they are not admin. dunno, just a thought. Other than that there should be a setting to not show the icon in the task bar if ZA is worth anything - but I dont know I never used it. Sorry I could not be more help.


0

Response Number 7
Name: stcc
Date: March 8, 2006 at 02:04:50 Pacific
Reply:

Hi geohoffman,

I am using system hook to insert a callback function which intercepts a Windows message (when the user open a IE window). I have a problem in using the GetMessage function where the while loop for this function seems to be only working for once, then it will just end the program even though in my code, there is no WM_QUIT message at all. I have the impression that this is related to the system hook I am using. But I don't know where is the wrong bit. Would be great if you can help.

Thanks,
S.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: GetMessage function

VBA math function for time dilation www.computing.net/answers/programming/vba-math-function-for-time-dilation/6177.html

functions to share a directory www.computing.net/answers/programming/functions-to-share-a-directory/83.html

help with an Scheme function www.computing.net/answers/programming/help-with-an-scheme-function/4860.html