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

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