home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / apps / lnotify.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  2.0 KB  |  83 lines

  1. /**************************************************************************
  2.  * LNOTIFY.C - Demo Program for LocalNotify.
  3.  *
  4.  *
  5.  * Compiled with MS C 5.1 & Windows SDK 2.03
  6.  * Compiled on IBM-AT with 640K RAM.
  7.  * 
  8.  **************************************************************************/
  9.  
  10. #include <windows.h>
  11.  
  12. /* PROTOTYPES */
  13. int    PASCAL WinMain (HANDLE, HANDLE, LPSTR, int);
  14. BOOL FAR PASCAL NotifyProc(WORD, HANDLE, WORD);
  15.  
  16. FARPROC  lpNotifyProc;
  17. FARPROC  oldNotifyProc;
  18.  
  19. /***************************************************************************/
  20.  
  21. int    PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  22. HANDLE    hInstance;
  23. HANDLE    hPrevInstance;
  24. LPSTR      lpszCmdLine;
  25. int    cmdShow;
  26. {
  27.   HANDLE   hMem;
  28.  
  29.   MessageBox(GetFocus(),
  30.       (LPSTR)"This is a program to demonstrate LocalNotify. About to swap Notify Procedures.",
  31.       (LPSTR)"LocalNotify",
  32.       MB_OK);
  33.  
  34. /* Get a relocatable procedure address. */
  35.   lpNotifyProc = MakeProcInstance((FARPROC)NotifyProc, hInstance);
  36.  
  37. /* Replace the local-heap notification handler */
  38.   oldNotifyProc = LocalNotify(lpNotifyProc);
  39.  
  40.   MessageBox(GetFocus(),
  41.       (LPSTR)"About to send a message to the new Notify Procedure.",
  42.       (LPSTR)"LocalNotify",
  43.       MB_OK);
  44.  
  45.   hMem = LocalAlloc(LMEM_DISCARDABLE | LHND, 1024);  /* Request a 1K buffer. */
  46.  
  47.   FreeProcInstance(LocalNotify(oldNotifyProc));                 /* Clean up. */
  48.  
  49.   MessageBox(GetFocus(), (LPSTR)"Finished", (LPSTR)"LocalNotify", MB_OK);
  50.  
  51.   return (0);
  52. } /* WINMAIN */
  53.  
  54.  
  55. /***************************************************************************/
  56. /*    NOTIFYPROC:  Local memory discarding notification procedure. */
  57.  
  58. BOOL FAR PASCAL NotifyProc(function, arg1, arg2)
  59. WORD   function;
  60. HANDLE arg1;
  61. WORD   arg2;
  62. {
  63.   switch (function) 
  64.   {
  65.  
  66.   case LNOTIFY_OUTOFMEM:
  67.  
  68.     MessageBox(GetFocus(),
  69.         (LPSTR)"Out of memory message received by new Notify Procedure.",
  70.         (LPSTR)"LocalNotify",
  71.         MB_OK);
  72.     return(0);
  73.     break;
  74.  
  75.   default:
  76.     break;
  77.   }
  78.   return(arg2);
  79. }
  80.  
  81.  
  82.  
  83.