• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 491
  • Last Modified:

GetWindow()

I would like to be able to get hold of the Window's handles of programs which are currently running. (eg MS Spy++ does this)

How do I do this?

I know its something to do with the GetWindow function but Ive been able to get hold of the HWNDLAST window which is rather frustrating.
Thanks in advance
Ian Robertson
0
yakky
Asked:
yakky
  • 2
  • 2
1 Solution
 
AVaulinCommented:
Use h=GetWindow( NULL, GW_HWNDFIRST ) to find first and GetNextWindow( h, GW_HWNDNEXT ) to find next window(s).
0
 
yakkyAuthor Commented:
Prehaps Im missing something, here but all Im getting is a Null
see bellow. Also if pos I would like to use the CWnd approach
.
HWND h;
h=::GetWindow(NULL,GW_HWNDFIRST);
for(int count=0; count<10; count++)
{
h=::GetWindow(h,GW_HWNDNEXT);
if (h==NULL) TRACE("failed\n");
    //pWnd.GetWindowText(my1);
   //TRACE("m=%s*\n",my1);
TRACE("window=%d*\n"5,h);
}
0
 
AVaulinCommented:
OK. Here is code. It gave all windows which Spy++ did:

#include <windows.h>
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
{
 HWND h;
 h = GetDesktopWindow();
 h = GetWindow( h, GW_CHILD );
 while( h )
 {
 // do what you want
  h = GetWindow( h, GW_HWNDNEXT );
 }
 return TRUE;
}
0
 
yakkyAuthor Commented:
Thanks very much...

Ian (The incompetent) Robertson
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now