In python, I enumerate top-level windows through EnumWindows
, and also I enumerate the processes through EnumProcesses
.
Then in the python script, I put all the window handles which belongs to the same pid into one list (I did this through GetWindowThreadProcessId
).
Later I found out something: there are 3 window handles which belong to notepad.exe
, but I only open one text file.
Why?
Besides, I tried to set the text window as the foreground window through SetForegroundWindow
, I passed the three window handles to this function, and two work.
How could this be ?
Processes sometimes create invisible windows for their own purposes. You should ignore them (use IsWindowVisible
function).
To investigate this kind of things your best friend is Spy++, that comes with several versions of Visual Studio, if you can get it.
According to it, notepad.exe creates three top-level windows:
The two hidden windows are used internally by notepad to implement the IME (Input Method Editor), the GUI to type complex scripts.
Many programs create top-level hidden windows for a lot of things. For what you intend, you can ignore them all and use only the visible ones.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With