Hi all,
I am trying to use PeekMessage to detect messages other than WM_QUIT.. and I can't understand PeekMessage. What's this first and last parameter stuff? I don't understand the documentation. Also, I would love to know how to send messages to different controls but I don't know how to go about it. Let's say I know the Style and Class Name of the control.. how can I send it a message?
I need the help :'( PeekMessage is annoying me. I know it can be used to get messages from other threads.. But I can't figure out its proper use. For example, trying to find when a WM_KEYDOWN message is posted?
Thanks again!
Hi Brixton. I can't help with PeekMessage, but for sending message to controls, trys:
invoke SendDlgItemMessage,hWnd,nIDControl,wMsg,wParam,lParam
Here are a few examples of using PeekMessage.
invoke PeekMessage, ADDR spmsg, hWnd, WM_KEYDOWN, WM_KEYDOWN, PM_NOREMOVE
.if eax != 0
.if spmsg.wParam == VK_ESCAPE
The above looks only for KEYDOWN messages being sent to hWnd but would NOT remove them from the message queue.
invoke PeekMessage, ADDR spmsg, hWnd, WM_LBUTTONDOWN, WM_RBUTTONDBLCLK, PM_REMOVE
The above looks for ALL the mouse click messages sent to hWnd AND removes them from the message queue.
invoke PeekMessage, ADDR spmsg, 0, 0, 0, PM_REMOVE
.if eax != 0
invoke TranslateMessage,ADDR spmsg
.if spmsg.message == WM_KEYDOWN
The above looks for ALL messages sent to ALL threads and controls of your process AND removes them from their respective message queues.
All of the above examples were taken from an actual program which worked fine. Hope they help you understand a bit more the hieroglyphs of the PeekMessage description.
Raymond
Thankyou for the examples!
I know each message (ie. WM_KEYDOWN) has a number associated with it -- so for the parameters could I put something like 0 and 100 to accept all messages? How do I know which message is lower than another?
Thanks for the help! :cheekygreen:
The WM_ message names and values are listed in windows.inc that comes with MASM32.
Quote from: brixton on July 01, 2005, 07:12:58 PM
Thankyou for the examples!
I know each message (ie. WM_KEYDOWN) has a number associated with it -- so for the parameters could I put something like 0 and 100 to accept all messages? How do I know which message is lower than another?
Thanks for the help! :cheekygreen:
Use 0 and 0 to accept all messages (as Raymond said :wink)
You can search through windows.inc to see the codes for each of the messages - but not all 'sets' have nice compact ranges.
OK I am still having problems.
msg is a MSG structure, handle is the hWnd, it all assembles correctly. Although it doesn't work..
invoke GetForegroundWindow
mov handle, eax
loopy:
invoke PeekMessage, ADDR msg, handle, WM_KEYDOWN, WM_KEYDOWN, PM_NOREMOVE
cmp eax, 0
je loopy
All/any help appreciated ! Stupid PeekMessage :'(
You do ofcourse realize that you cannot intercept the message queue of a window that is not yours in this way. PeekMessage only works with windows that are owned by the current thread, it appears to me that you are attempting to make a primitive key logger, something that would be frowned upon here. Ofcourse, if you are not, just make sure that the window belongs to your thread.
It doesn't belong to me, and I'm not trying to do anything except work out windows messages - A totally new concept for me!
How would one intercept messages from other applications? An example perhaps would be nice :bg
Apologies for my lack of smarts in this area :'(
Hi brixton,
This is looking more and more like a keylogger, and that is definitely against the rules here. I suggest another line of questioning.
Well the question is about interpreting other windows messages, I don't see how this relates to keylogging at all! Let's say I want to find out when another window minimizes, I can look for the message WM_SYSCOMMAND and go from there. All I want to do is learn more about the messages, how they work, and how one application can interact with another -- something I've not had experience of before.
Apologies if my wording meant you interpreted this the wrong way, and feel free to close, although it won't help my plight :(
you might want to look at the AttachThreadInput (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/attachthreadinput.asp) function.
Quote from: brixton on July 03, 2005, 11:17:42 PMApologies if my wording meant you interpreted this the wrong way, and feel free to close, although it won't help my plight :(
Hi Brixton,
We have discussed the thread in the moderators forum as we do with all suspect threads and decided to keep it open for now. You are seen as an upstanding member here and we are giving you the benefit of the doubt but as I said, this topic treads dangerously close to key logging and will be closed if it degrades to that.
It is unfortunate that many innocent requests have to go unanswered because some would put the information to malicious use, it makes our job as moderators difficult, deciding at what point the information becomes contraban.
That's fair enough -- and thanks for your help. I don't have a clue about window messages, I just sent a message to a button to click (BN_CLICK) and it worked! I had to use ResHacker to get the ID of the button though, is there a better way? I don't like this method because if the EXE is packed or encrypted, obviously sometimes I can't view it's resources.
Also I briefly tried attaching my thread to another thread, using the handle of my window and the handle of the other window, but I couldn't make it work still. I think I'll go trawling for an example!
Quote from: brixton on July 04, 2005, 11:53:52 AM
I had to use ResHacker to get the ID of the button though, is there a better way?
Try WinSpy++ (http://www.catch22.net/software/winspy.asp)
QuoteWinSpy++ is a handy programmer's utility which can be used to select and view the properties of any window in the system.
(at runtime)
And it's even open source (in C) so you can learn a lot about some APIs...