Register an App with windows
Simple thing, but I can't get it to work! I'm trying to register my main
application with windows, so that a small mini (launcher) application can
find mine using FindWindow. My mini application simply has Sleep(100) inside
a "while (FindWindow(_T("CircaApp")) == 0)" loop, but it never finds my main
application (loops forever). My main application has the following code in
its InitInstance (I lifted this from an online example somewhere):
// Register the class, so that FindWindow can find us.
WNDCLASS wndcls;
memset(&wndcls, 0, sizeof(WNDCLASS)); // start with NULL defaults
wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc = ::DefWindowProc;
wndcls.hInstance = AfxGetInstanceHandle();
wndcls.hIcon = LoadIcon(IDR_MAINFRAME); // or load a different icon
wndcls.hCursor = LoadCursor( IDC_ARROW );
wndcls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndcls.lpszMenuName = NULL;
// Specify your own class name for using FindWindow later
wndcls.lpszClassName = _T("CircaApp");
// Register the new class and exit if it fails
if(!AfxRegisterClass(&wndcls))
{
TRACE("Circa Class Registration Failed\n");
return false;
}
Can anyone spot where I'm going wrong? Am I missing something else? Is there
a shorter way of doing this? Why doesn't FindWindow find my App?
Thanks,
GT