home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / dialog / enddia.c < prev    next >
C/C++ Source or Header  |  1988-08-10  |  4KB  |  179 lines

  1. /*
  2.  *  Function Name:   EndDialog
  3.  *  Program Name:    enddia.c
  4.  *  SDK Version:         2.03
  5.  *  Runtime Version:     2.03
  6.  *  Microsoft C Version: 5.0
  7.  *
  8.  *  Description:
  9.  *   This function frees resources and reactivates the parent window
  10.  *   while destroying the dialog box.
  11.  */
  12.  
  13. #include "windows.h"
  14. #include "enddia.h"
  15.  
  16. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  17.  
  18. HANDLE   hInst;
  19.  
  20. /**************************************************************************/
  21.  
  22. /* Window procedure for the dialog box */
  23. BOOL FAR PASCAL DialogProc (hDlg, message, wParam, lParam)
  24. HWND hDlg;
  25. unsigned message;
  26. WORD wParam;
  27. LONG lParam;
  28. {
  29.   if (message == WM_COMMAND)           /* check for WM_COMMAND            */
  30.     EndDialog(hDlg, TRUE);            /* free resources                   */
  31.   else
  32.     return FALSE;
  33. }
  34.  
  35. /**************************************************************************/
  36.  
  37. void CALL_EndDialog(hWnd)
  38. HWND   hWnd;
  39. {
  40.   FARPROC lpprocDialogBox;
  41.                     /*  Bind calback function with module instance  */
  42.     lpprocDialogBox = MakeProcInstance ((FARPROC) DialogProc, hInst);
  43.                     /*  Create a modal dialog box  */
  44.     DialogBox (hInst, MAKEINTRESOURCE(IDD_10), hWnd, lpprocDialogBox);
  45.     FreeProcInstance ((FARPROC) lpprocDialogBox);
  46.  
  47.   return;
  48. }
  49.  
  50. /**************************************************************************/
  51.  
  52. /* Procedure called when the application is loaded for the first time */
  53. BOOL WinInit( hInstance )
  54. HANDLE hInstance;
  55. {
  56.     WNDCLASS   wcClass;
  57.  
  58.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  59.     wcClass.lpfnWndProc    = WndProc;
  60.     wcClass.cbClsExtra     =0;
  61.     wcClass.cbWndExtra     =0;
  62.     wcClass.hInstance      = hInstance;
  63.     wcClass.hIcon          = LoadIcon( hInstance,NULL );
  64.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  65.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  66.     wcClass.lpszMenuName   = (LPSTR)"MenuName";
  67.     wcClass.lpszClassName  = (LPSTR)"EndDialog";
  68.  
  69.     if (!RegisterClass( (LPWNDCLASS)&wcClass ) )
  70.         /* Initialization failed.
  71.          * Windows will automatically deallocate all allocated memory.
  72.          */
  73.         return FALSE;
  74.  
  75.     return TRUE;        /* Initialization succeeded */
  76. }
  77.  
  78.  
  79. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  80. HANDLE hInstance, hPrevInstance;
  81. LPSTR lpszCmdLine;
  82. int cmdShow;
  83. {
  84.     MSG   msg;
  85.     HWND  hWnd;
  86.  
  87.     if (!hPrevInstance)
  88.         {
  89.         /* Call initialization procedure if this is the first instance */
  90.         if (!WinInit( hInstance ))
  91.             return FALSE;
  92.         }
  93.  
  94.     hWnd = CreateWindow((LPSTR)"EndDialog",
  95.                         (LPSTR)"EndDialog()",
  96.                         WS_OVERLAPPEDWINDOW,
  97.                         CW_USEDEFAULT,
  98.                         CW_USEDEFAULT,
  99.                         CW_USEDEFAULT,
  100.                         CW_USEDEFAULT,
  101.                         (HWND)NULL,        /* no parent */
  102.                         (HMENU)NULL,       /* use class menu */
  103.                         (HANDLE)hInstance, /* handle to window instance */
  104.                         (LPSTR)NULL        /* no params to pass on */
  105.                         );
  106.  
  107.      hInst = hInstance;
  108.  
  109.     /* Make window visible according to the way the app is activated */
  110.     ShowWindow( hWnd, cmdShow );
  111.     UpdateWindow( hWnd );
  112.  
  113.     /* Polling messages from event queue */
  114.     while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  115.         {
  116.         TranslateMessage((LPMSG)&msg);
  117.         DispatchMessage((LPMSG)&msg);
  118.         }
  119.     return (int)msg.wParam;
  120. }
  121.  
  122. /* Procedures which make up the window class. */
  123. long FAR PASCAL WndProc( hWnd, message, wParam, lParam )
  124. HWND hWnd;
  125. unsigned message;
  126. WORD wParam;
  127. LONG lParam;
  128. {
  129.     PAINTSTRUCT ps;
  130.  
  131.     switch (message)
  132.     {
  133.       case WM_COMMAND:
  134.         switch (wParam)
  135.         {
  136.           case IDM_1:
  137.             CALL_EndDialog(hWnd);
  138.             break;
  139.  
  140.           default:
  141.             return DefWindowProc( hWnd, message, wParam, lParam );
  142.             break;
  143.         }
  144.  
  145.     case WM_DESTROY:
  146.         PostQuitMessage( 0 );
  147.         break;
  148.  
  149.     default:
  150.         return DefWindowProc( hWnd, message, wParam, lParam );
  151.         break;
  152.     }
  153.     return(0L);
  154. }
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178. c
  179.