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

  1. /*
  2.  *
  3.  *  MakeProcInstance
  4.  *  
  5.  *  This program demonstrates the use of the functions MakeProcInstance.
  6.  *  MakeProcInstance binds the segment of the model instance to the
  7.  *  function pointed to by lpProc.
  8.  *
  9.  *  Other references: DlgOpen.c, DlgSave.c, Print.c
  10.  *
  11.  */
  12.  
  13. #include <windows.h>
  14.  
  15. static char    szAppName[] = "makeproc";
  16. static char    szFuncName[] = "MakeProcInstance";
  17. HANDLE hInst;
  18.  
  19. long    FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  20. long    FAR PASCAL TestFarFunc (HWND, unsigned, WORD, LONG);
  21.  
  22. int    PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  23. HANDLE hInstance, hPrevInstance;
  24. LPSTR  lpszCmdLine;
  25. int    cmdShow;
  26. {
  27.   HWND     hWnd;
  28.   WNDCLASS rClass;
  29.   MSG      msg;
  30.  
  31.   if (!hPrevInstance)
  32.   {
  33.     rClass.style         = CS_HREDRAW | CS_VREDRAW;
  34.     rClass.lpfnWndProc   = WndProc;
  35.     rClass.cbClsExtra    = 0;
  36.     rClass.cbWndExtra    = 0;
  37.     rClass.hInstance     = hInstance;
  38.     rClass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  39.     rClass.hIcon         = LoadIcon (hInstance, IDI_APPLICATION);
  40.     rClass.hbrBackground = GetStockObject (WHITE_BRUSH);
  41.     rClass.lpszMenuName  = NULL;
  42.     rClass.lpszClassName = szAppName;
  43.  
  44.     if (!RegisterClass (&rClass))
  45.       return FALSE;
  46.   }
  47.  
  48.   hInst = hInstance;
  49.  
  50. hWnd = CreateWindow (szAppName,            /* window class name       */
  51. szFuncName,                 /* window caption          */
  52. WS_OVERLAPPEDWINDOW,        /* window style            */
  53. CW_USEDEFAULT,              /* initial x position      */
  54. 0,                          /* initial y position      */
  55. CW_USEDEFAULT,              /* initial x size          */
  56. 0,                          /* initial y size          */
  57. NULL,                       /* parent window handle    */
  58. NULL,                       /* window menu handle      */
  59. hInstance,                  /* program instance handle */
  60.   NULL);                      /* create parameters       */
  61.  
  62.   ShowWindow (hWnd, cmdShow);
  63.   UpdateWindow (hWnd);
  64.  
  65.   while (GetMessage ((LPMSG) & msg, NULL, 0, 0))
  66.   {
  67.     TranslateMessage ((LPMSG) & msg);
  68.     DispatchMessage ((LPMSG) & msg);
  69.   }
  70.   return (msg.wParam);
  71. }
  72.  
  73.  
  74. long    FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  75. HWND     hWnd;
  76. unsigned    iMessage;
  77. WORD     wParam;
  78. LONG     lParam;
  79. {
  80.   HMENU   hMenu;
  81.   FARPROC lpProc;
  82.  
  83.   switch (iMessage)
  84.   {
  85.   case WM_CREATE:
  86.     hMenu = CreateMenu ();
  87.     ChangeMenu (hMenu, NULL, (LPSTR)"Make", 100, MF_APPEND);
  88.     SetMenu (hWnd, hMenu);
  89.     break;
  90.   case WM_COMMAND:
  91.     if (wParam == 100)
  92.     {
  93.       MessageBox (GetFocus(), (LPSTR)"Making instance proc.",
  94.           (LPSTR)szFuncName, MB_OK);
  95.       lpProc = MakeProcInstance ((FARPROC)TestFarFunc, hInst);
  96.       if (lpProc != NULL)
  97.     MessageBox (GetFocus(), (LPSTR)"Instance proc. made",
  98.         (LPSTR)szFuncName, MB_OK);
  99.       else
  100.     MessageBox (GetFocus(), (LPSTR)"Instance proc. not made",
  101.         (LPSTR)szFuncName, MB_OK);
  102.       FreeProcInstance (lpProc);
  103.     }
  104.     break;
  105.   case WM_DESTROY:
  106.     PostQuitMessage (0);
  107.     break;
  108.   default:
  109.     return (DefWindowProc (hWnd, iMessage, wParam, lParam));
  110.   }
  111.   return (0L);
  112. }
  113.  
  114.  
  115. long    FAR PASCAL TestFarFunc (hWnd, iMessage, wParam, lParam)
  116. HWND     hWnd;
  117. unsigned    iMessage;
  118. WORD     wParam;
  119. LONG     lParam;
  120. {
  121.   return TRUE;
  122. }
  123.  
  124.  
  125.