1
Answer

Need help with SendMessage / PostMessage

Ask a question
Paul

Paul

14y
12.6k
1
Need help or a really good tutorial on using PostMessage / SendMessage
I'm using VS2k10 c#
Here is what I am trying to do.

Have a program that you have to press a refresh button, it doesn't have a hotkey so I can't send F5 key to the window so I need to send WM_LBUTTONDOWN and WM_LBUTTONUP on a button. This will be for other people on other machines as well not just mine.
Also as you can see below one of the window text changes with user login creds. idk if this matters or not. Also the window may not always have focus so I need it to issue the click without it being in focus. (Example. split windows or dual monitors, app may not have main focus but it is still viewable)

Now I know I need to grab info from spy++ (*I think anyhow lol*) so here is the run down of the location of the button I want pressed.


 Windows 0008024C "Clientele" Afx:400000:8:10011:0:62044b
- Window 000C027C "" MDIClient
-- Window 000901FC "Main Search Form MY APP LOGIN CREDS SHOW HERE" Afx:400000:b:10011:6:83f02ed
--- Window 000C027C "" AfxFrameOrView42
---- Window 0008028A "Refresh" Button


Here is what I attempted to do before but I know its wrong.

 IntPtr hwnd = FindWindow(null, "Clientele");
IntPtr refresh = FindWindowEx(hwnd, IntPtr.Zero, "Button", "Refresh");
SendMessage(refresh, (int)WMessages.WM_LBUTTONDOWN, 0, 0);
SendMessage(refresh, (int)WMessages.WM_LBUTTONUP, 0, 0);

again no idea if this is correct or if I am in the ball park of this being correct.

Thanks in advance.

Answers (1)