home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / dos_ency / 17 / sample.c next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  5.0 KB  |  138 lines

  1. /* SAMPLE.C -- Demonstration Windows Program */
  2.  
  3. #include <windows.h>
  4. #include "sample.h"
  5.  
  6. long FAR PASCAL WndProc (HWND, unsigned, WORD, LONG) ;
  7.  
  8. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  9.      HANDLE      hInstance, hPrevInstance ;
  10.      LPSTR       lpszCmdLine ;
  11.      int         nCmdShow ;
  12.      {
  13.      WNDCLASS    wndclass ;
  14.      HWND        hWnd ;
  15.      MSG         msg ;
  16.      static char szAppName [] = "Sample" ;
  17.  
  18.                /*---------------------------*/
  19.                /* Register the Window Class */
  20.                /*---------------------------*/
  21.  
  22.      if (!hPrevInstance) 
  23.           {
  24.           wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  25.           wndclass.lpfnWndProc   = WndProc ;
  26.           wndclass.cbClsExtra    = 0 ;
  27.           wndclass.cbWndExtra    = 0 ;
  28.           wndclass.hInstance     = hInstance ;
  29.           wndclass.hIcon         = NULL ;
  30.           wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  31.           wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  32.           wndclass.lpszMenuName  = szAppName ;
  33.           wndclass.lpszClassName = szAppName ;
  34.  
  35.           RegisterClass (&wndclass) ;
  36.           }
  37.  
  38.                /*----------------------------------*/
  39.                /* Create the window and display it */
  40.                /*----------------------------------*/
  41.  
  42.      hWnd = CreateWindow (szAppName, "Demonstration Windows Program",
  43.                           WS_OVERLAPPEDWINDOW,
  44.                           (int) CW_USEDEFAULT, 0,
  45.                           (int) CW_USEDEFAULT, 0,
  46.                           NULL, NULL, hInstance, NULL) ;
  47.  
  48.      ShowWindow (hWnd, nCmdShow) ;
  49.      UpdateWindow (hWnd) ;
  50.  
  51.                 /*----------------------------------------------*/
  52.                 /* Stay in message loop until a WM_QUIT message */
  53.                 /*----------------------------------------------*/
  54.  
  55.      while (GetMessage (&msg, NULL, 0, 0))
  56.           {
  57.           TranslateMessage (&msg) ;
  58.           DispatchMessage (&msg) ;
  59.           }
  60.      return msg.wParam ;
  61.      }
  62.  
  63. long FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  64.      HWND         hWnd ;
  65.      unsigned     iMessage ;
  66.      WORD         wParam ;
  67.      LONG         lParam ;
  68.      {
  69.      PAINTSTRUCT  ps ;
  70.      HFONT        hFont ;
  71.      HMENU        hMenu ;
  72.      static short xClient, yClient, nCurrentFont = IDM_SCRIPT ;
  73.      static BYTE  cFamily [] = { FF_SCRIPT, FF_MODERN, FF_ROMAN } ;
  74.      static char  *szFace [] = { "Script",  "Modern",  "Roman"  } ;
  75.  
  76.      switch (iMessage)
  77.           {
  78.  
  79.                     /*---------------------------------------------*/
  80.                     /* WM_COMMAND message: Change checkmarked font */
  81.                     /*---------------------------------------------*/
  82.  
  83.           case WM_COMMAND:
  84.                hMenu = GetMenu (hWnd) ;
  85.                CheckMenuItem (hMenu, nCurrentFont, MF_UNCHECKED) ;
  86.                nCurrentFont = wParam ;
  87.                CheckMenuItem (hMenu, nCurrentFont, MF_CHECKED) ;
  88.                InvalidateRect (hWnd, NULL, TRUE) ;
  89.                break ;
  90.  
  91.                     /*--------------------------------------------*/
  92.                     /* WM_SIZE message: Save dimensions of window */
  93.                     /*--------------------------------------------*/
  94.  
  95.           case WM_SIZE:
  96.                xClient = LOWORD (lParam) ;
  97.                yClient = HIWORD (lParam) ;
  98.                break ;
  99.  
  100.                     /*-----------------------------------------------*/
  101.                     /* WM_PAINT message: Display "Windows" in Script */
  102.                     /*-----------------------------------------------*/
  103.  
  104.           case WM_PAINT:
  105.                BeginPaint (hWnd, &ps) ;
  106.  
  107.                hFont = CreateFont (yClient, xClient / 8,
  108.                                    0, 0, 400, 0, 0, 0, OEM_CHARSET, 
  109.                                    OUT_STROKE_PRECIS, OUT_STROKE_PRECIS,
  110.                                    DRAFT_QUALITY, (BYTE) VARIABLE_PITCH |
  111.                                    cFamily [nCurrentFont - IDM_SCRIPT],
  112.                                    szFace  [nCurrentFont - IDM_SCRIPT]) ;
  113.  
  114.                hFont = SelectObject (ps.hdc, hFont) ;
  115.                TextOut (ps.hdc, 0, 0, "Windows", 7) ;
  116.  
  117.                DeleteObject (SelectObject (ps.hdc, hFont)) ;
  118.                EndPaint (hWnd, &ps) ;
  119.                break ;
  120.  
  121.                     /*---------------------------------------*/
  122.                     /* WM_DESTROY message: Post Quit message */
  123.                     /*---------------------------------------*/
  124.  
  125.           case WM_DESTROY:
  126.                PostQuitMessage (0) ;
  127.                break ;
  128.  
  129.                     /*---------------------------------------*/
  130.                     /* Other messages: Do default processing */
  131.                     /*---------------------------------------*/
  132.  
  133.           default:
  134.                return DefWindowProc (hWnd, iMessage, wParam, lParam) ;
  135.           }
  136.      return 0L ;
  137.      }
  138.