home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_04 / spector.c < prev    next >
Text File  |  1993-02-12  |  1KB  |  44 lines

  1. /* find_prev_wnd(): Find the main window of the previous
  2.    instance by searching all top-level windows */
  3. HWND                   prev_wnd;
  4. FARPROC                find_prev_wndi;
  5. BOOL CALLBACK _export  find_prev_wnd(HWND wnd, LPARAM lParam)
  6.    {
  7.    /* Look for a top-level window having the same instance */
  8.    if (!GetParent(wnd) && GetWindowWord(wnd, GWW_HINSTANCE) ==
  9.       (HINSTANCE)lParam)
  10.       {
  11.       prev_wnd = wnd;
  12.       return FALSE; /* Stop enumerating */
  13.       }
  14.     return TRUE; /* Continue enumerating */
  15.    } /* find_prev_wnd() */
  16. /* Main application function */
  17. int pascal    WinMain(HINSTANCE hinst, HINSTANCE hPrevInst,
  18.                       LPSTR pCmdLine, int Show)
  19.    {
  20.    /* If there is a previous task instance, return to it */
  21.    if (hPrevInst)
  22.       {
  23.       find_prev_wndi =
  24.          MakeProcInstance((FARPROC)find_prev_wnd, instance);
  25.       EnumWindows(find_prev_wndi, hPrevInst);
  26.       FreeProcInstance(find_prev_wndi);
  27.  
  28.       /* Window not found error */
  29.       if (!prev_wnd)
  30.          return 0; /* Fail silently */
  31.  
  32.       /* Return to the last active popup window, if any,
  33.          of the previous instance */
  34.       prev_wnd = GetLastActivePopup(prev_wnd);
  35.  
  36.       /* If the existing window is minimized, restore it */
  37.       ShowWindow(prev_wnd, SW_SHOWNORMAL);
  38.       SetActiveWindow(prev_wnd);
  39.       return 0;
  40.       } /* There is a previous instance */
  41.    . . .
  42.    } /* WinMain() */
  43.       
  44.