Hi, all.
I'm not a Delphi guy, so forgive the stupid question. I notice when running a Delphi application that the window handles for controls (edit fields, buttons, etc.) are not static. In other words, an edit field on an application might have an ID of 0x000502cd the first time I run it, and the same edit field could have an ID of 0x00001133 the next time I run the program.
I'm interested in determining which field in an executable has focus at any given point in time, and obviously the non-static nature of the controls presents a problem. Is there any way to either force the control IDs to be static, or to otherwise identify a particular control between instantiations of an application?
Additional (possibly significant information): I'm only interested in Delphi on Windows operating systems. I have a good background in VC++ and the program that's snooping for this information is written in VC++. I determine the currently running program and the ID of the control in
this fashion:
HWND hwnd = GetForegroundWindow();
LONG_PTR lpID;
DWORD dwProcID;
TCHAR lpszFilename[MAX_PATH];
// Do some testing of hwnd (make sure it's not this process, etc.)
// Get the process name (very abbreviated)
GetWindowThreadProcessId(hwnd,&dwProcID);
HANDLE hProc = OpenProcess(...,dwProcID);
HMODULE hMod;
EnumProcessModules(hProc,&hModule,....)
GetModuleBase(hProc,hModule,lpszFilename,MAX_PATH);
// Get the window with focus
GUITHREADINFO tInfo;
tInfo.cbSize = sizeof(GUITHREADINFO);
GetGUIThreadInfo(NULL,&tInfo);
if (tInfo.hwndFocus)
{
lpID = GetWindowLongPtr(tInfo.hwndFocus,GWLP_ID);
// do stuff depending on process name and lpID
}
Thanks for any information.
I'm not a Delphi guy, so forgive the stupid question. I notice when running a Delphi application that the window handles for controls (edit fields, buttons, etc.) are not static. In other words, an edit field on an application might have an ID of 0x000502cd the first time I run it, and the same edit field could have an ID of 0x00001133 the next time I run the program.
I'm interested in determining which field in an executable has focus at any given point in time, and obviously the non-static nature of the controls presents a problem. Is there any way to either force the control IDs to be static, or to otherwise identify a particular control between instantiations of an application?
Additional (possibly significant information): I'm only interested in Delphi on Windows operating systems. I have a good background in VC++ and the program that's snooping for this information is written in VC++. I determine the currently running program and the ID of the control in
this fashion:
HWND hwnd = GetForegroundWindow();
LONG_PTR lpID;
DWORD dwProcID;
TCHAR lpszFilename[MAX_PATH];
// Do some testing of hwnd (make sure it's not this process, etc.)
// Get the process name (very abbreviated)
GetWindowThreadProcessId(hwnd,&dwProcID);
HANDLE hProc = OpenProcess(...,dwProcID);
HMODULE hMod;
EnumProcessModules(hProc,&hModule,....)
GetModuleBase(hProc,hModule,lpszFilename,MAX_PATH);
// Get the window with focus
GUITHREADINFO tInfo;
tInfo.cbSize = sizeof(GUITHREADINFO);
GetGUIThreadInfo(NULL,&tInfo);
if (tInfo.hwndFocus)
{
lpID = GetWindowLongPtr(tInfo.hwndFocus,GWLP_ID);
// do stuff depending on process name and lpID
}
Thanks for any information.