I am a beginner in C++ (always been a C#) and I was put in to troublshooting/update on of our legacy program written in C++.
I have a process name “setup.exe” that runs on window and I knew how to find its HANDLE and DWORD process id. I know it has a window for sure but I can’t seem to find out how to bring this window to a foreground and that is what I am trying to do: To bring a window to a foreground using its process name.
Upon reading on the internet I came to the following algorithm which i’m also not sure is the proper way to do it:
- Find the process ID from the process name.
- Enumerate all the windows which belong to this process ID using EnumWindows
- the above step will give me the window handle(s) variable of type – HWND
- I can set focus or set the foreground by passing in this HWND variable.
My problem here is syntax wise, I don’t really know how to begin to write up enumwindows, can anybody point me toward a set of sample code or if you have any pointer to how I should approach this issue?
Thank you.
The EnumWindows procedure evaluates all top level windows. If you are sure the window you are looking for is top level, you can use this code:
Then just call
BringToForegroundwith the process ID you want.DISCLAIMER: not tested but should work 🙂