home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / mswindo / programm / misc / 4203 < prev    next >
Encoding:
Internet Message Format  |  1992-12-14  |  2.2 KB

  1. Path: sparky!uunet!lax.pe-nelson.com!lax!twbrown
  2. From: twbrown@PE-Nelson.COM (Tom W. Brown)
  3. Newsgroups: comp.os.ms-windows.programmer.misc
  4. Subject: Re: Novice programmer question
  5. Message-ID: <710@lax.lax.pe-nelson.com>
  6. Date: 14 Dec 92 19:20:47 GMT
  7. References: <1992Dec13.204238.8073@ucsu.Colorado.EDU>
  8. Sender: news@lax.pe-nelson.com
  9. Distribution: usa
  10. Organization: PE-Nelson
  11. Lines: 64
  12.  
  13. In article <1992Dec13.204238.8073@ucsu.Colorado.EDU>, tylerd@rintintin.Colorado.EDU (TYLER DAVID CHARLES) writes:
  14. |> I'll make this brief:
  15. |> Why doesn't the following work?
  16. |> 
  17. |>   if (!hPrevInstance)
  18. |>   {
  19. |>     [normal stuff]
  20. |>   }
  21. |>   else
  22. |>   //
  23. |>   // If an instance is already running, just display it.
  24. |>   //
  25. |>   {
  26. |>     if (IsIconic (hPrevInstance))
  27. |>     {
  28. |>       OpenIcon (hPrevInstance);
  29. |>     }
  30. |>     BringWindowToTop (hPrevInstance);
  31. |>     return TRUE;                      // Or should this be FALSE?
  32. |>   }
  33.  
  34. The routines IsIconic(), OpenIcon(), and BringWindowToTop() need window
  35. handles, not instance handles.
  36.  
  37. Use FindWindow() (as one possibility) to obtain the window handle for the
  38. first instance.  Assuming that you have the class name (used to register
  39. the window class) in a variable, szClassName, you can do the following:
  40.  
  41.    .
  42.    .
  43.    .
  44.    else
  45.       {
  46.       HWND hwnd = FindWindow(szClassName, NULL);
  47.       if (hwnd)
  48.          {
  49.          if (IsIconic(hwnd))
  50.             OpenIcon(hwnd);
  51.  
  52.          BringWindowToTop(hwnd);
  53.          }
  54.       else
  55.          {
  56.          MessageBeep(MB_OK | MB_ICONEXCLAMATION);
  57.          MessageBox(GetFocus(), "Unable to find window of first instance",
  58.                     NULL, MB_OK | MB_ICONEXCLAMATION);
  59.          }
  60.  
  61.       return 0;
  62.       }
  63.    .
  64.    .
  65.    .
  66.  
  67. The return value doesn't particularly matter -- it *can* be interpreted
  68. as an error code by the environment that spawned your application, but
  69. Windows itself doesn't care.
  70.  
  71.  
  72. ----------------------------------------------------------------------------
  73. Tom Brown               |  "She turned me into a newt...
  74. PE Nelson Systems       |                                  ... I got better"
  75. twbrown@pe-nelson.com   |                    Monty Python and the Holy Grail
  76. ----------------------------------------------------------------------------
  77.