Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using enumwindows in MFC

Status
Not open for further replies.

cellpeter

Programmer
Dec 30, 2004
34
0
0
US
can anyone display some source code or give an explanation as to how to use enumwindows properly in MFC?

i've tried to use the function but it only displays one window which is the program that is running the function itself..

here are the steps that i've used to attempt to run the function

::EnumWindows(EnumWindowsProc,(LPARAM)this);


static BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam);


BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
HWND grrr;
grrr = GetDlgItem(hwnd,IDC_LIST1);
char szWindowTitle[100];
GetWindowText(hwnd,szWindowTitle,100);
SendMessage(grrr, LB_ADDSTRING,0,(LPARAM) szWindowTitle);

return TRUE;
}

thanks for any help that you can offer
 

// define your function
BOOL CALLBACK MyEnumFunction(HWND wnd,LPARAM lParam)
{
auto char buf[1024]="";

// examine this HWND - see if it's the one we want!
::GetWindowText(wnd,buf,1023);

if (strstr(buf,"My Program's Main Window"))
{
// we found our window on the desktop
// so return FALSE to stop the search
return FALSE;
}
return TRUE;
}

notice how the function gets called repeatedly once for each window on the desktop, either visible or invisible - you can do whatever you need to with the 'wnd' parameter once you've found the window you're looking for
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top