"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
FindWindow is a really unreliable technique. For one thing, your window
name doesn't
include a GUID, which immediately opens the possibility that someone
else
will use that
name.
On Thu, 16 Sep 2010 10:40:27 +0100, "GT" <a@b.c> wrote:
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,
****
It usually helps to show the actual code you use. This code should not
even compile,
because CWnd::FindWindow takes TWO parameters, and should have been
written with the
second parameter as NULL (I just checked the header files, and the
documentation and
header files both require the second parameter).
The fact that you have a Sleep(100) is already suspect, because in
almost
any case where
you are using a Sleep() call, there is a better way.
You have not said how you are launching the process. CreateProcess or
ShellExecute?
Look at WaitForInputIdle, which is a better indicator of when the
process
is ready. What,
exactly, do you do with the information you receive that the program has
launched? For
that matter, if CreateProcess or ShellExecute returned a success code,
why
do you care?
****
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):
****
Did you just launch the process and use Spy++ to see what its window
class
is? Do you
actually see the app come up?
****
// 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?
****
Need LOTS more information! Please answer all above questions.
joe
****
Thanks,
GT
required - first one is the App's class, second is the window title. Both
are optional NULLs. I did have NULL as the second and just didn't
my code into the newsgroup posting.
network.
Once the main app arrives, the mini launcher app just closes. I use
CPU core while it looks for the main app window. Its only job is to show a
to arrive.