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

  1. /*
  2.     ENDMENU.C -- Shows the system wide effect of EndMenu
  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 ENDMENU (for Borland C++ v3.00)
  8.                  WINIOMS ENDMENU (for Microsoft C/SDK)
  9. */
  10.  
  11. #include <windows.h> 
  12. #include "winio.h" 
  13.  
  14. /* undocumented function */ 
  15. extern void FAR PASCAL EndMenu(void);
  16.  
  17. #include "checkord.c"
  18.  
  19. HANDLE hTimer;
  20. FARPROC lpfnTimerFunc;
  21.  
  22. WORD FAR PASCAL TimerFunc(HWND hwnd, WORD wMsg,
  23.                                 int nIDEvent, DWORD dwTime)
  24.     {
  25.     EndMenu();
  26.     return 1;
  27.     }
  28.  
  29. BOOL CleanUp(HWND hwnd)
  30.     {
  31.     FreeProcInstance(lpfnTimerFunc);
  32.     KillTimer(winio_current(), hTimer);
  33.     return TRUE;
  34.     }
  35.  
  36. int main() 
  37.     {
  38.     HMENU hMenu, hPopup;
  39.     
  40.     // Ord/name check
  41.     if (! CheckOrdName("EndMenu", "USER", 187))
  42.         return 0;
  43.  
  44.     winio_about("ENDMENU"
  45.         "\nShows the system wide effect of EndMenu"
  46.         "\n\nFrom Chapter 6 of"
  47.         "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
  48.         "\nby Andrew Schulman, David Maxey and Matt Pietrek"
  49.         );
  50.     
  51.     lpfnTimerFunc = MakeProcInstance((FARPROC) TimerFunc, __hInst);
  52.     
  53.     hPopup = CreateMenu();
  54.     AppendMenu(hPopup, MF_GRAYED | MF_STRING,
  55.                         1, "Watch me disappear...");
  56.     AppendMenu(hPopup, MF_GRAYED | MF_STRING,
  57.                         2, ".. within 3 seconds.");
  58.     
  59.     hMenu = winio_hmenumain(winio_current());
  60.     AppendMenu(hMenu, MF_ENABLED | MF_STRING | MF_POPUP,
  61.                         hPopup, "Click Me");
  62.  
  63.     hTimer = SetTimer(winio_current(), 10, 3000, lpfnTimerFunc);
  64.  
  65.     winio_onclose(winio_current(), (DESTROY_FUNC) CleanUp);
  66.     
  67.     printf("\nClick once on the menu selection \"Click Me\" above,\n"
  68.             "leaving the popup visible. Within a couple of seconds\n"
  69.             "the popup will disappear by itself. This is caused by\n"
  70.             "a call to EndMenu() within a timer event handler.\n\n"
  71.             "Close the window to exit.");
  72.     
  73.     return 0;
  74.     }
  75.  
  76.