Find the windows
-
Hello, I want to find the handle of same windows currently opened. E.g: I have started 2 notepads and I want to get handle of both notepads using some windows APIs. I tried FindWindow(). But its only return the first notepad window handle. Any other APIs available for getting the handle of second Window? Please help. -Cvaji
-
Hello, I want to find the handle of same windows currently opened. E.g: I have started 2 notepads and I want to get handle of both notepads using some windows APIs. I tried FindWindow(). But its only return the first notepad window handle. Any other APIs available for getting the handle of second Window? Please help. -Cvaji
Maybe try EnumWindows[^].
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <
-
Maybe try EnumWindows[^].
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <
-
Code-o-mat wrote:
Maybe try EnumWindows[^].
But this will enumerate all the top level windows right? I have the window name/window class of my required window. I need to get only that specific windows. -Cvaji
You can implement the filtering in the callback function, you can get the window's "name" by calling GetWindowText[^] and the class name by calling GetClassName[^], althorough i am not sure that GetClassName works on windows in different processes... If you know the Process ID's of the notepad apps you started you can also use GetWindowthreadProcessId[^] to recognize them.
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <
-
You can implement the filtering in the callback function, you can get the window's "name" by calling GetWindowText[^] and the class name by calling GetClassName[^], althorough i am not sure that GetClassName works on windows in different processes... If you know the Process ID's of the notepad apps you started you can also use GetWindowthreadProcessId[^] to recognize them.
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <
-
You could also try using FindWindow as you did, and once you find a window, do whatever you want with it and then add a space at the end of its name (title) and then use FindWindow again until it does not find any such windows anymore, you might want to remove the extra added space when you are done, of course this would be quite an unelegant and ugly solution...
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <
-
You could also try using FindWindow as you did, and once you find a window, do whatever you want with it and then add a space at the end of its name (title) and then use FindWindow again until it does not find any such windows anymore, you might want to remove the extra added space when you are done, of course this would be quite an unelegant and ugly solution...
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <
-
You mean the below code will return the handle for second notepad ? :confused:
hWnd = ::FindWindow( 0, L"Untitled - Notepad " );
-CvajiNo, i mean something like this:
HWND hWnd;
while ((hWnd = ::FindWindow(0, L"Untitled - Notepad")) != NULL)
{
//Do what you need with hWnd
::SetWindowText(hWnd, L"Untitled - Notepad ");
}Since you add a space at the end of the window text, the next time you call FindWindow, it will not find this window you already used (since it's title does not mach your search string anymore) and go on looking for the next one, if you find that next one, you add a space to that one too and so on untill you get no more windows...
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <
-
No, i mean something like this:
HWND hWnd;
while ((hWnd = ::FindWindow(0, L"Untitled - Notepad")) != NULL)
{
//Do what you need with hWnd
::SetWindowText(hWnd, L"Untitled - Notepad ");
}Since you add a space at the end of the window text, the next time you call FindWindow, it will not find this window you already used (since it's title does not mach your search string anymore) and go on looking for the next one, if you find that next one, you add a space to that one too and so on untill you get no more windows...
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <
-
Wow. Hats off you man :) even though its an ugly method, i congratulate your brilliancy :thumbsup: But I got another method.
HWND hWnd = ::FindWindow( L"Notepad", 0 );
hWnd = ::FindWindowEx( 0, hWnd, L"Notepad", 0 );-Cvaji
Gee, thanks :) FindWindowEx, i better rememeber that for the next time :)
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <
-
Gee, thanks :) FindWindowEx, i better rememeber that for the next time :)
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <