🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.ms-windows.programmer.misc
Article #1746

Re: Novice programmer question

#1746
From: Tom W. Brown
Date: Mon, 14 Dec 1992 19:20
64 lines
2328 bytes
In article <1992Dec13.204238.8073@ucsu.Colorado.EDU>, tylerd@rintintin.Colorado.EDU (TYLER DAVID CHARLES) writes:
|> I'll make this brief:
|> Why doesn't the following work?
|> 
|>   if (!hPrevInstance)
|>   {
|>     [normal stuff]
|>   }
|>   else
|>   //
|>   // If an instance is already running, just display it.
|>   //
|>   {
|>     if (IsIconic (hPrevInstance))
|>     {
|>       OpenIcon (hPrevInstance);
|>     }
|>     BringWindowToTop (hPrevInstance);
|>     return TRUE;                      // Or should this be FALSE?
|>   }

The routines IsIconic(), OpenIcon(), and BringWindowToTop() need window
handles, not instance handles.

Use FindWindow() (as one possibility) to obtain the window handle for the
first instance.  Assuming that you have the class name (used to register
the window class) in a variable, szClassName, you can do the following:

   .
   .
   .
   else
      {
      HWND hwnd = FindWindow(szClassName, NULL);
      if (hwnd)
         {
         if (IsIconic(hwnd))
            OpenIcon(hwnd);

         BringWindowToTop(hwnd);
         }
      else
         {
         MessageBeep(MB_OK | MB_ICONEXCLAMATION);
         MessageBox(GetFocus(), "Unable to find window of first instance",
                    NULL, MB_OK | MB_ICONEXCLAMATION);
         }

      return 0;
      }
   .
   .
   .

The return value doesn't particularly matter -- it *can* be interpreted
as an error code by the environment that spawned your application, but
Windows itself doesn't care.


----------------------------------------------------------------------------
Tom Brown               |  "She turned me into a newt...
PE Nelson Systems       |                                  ... I got better"
twbrown@pe-nelson.com   |                    Monty Python and the Holy Grail
----------------------------------------------------------------------------
Technical Details
Message-ID: <710@lax.lax.pe-nelson.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!lax.pe-nelson.com!lax!twbrown
References: <1992Dec13.204238.8073@ucsu.Colorado.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!lax.pe-nelson.com!lax!twbrown
From: twbrown@PE-Nelson.COM (Tom W. Brown)
Newsgroups: comp.os.ms-windows.programmer.misc
Subject: Re: Novice programmer question
Message-ID: <710@lax.lax.pe-nelson.com>
Date: 14 Dec 92 19:20:47 GMT
References: <1992Dec13.204238.8073@ucsu.Colorado.EDU>
Sender: news@lax.pe-nelson.com
Distribution: usa
Organization: PE-Nelson
Lines: 64