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

  1. /* 
  2.  *
  3.  *  SetDlgItemInt
  4.  *  This program demonstrates the use of the function SetDlgItemInt.
  5.  *  It sets the text of a dialog item (control) to the string representation
  6.  *  of an integer value.
  7.  */
  8.  
  9. #include "windows.h"
  10. #include "dlgint.h"
  11.  
  12. HANDLE     hInst;
  13. FARPROC  lpprocEdit;
  14.  
  15. long    FAR PASCAL SampleWndProc (HWND, unsigned, WORD, LONG);
  16. BOOL FAR PASCAL EditProc (HWND, unsigned, WORD, LONG);
  17.  
  18. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  19. HANDLE    hInstance, hPrevInstance;
  20. LPSTR     lpszCmdLine;
  21. int       cmdShow;
  22.   {
  23.   MSG         msg;
  24.   HWND         hWnd;
  25.   WNDCLASS   wcClass;
  26.  
  27.   if (!hPrevInstance)
  28.     {
  29.     wcClass.style       = CS_HREDRAW | CS_VREDRAW;
  30.     wcClass.lpfnWndProc    = SampleWndProc;
  31.     wcClass.cbClsExtra       = 0;
  32.     wcClass.cbWndExtra       = 0;
  33.     wcClass.hInstance       = hInstance;
  34.     wcClass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
  35.     wcClass.hIcon          = LoadIcon (hInstance, "WindowIcon");
  36.     wcClass.hCursor        = LoadCursor (NULL, IDC_ARROW);
  37.     wcClass.lpszMenuName   = MAKEINTRESOURCE (DIALOGMENU);
  38.     wcClass.lpszClassName  = "dlgint";
  39.  
  40.     if (!RegisterClass (&wcClass))
  41.       return FALSE;
  42.     }
  43.   hWnd = CreateWindow ("dlgint",
  44.                       "Sending Integers",
  45.                       WS_OVERLAPPEDWINDOW,
  46.                       50,
  47.                       50,
  48.                       600,
  49.                       250,
  50.                       NULL,
  51.                       NULL,
  52.                       hInstance,
  53.                       NULL);
  54.   hInst = hInstance;
  55.   ShowWindow (hWnd, cmdShow);
  56.   UpdateWindow (hWnd);
  57.   while (GetMessage (&msg, NULL, 0, 0))
  58.     {
  59.     TranslateMessage (&msg);
  60.     DispatchMessage (&msg);
  61.     }
  62.   return msg.wParam;
  63.   }
  64.  
  65. long    FAR PASCAL SampleWndProc (hWnd, message, wParam, lParam)
  66. HWND       hWnd;
  67. unsigned   message;
  68. WORD       wParam;
  69. LONG       lParam;
  70.   {
  71.   switch (message)
  72.     {
  73.     case WM_COMMAND:
  74.       if (wParam == ID_DIALOG)
  75.         {
  76.         lpprocEdit = MakeProcInstance ( (FARPROC) EditProc, hInst);
  77.         DialogBox (hInst, MAKEINTRESOURCE (EDITBOX), hWnd, lpprocEdit);
  78.         FreeProcInstance ( (FARPROC) lpprocEdit);
  79.         }
  80.       break;
  81.  
  82.     default:
  83.       return DefWindowProc (hWnd, message, wParam, lParam);
  84.     }
  85.   return (0L);
  86.   }
  87.  
  88.  
  89. BOOL FAR PASCAL EditProc (hDlg, message, wParam, lParam)
  90. HWND       hDlg;
  91. unsigned   message;
  92. WORD       wParam;
  93. LONG       lParam;
  94.   {
  95.   switch (message)
  96.     {
  97.     case WM_INITDIALOG:
  98.       SetDlgItemInt (hDlg, ID_EDITBOX, 12345, (BOOL)FALSE);
  99.       return TRUE;
  100.       break;
  101.  
  102.     case WM_COMMAND:
  103.       if (wParam == IDOK)
  104.         {
  105.         EndDialog (hDlg, TRUE);
  106.     return TRUE;
  107.         }
  108.       break;
  109.  
  110.     default:
  111.       return FALSE;
  112.     }
  113.   return TRUE;
  114.   }
  115.