home *** CD-ROM | disk | FTP | other *** search
- /*
- SWTOTHIS.C -- Uses SwitchToThisWindow to change active app focus
-
- From Chapter 6 of "Undocumented Windows" (Addison-Wesley 1992)
- by Andrew Schulman, Dave Maxey and Matt Pietrek
-
- Build using: WINIOBC SWTOTHIS (for Borland C++ v3.00)
- WINIOMS SWTOTHIS (for Microsoft C/SDK)
- */
-
- #include <windows.h>
- #include "winio.h"
-
- /* undocumented function */
- extern void FAR PASCAL SwitchToThisWindow(HWND hwnd, BOOL tRestore);
-
- #include "checkord.c"
-
- WORD hTimer;
- FARPROC lpfnTimerFunc;
-
- WORD FAR PASCAL TimerFunc(HWND hWnd, WORD wMsg,
- int nIDEvent, DWORD dwTime)
- {
- SwitchToThisWindow(winio_current(), TRUE);
- return 1;
- }
-
- BOOL ResetTimer(HWND hwnd)
- {
- FreeProcInstance(lpfnTimerFunc);
- KillTimer(winio_current(), 0xDADA);
- return TRUE;
- }
-
- int main()
- {
- // Ord/name check
- if (! CheckOrdName("SwitchToThisWindow", "USER", 172))
- return 0;
-
- winio_about("SWTOTHIS"
- "\nUses SwitchToThisWindow to change application focus"
- "\n\nFrom Chapter 6 of"
- "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
- "\nby Andrew Schulman, David Maxey and Matt Pietrek"
- );
-
- lpfnTimerFunc = MakeProcInstance((FARPROC) TimerFunc, __hInst);
-
- if ((hTimer = SetTimer(winio_current(), 0xDADA,
- 3000, lpfnTimerFunc)) == NULL)
- {
- printf("Could not SetTimer.\nProgram terminating.");
- return 0;
- }
-
- winio_onclose(winio_current(), (DESTROY_FUNC) ResetTimer);
-
- printf("Minimize this window, and within 5 seconds,\n"
- "it will restore itself using a call to\n"
- "SwitchToThisWindow() within a timer event.\n\n"
- "Close the window to terminate");
-
- return 0;
- }
-