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

  1. /*
  2.  *   This program demonstrates use of the CreateDialog () function.
  3.  *   CreateDialog () creates a modeless dialog box. CreateDialog () is
  4.  *   called in response to a WM_COMMAND message in HelloWndProc ();
  5.  */
  6.  
  7. #include "windows.h"
  8. #include "creatdlg.h"
  9.  
  10. long    FAR PASCAL HelloWndProc (HWND, unsigned, WORD, LONG);
  11. BOOL    FAR PASCAL ShakeOptions (HWND, unsigned, WORD, LONG);
  12. HWND    hYourTurnDlg = NULL;
  13. HANDLE  hInst;
  14. HWND    hWnd;
  15. FARPROC lpprocSHAKE;
  16.  
  17. BOOL FAR PASCAL ShakeOptions (hDlg, message, wParam, lParam)
  18. HWND     hDlg;
  19. unsigned message;
  20. WORD     wParam;
  21. LONG     lParam;
  22.   {
  23.   HWND hCtl;
  24.   int    i;
  25.   BOOL OKAY;
  26.   HDC hDC;
  27.   RECT ClearRect;
  28.  
  29.   switch (message)
  30.     {
  31.     case WM_INITDIALOG:
  32.       return TRUE;
  33.       break;
  34.  
  35.     case WM_COMMAND:
  36.       switch (wParam)
  37.         {
  38.         case IDOK:
  39.           DestroyWindow (hYourTurnDlg);
  40.           hYourTurnDlg = NULL;
  41.           break;
  42.  
  43.         default:
  44.           return FALSE;
  45.           break;
  46.         } /** end CASE WM_COMMAND **/
  47.       break;
  48.  
  49.     case WM_DESTROY:
  50.       return TRUE;
  51.       break;
  52.  
  53.     default:
  54.       return FALSE;
  55.     }
  56.   }
  57.  
  58. /* Procedure called when the application is loaded for the first time */
  59. BOOL HelloInit (hInstance)
  60. HANDLE hInstance;
  61.   {
  62.   PWNDCLASS   pHelloClass;
  63.  
  64.   pHelloClass = (PWNDCLASS)LocalAlloc (LPTR, sizeof (WNDCLASS));
  65.   pHelloClass->hCursor        = LoadCursor (NULL, IDC_ARROW);
  66.   pHelloClass->hIcon          = NULL;
  67.   pHelloClass->lpszMenuName   = (LPSTR)"hello";
  68.   pHelloClass->lpszClassName  = (LPSTR)"CreateDialog";
  69.   pHelloClass->hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
  70.   pHelloClass->hInstance      = hInstance;
  71.   pHelloClass->style          = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  72.   pHelloClass->lpfnWndProc    = HelloWndProc;
  73.  
  74.   if (!RegisterClass ( (LPWNDCLASS)pHelloClass))
  75.     return FALSE;     
  76.  
  77.   LocalFree ( (HANDLE)pHelloClass);
  78.  
  79.   return TRUE;        /* Initialization succeeded */
  80.   }
  81.  
  82.  
  83. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  84. HANDLE hInstance, hPrevInstance;
  85. LPSTR lpszCmdLine;
  86. int    cmdShow;
  87.   {
  88.   MSG    msg;
  89.  
  90.   int   i;
  91.  
  92.   if (!hPrevInstance)
  93.     if (!HelloInit (hInstance))
  94.       return FALSE;
  95.  
  96.   hWnd = CreateWindow ( (LPSTR)"CreateDialog",
  97.                       (LPSTR)"CreateDialog ()",
  98.                       WS_OVERLAPPEDWINDOW,
  99.                       CW_USEDEFAULT,
  100.                       CW_USEDEFAULT,
  101.                       CW_USEDEFAULT,
  102.                       CW_USEDEFAULT,
  103.                       (HWND)NULL,        /* no parent */
  104.                       (HMENU)NULL,       /* use class menu */
  105.                       (HANDLE)hInstance, /* handle to window instance */
  106.                       (LPSTR)NULL);      /* no params to pass on */
  107.  
  108.   hInst = hInstance;
  109.  
  110.   lpprocSHAKE  = MakeProcInstance ( (FARPROC)ShakeOptions, hInstance);
  111.  
  112.   ShowWindow (hWnd, cmdShow);
  113.   UpdateWindow (hWnd);
  114.  
  115.   while (GetMessage ( (LPMSG) & msg, NULL, 0, 0))
  116.     {
  117.     if (hYourTurnDlg == NULL || !IsDialogMessage (hYourTurnDlg, &msg))
  118.       {
  119.       TranslateMessage ( (LPMSG) & msg);
  120.       DispatchMessage ( (LPMSG) & msg);
  121.       }
  122.     }
  123.  
  124.   return (int)msg.wParam;
  125.   }
  126.  
  127.  
  128. /* Procedures which make up the window class. */
  129. long    FAR PASCAL HelloWndProc (hWnd, message, wParam, lParam)
  130. HWND hWnd;
  131. unsigned    message;
  132. WORD wParam;
  133. LONG lParam;
  134.   {
  135.   switch (message)
  136.     {
  137.     case WM_COMMAND:
  138.          /*** if the dialog box does not currently exist ***/
  139.       if (!hYourTurnDlg)
  140.         hYourTurnDlg = CreateDialog (hInst, MAKEINTRESOURCE (5), hWnd, lpprocSHAKE);
  141.          /*** create the dialog box and assign "hYourTurnDlg" to its handle ***/
  142.       break;
  143.  
  144.     case WM_DESTROY:
  145.       PostQuitMessage (0);
  146.       break;
  147.  
  148.     default:
  149.       return DefWindowProc (hWnd, message, wParam, lParam);
  150.       break;
  151.     }
  152.   return (0L);
  153.   }
  154.