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

  1. /*
  2.  *
  3.  *   qchecked.c
  4.  *
  5.  *   This program demonstrates the use of the IsDlgButtonChecked function.
  6.  *   IsDlgButtonChecked checks to see if the given button control or 3 state
  7.  *   button is checked. That is not the same as seeing if the control has
  8.  *   been chosen. To enact the dialog box, choose the "DIALOG" menu
  9.  *   selection. To invoke a call to IsDlgButtonChecked,choose one of the two
  10.  *   check boxes in the dialog box.
  11.  *
  12.  */
  13.  
  14. #include "windows.h"
  15. #include "qchecked.h"
  16.  
  17. HANDLE hInst;
  18.  
  19. FARPROC lpprocDialog;
  20. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  21. BOOL FAR PASCAL DialogBoxProc(HWND, unsigned, WORD, LONG);
  22.  
  23.  
  24. int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  25. HANDLE     hInstance, hPrevInstance;
  26. LPSTR     lpszCmdLine;
  27. int     cmdShow;
  28.   {
  29.   MSG        msg;
  30.   HWND        hWnd;
  31.   HMENU     hMenu;
  32.   WNDCLASS  wndclass;
  33.  
  34.   if (!hPrevInstance)
  35.     {
  36.     wndclass.style        = CS_HREDRAW | CS_VREDRAW;
  37.     wndclass.lpfnWndProc    = WndProc;
  38.     wndclass.cbClsExtra     = 0;
  39.     wndclass.cbWndExtra     = 0;
  40.     wndclass.hInstance        = hInstance;
  41.     wndclass.hIcon        = NULL;
  42.     wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
  43.     wndclass.hbrBackground  = GetStockObject(WHITE_BRUSH);
  44.     wndclass.lpszMenuName   = NULL;
  45.     wndclass.lpszClassName  = "Sample Application";
  46.  
  47.     if (!RegisterClass(&wndclass))
  48.       return FALSE;
  49.     }
  50.  
  51.   hWnd = CreateWindow("Sample Application",
  52.               "IsDlgItemChecked",
  53.               WS_OVERLAPPEDWINDOW,
  54.               CW_USEDEFAULT,
  55.               CW_USEDEFAULT,
  56.               CW_USEDEFAULT,
  57.               CW_USEDEFAULT,
  58.               NULL,
  59.               NULL,
  60.               hInstance,
  61.               NULL);
  62.  
  63.   hInst = hInstance;
  64.   lpprocDialog = MakeProcInstance((FARPROC)DialogBoxProc, hInst);
  65.   ShowWindow(hWnd, cmdShow);
  66.   UpdateWindow(hWnd);
  67.   hMenu = LoadMenu(hInstance, "qchecked");
  68.   SetMenu(hWnd, hMenu);
  69.  
  70.   while (GetMessage(&msg, NULL, 0, 0))
  71.     {
  72.     TranslateMessage(&msg);
  73.     DispatchMessage(&msg);
  74.     }
  75.   FreeProcInstance (lpprocDialog);
  76.   return msg.wParam;
  77.   }
  78.  
  79.  
  80. long FAR PASCAL WndProc(hWnd, message, wParam, lParam)
  81. HWND       hWnd;
  82. unsigned   message;
  83. WORD       wParam;
  84. LONG       lParam;
  85.   {
  86.   switch (message)
  87.     {
  88.     case WM_COMMAND:
  89.       if (wParam == 80)
  90.         {
  91.         DialogBox(hInst, MAKEINTRESOURCE(2), hWnd, lpprocDialog);
  92.         break;
  93.         }
  94.       else
  95.         return DefWindowProc(hWnd, message, wParam, lParam);
  96.  
  97.     case WM_DESTROY:
  98.       FreeProcInstance((FARPROC)lpprocDialog);
  99.       PostQuitMessage(0);
  100.       break;
  101.  
  102.     default:
  103.       return DefWindowProc(hWnd, message, wParam, lParam);
  104.     }
  105.   return(0L);
  106.   }
  107.  
  108.  
  109. BOOL FAR PASCAL DialogBoxProc(hDlg, message, wParam, lParam)
  110. HWND      hDlg;
  111. unsigned  message;
  112. WORD      wParam;
  113. LONG      lParam;
  114.   {
  115.   HWND hCtl;
  116.  
  117.   switch (message)
  118.     {
  119.     case WM_INITDIALOG:
  120.       SendDlgItemMessage(hDlg, TOP_CONTROL, BM_SETCHECK, TRUE, (LONG) 0);
  121.       return TRUE;
  122.       break;
  123.  
  124.     case WM_COMMAND:
  125.       switch (wParam)
  126.     {
  127.     case TOP_CONTROL:
  128.       if (IsDlgButtonChecked(hDlg, TOP_CONTROL))
  129.             MessageBox(GetFocus(), "IS checked", "The top control:", MB_OK);
  130.       else
  131.             MessageBox(GetFocus(), "is NOT checked", "The top control:", MB_OK);
  132.           break;
  133.  
  134.     case BOTTOM_CONTROL:
  135.       if (IsDlgButtonChecked(hDlg, BOTTOM_CONTROL))
  136.             MessageBox(GetFocus(), "IS checked", "The bottom control:", MB_OK);
  137.       else
  138.             MessageBox(GetFocus(), "is NOT checked", "The bottom control:",
  139.                        MB_OK);
  140.           break;
  141.  
  142.     case ID_OK:
  143.       EndDialog(hDlg, TRUE);
  144.           break;
  145.  
  146.     default:
  147.       MessageBox(NULL, "oops", NULL, MB_OK);
  148.       return FALSE;
  149.         }
  150.       break;
  151.  
  152.     default:
  153.       return FALSE;
  154.     }
  155.   }
  156.