Sending a message to a process

I like to send a message to a process main window.
I can get the process id with Process32First etc but then I'd like to send that process a message, for that I need the handle of the main window.
So my question is: How do I get a handle to the main window from the process id?

LVL 3
LucHoltkampAsked:
Who is Participating?
 
WynConnect With a Mentor Commented:
Try Thread32First() first and EnumThreadWindows()...

Regards
W.Yinan
0
 
MichaelSCommented:
If you know that process than you probably know the class of main window. If so you can use FindWindow() API.
0
 
LucHoltkampAuthor Commented:
Thanks for the reaction!
The problem with FindWindow is that MFC registrates the window class, and it's the same for all windows MFC creates....
So you can only select on Window title and that's not very reliable (the name changes in a SDI/MDI app).
Unfortunatly, it takes a lot of code to find the window, but it works and that is what counts...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.