Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To identify the background process & bring to foreground in C++ WIN32

Tags:

c++

winapi

Can anyone tell me how to identify a particular background process (i.e., Already running application) and bring to foreground? For example, if a Notepad application is running in the background, when I run my WIN32 application, it should identify the Notepad application and notepad should pop up or come to foreground.

I tried SwitchToThisWindow() function, but it works like Alt+tab. It will not identify the background process.

Pls suggest me walkthrough guide for this..

Thank you..

like image 213
Guru Avatar asked Jun 13 '12 05:06

Guru


People also ask

How do I find background processes?

If you want to see all of the background processes running on the system, you can use ps -e , or ps -eF to get some additional details. To get more information about what commands are able to do, you can run almost always run man ps (replacing ps with any command) to get the manual page with lots of info.

What are background processes?

A background process is a computer process that runs behind the scenes (i.e., in the background) and without user intervention. Typical tasks for these processes include logging, system monitoring, scheduling, and user notification.

Which command is used to view background processes?

You can use the ps command to list all background process in Linux. Other Linux commands to obtain what processes are running in the background on Linux. top command – Display your Linux server's resource usage and see the processes that are eating up most system resources such as memory, CPU, disk and more.

What are background processes in Task Manager?

Background processes are typically Microsoft and third-party software services listed on the Services window. Thus, reducing background processes is more a matter of terminating services. However, they can also be startup programs and system monitors.


1 Answers

It's not clear what you mean by 'background process', but here's some ideas:

Use EnumWindows to get you all the top-level HWNDs on the desktop. This will include a bunch of stuff you don't want that you'll have to filter out. Recommend you play with Spy++ to see what the HWND tree looks like, and what sort of HWNDs you'll find here:

From this set, you'll want to filter out or ignore invisible HWNDs (use IsWindowVisible or check for the WS_VISIBLE style).

Also filter out windows that have WS_POPUP set - those are things like tooltips, menu popups, floating toolbars, and the like.

To filter out the currently active window, (if you don't already know it) use GetGUIThreadInfo with idThread=0; GUIHREADINFO.hwndActive returns the active window, so any top-level HWND that's not it is an inactive window.

If you're looking specifically for minimized windows, you can detect those using IsIconic(hwnd).

Finally, when you've found a window that you consider to be 'background', you can use GetWindowText to get the title, or GetWindowThreadProcessId to get the process ID.

like image 102
BrendanMcK Avatar answered Sep 22 '22 20:09

BrendanMcK