Win32 API and FindWindow
-
I need a function, which gives me the handle to an active Window. I currently use the FindWindow function, but it also returns handles to already destroyed windows (which come from the same application that ran before and was closed). I found the IsWindow function and currently use it in combination with FindWindow, which looks like the following: private int GetExistingWindow(string cl, string name) { int hWnd; while(true) { if((hWnd = WM.FindWindow(cl, name)) == 0) StartProcess(); if(WM.IsWindow(hWnd)) break; } return hWnd; } questions: 1) Can I do it that way (means returns a second call of FindWindow another handle than the first one or do I always get the same) 2) Is there a better method (single function, etc.) Thanks BTW: The code is written in C#(functions are well implemented), but due to the fact that it is a Win32 API question I decided to post it here.
-
I need a function, which gives me the handle to an active Window. I currently use the FindWindow function, but it also returns handles to already destroyed windows (which come from the same application that ran before and was closed). I found the IsWindow function and currently use it in combination with FindWindow, which looks like the following: private int GetExistingWindow(string cl, string name) { int hWnd; while(true) { if((hWnd = WM.FindWindow(cl, name)) == 0) StartProcess(); if(WM.IsWindow(hWnd)) break; } return hWnd; } questions: 1) Can I do it that way (means returns a second call of FindWindow another handle than the first one or do I always get the same) 2) Is there a better method (single function, etc.) Thanks BTW: The code is written in C#(functions are well implemented), but due to the fact that it is a Win32 API question I decided to post it here.
well the proplem is that in win32 you can not get a valid handle to a window in another application this is some type of protection that windows do to protect applications from affecting each other
-
well the proplem is that in win32 you can not get a valid handle to a window in another application this is some type of protection that windows do to protect applications from affecting each other
I'm not sure what you are referring to but
FindWindow()
does exactly what you indicate is not possible - it returns a handle to a top-level window given either the window's name or class.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow