简体   繁体   中英

Can't interact with a window (HWND) cpp

I want to be able to minimize/maximize a window of a process that I create with ShellExecuteEx() .

First, I find the process ID and its HWND (I made sure it was the good HWND with Spy++).

Next, I try to minimize with ShowWindow(hwnd) or with ShowWindow(GetForegroundWindow(), SW_MINIMIZE) .

But it doesn't work. I made sure the process was elevated (administrator rights). This seems to work with any other windows, such as the one for Notepad, RocketLeague, or whatever. But this one window doesn't react. When I call SetForegroundWindow(hwnd) I can see it flashing in the Taskbar, so I'm sure it is the right HWND for my application to use.

Any idea of what the issue might be?

Use SPY++ to find className and windowName, then you can:

HWND hWnd = ::FindWindow(className, windowName);
::ShowWindow(hWnd, SW_MINIMIZE);

SendMessage(GetForegroundWindow(),WM_SYSCOMMAND,SC_MINIMIZE,0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM