siawos
July 29th, 2003, 03:22 AM
hi all
am having a problem identifying a window. window handle is the unique identifier of a window but it is dynamic(changes in every new call to CreateWindow ())..
i tried findwindow[Ex](), it worked well, but in certain cases it failed to give the desired result ("i.e the new handle")....
findwindow() takes a lebel and the class name to return the handle but we dont have labels attached to controls all the times.(eg; edit box, toolbar,etc).....
is there any other charactersitic or way by which i can identify a window uniquely in multiple instances...
thanx in advance
Matthias Kring
July 29th, 2003, 03:54 AM
Instead of FindWindow, you can use the enumeration functions like EnumWindows and EnumChildWindows
For example, here are some code fragments, I used in a tool to list _all_ windows:
BOOL CALLBACK EnumChildProc (HWND, LPARAM);
BOOL CALLBACK EnumDesktopProc(LPTSTR , LPARAM);
BOOL CALLBACK EnumDesktopWindowsProc(HWND , LPARAM);
(in the main routine: )
...
EnumDesktops(GetProcessWindowStation(), (DESKTOPENUMPROC) EnumDesktopProc, (LPARAM) 0);
...
BOOL CALLBACK EnumDesktopProc(LPTSTR lpszDesktop, LPARAM nothing)
{
HDESK hdesk;
hdesk = OpenDesktop(lpszDesktop, DF_ALLOWOTHERACCOUNTHOOK, TRUE, GENERIC_ALL);
EnumDesktopWindows(hdesk, (WNDENUMPROC) EnumDesktopWindowsProc, NULL);
...
CloseDesktop(hdesk);
return TRUE;
}
BOOL CALLBACK EnumDesktopWindowsProc(HWND hWindow, LPARAM nothing)
{
CHAR WinTitleBuf[256];
CHAR WinClassBuf[256];
GetWindowText(hWindow, WinTitleBuf, 255);
GetClassName (hWindow, WinClassBuf, 255);
...
EnumChildWindows(hWindow,(WNDENUMPROC) EnumChildProc, 0);
return TRUE;
}
BOOL CALLBACK EnumChildProc (HWND hWC, LPARAM lParam)
{
CHAR WinTitleBuf[256];
CHAR WinClassBuf[256];
int CtrlID;
GetWindowText(hWC, WinTitleBuf, 255);
GetClassName (hWC, WinClassBuf, 255);
CtrlID = GetDlgCtrlID(hWC);
...
return TRUE;
}
siawos
July 29th, 2003, 06:08 AM
i have enumerated all child windows n have all the handles with me, but the problem is at playing back, which handle corresponds to its entry in the "gui info file"....??
the particualar case in which theres no id, label associated with control i havent found anything yet ..
someone told me to use windowfrompoint() ... but the "last thing on my mind" :) am searching for a generic approach that could apply in almost all scenarios by mapping controls on a unique sorta combination... i have also used getwindowlong() and getclasslong() and taken the window styles but styles also keep on changing and can be same for two controls....
another "beyond the last thing on my mind " is to ask the user to point to that control and get the handle from there....but there are "hidden" windows as well on windows that [can] overlap each other!!!
thnx