home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l430 / 1.ddi / CHAP6.ZIP / SWTOTHIS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.8 KB  |  67 lines

  1. /*
  2.     SWTOTHIS.C -- Uses SwitchToThisWindow to change active app focus
  3.  
  4.     From Chapter 6 of "Undocumented Windows" (Addison-Wesley 1992)
  5.     by Andrew Schulman, Dave Maxey and Matt Pietrek
  6.  
  7.     Build using: WINIOBC SWTOTHIS (for Borland C++ v3.00)
  8.                  WINIOMS SWTOTHIS (for Microsoft C/SDK)
  9. */
  10.  
  11. #include <windows.h> 
  12. #include "winio.h" 
  13.  
  14. /* undocumented function */ 
  15. extern void FAR PASCAL SwitchToThisWindow(HWND hwnd, BOOL tRestore);
  16.  
  17. #include "checkord.c"
  18.  
  19. WORD hTimer;
  20. FARPROC lpfnTimerFunc;
  21.  
  22. WORD FAR PASCAL TimerFunc(HWND hWnd, WORD wMsg,
  23.                                 int nIDEvent, DWORD dwTime)
  24.     {
  25.     SwitchToThisWindow(winio_current(), TRUE);
  26.     return 1;
  27.     }
  28.  
  29. BOOL ResetTimer(HWND hwnd)
  30.     {
  31.     FreeProcInstance(lpfnTimerFunc);
  32.     KillTimer(winio_current(), 0xDADA);
  33.     return TRUE;
  34.     }
  35.  
  36. int main() 
  37.     {
  38.     // Ord/name check
  39.     if (! CheckOrdName("SwitchToThisWindow", "USER", 172))
  40.         return 0;
  41.  
  42.     winio_about("SWTOTHIS"
  43.         "\nUses SwitchToThisWindow to change application focus"
  44.         "\n\nFrom Chapter 6 of"
  45.         "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
  46.         "\nby Andrew Schulman, David Maxey and Matt Pietrek"
  47.         );
  48.  
  49.     lpfnTimerFunc = MakeProcInstance((FARPROC) TimerFunc, __hInst);
  50.     
  51.     if ((hTimer = SetTimer(winio_current(), 0xDADA,
  52.                             3000, lpfnTimerFunc)) == NULL)
  53.         {
  54.         printf("Could not SetTimer.\nProgram terminating.");
  55.         return 0;
  56.         }
  57.  
  58.     winio_onclose(winio_current(), (DESTROY_FUNC) ResetTimer);
  59.  
  60.     printf("Minimize this window, and within 5 seconds,\n"
  61.             "it will restore itself using a call to\n"
  62.             "SwitchToThisWindow() within a timer event.\n\n"
  63.             "Close the window to terminate");
  64.     
  65.     return 0;
  66.     }
  67.