I have a program that is looking for another program to communicate with. It works if you run it from the desktop (explorer), but if I schedule it as a schedule task, enumwindows() only calls the callback function once, then no more.
In the below code, g_hProc is getting set correctly, regardless of the code running as a normal app or a scheduled task. However, g_hWnd never gets set, because enumWindowProc() only gets called once. It properly enumerates if run as a regular app???? (Note: g_appTitle is the name of the window we're looking for, and this object is basically a version of CString.)
If anybody has a fix, please email me at bret @ levycodev dot com.
Thanks,
Bret
BOOL CALLBACK enumWindowsProc (HWND hwnd, LPARAM lParam) {
DWORD procid;
GetWindowThreadProcessId (hwnd, &procid);
if ((HANDLE)procid == g_hProc) {
staticchar module[1024];
module[0] = 0;
if (g_softPhoneTitle.Size() > 0) {
int rc = GetWindowText (hwnd, module, 1023);
module[rc] = 0;
}
if (IsWindow(hwnd) && ((g_appTitle.Size() == 0) || (g_appTitle.EqualsNoCase(module)))) {
g_hWnd = hwnd;
return (false);
}
}
return (true);
}
int
findApplicationWindow (void) {
g_hWnd = NULL;
EnumWindows (enumWindowsProc, 0);
return (0);
}