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

  1. /*
  2.  *
  3.  * GetTextCharacterExtra
  4.  *
  5.  * This program registers a window and creates it on the screen.  The
  6.  *  program then creates the window, shows the window, and then updates
  7.  *  the window.  If the user couble clicks the right mouse button, the
  8.  *  GetTextCharacterExtra function is executed.  The intercharacter
  9.  *  spacing is returned and displayed in a message box.
  10.  *
  11.  */
  12.  
  13. #include "windows.h"
  14.  
  15. /* Global Variables */
  16. static HANDLE hInst;
  17. static HWND hWnd;
  18.  
  19. /* FORWARD REFERENCES */
  20. long FAR PASCAL WindowProc (HWND, unsigned, WORD, LONG);
  21.  
  22. /* WINMAIN */
  23. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  24. HANDLE hInstance, hPrevInstance;
  25. LPSTR lpszCmdLine;
  26. int cmdShow;
  27. {
  28.   MSG msg;
  29.  
  30.   if (!hPrevInstance)  {
  31.  
  32.      WNDCLASS rClass;
  33.  
  34.      rClass.lpszClassName = (LPSTR)"gtxtchx";
  35.      rClass.hInstance      = hInstance;
  36.      rClass.lpfnWndProc   = WindowProc;
  37.      rClass.hCursor         = LoadCursor(NULL, IDC_ARROW);
  38.      rClass.hIcon          = LoadIcon(hInstance, IDI_APPLICATION);
  39.      rClass.lpszMenuName  = (LPSTR)NULL;
  40.      rClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  41.      rClass.style            = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  42.      rClass.cbClsExtra      = 0;       /* Add double click capabilities. */
  43.      rClass.cbWndExtra      = 0;
  44.  
  45.      RegisterClass((LPWNDCLASS)&rClass);
  46.  
  47.      }
  48.    else
  49.       ;
  50.  
  51.    hInst = hInstance;
  52.  
  53.    hWnd = CreateWindow((LPSTR) "gtxtchx",
  54.                (LPSTR) "GetTextCharacterExtra", /* Create a window.         */
  55.                WS_OVERLAPPEDWINDOW,             /* Make it overlapped.      */
  56.                CW_USEDEFAULT,                   /* Use default coordinates. */
  57.                CW_USEDEFAULT,                   /* Use default coordinates. */
  58.                CW_USEDEFAULT,                   /* Use default coordinates. */
  59.                CW_USEDEFAULT,                   /* Use default coordinates. */
  60.                (HWND)NULL,
  61.                (HMENU)NULL,
  62.                (HANDLE)hInstance,
  63.                (LPSTR)NULL
  64.              );
  65.  
  66.    ShowWindow(hWnd, cmdShow);
  67.  
  68.    UpdateWindow(hWnd);
  69.  
  70.    while (GetMessage((LPMSG)&msg, NULL, 0, 0)) {
  71.        TranslateMessage(&msg);
  72.        DispatchMessage(&msg);
  73.    }
  74.  
  75.    exit(msg.wParam);
  76.  
  77. } /* WinMain */
  78.  
  79. /* WINDOWPROC */
  80.  
  81. long FAR PASCAL WindowProc(hWnd, identifier, wParam, lParam)
  82. HWND    hWnd;
  83. unsigned identifier;
  84. WORD     wParam;
  85. LONG     lParam;
  86.  
  87. {
  88.    
  89.    switch (identifier) {
  90.  
  91.      case WM_PAINT: {
  92.  
  93.            PAINTSTRUCT ps;
  94.           RECT        rRect;
  95.          HDC        hDC;
  96.  
  97.          hDC=BeginPaint(hWnd, (LPPAINTSTRUCT)&ps);
  98.          SetMapMode(hDC, MM_ANISOTROPIC);
  99.          SetWindowOrg(hDC, 0, 0);
  100.          SetWindowExt(hDC, 110, 110);
  101.          GetClientRect(hWnd, (LPRECT)&rRect);
  102.          SetViewportOrg(hDC, 0, 0);
  103.          SetViewportExt(hDC, rRect.right, rRect.bottom);
  104.          DrawText(hDC,
  105.                 (LPSTR)"Double Click Right Mouse Button To Show Intercharacter Spacing.",
  106.                 63, (LPRECT)&rRect, DT_SINGLELINE);  /* Place text to    */
  107.          EndPaint(hWnd, (LPPAINTSTRUCT)&ps);          /* prompt for test. */
  108.  
  109.       }
  110.         break;
  111.     
  112.      case WM_RBUTTONDBLCLK:                    /* If the user double    */
  113.        {                                       /* clicks on the right   */
  114.        char szbuf[80];   /* Output buffer       | mouse button, then    */
  115.        short sIntSpacing;                      /* variables and call    */
  116.        HDC hDC; /* Handle to display Context. */
  117.  
  118.        hDC = GetDC(hWnd);                      /* (after getting DC)    */
  119.        sIntSpacing = GetTextCharacterExtra(hDC); /* GetTextCharacterExtra */
  120.                                                /* (with the display     */
  121.                                                /* context of the top    */
  122.                                                /* level window.         */
  123.         sprintf(szbuf,                          /* Capture the interchar */
  124.           "%s%i%s\0",                          /* spacing information   */
  125.           "Current Intercharacter Spacing = ", /* in a zero terminated  */
  126.            (int)sIntSpacing, ".");              /* buffer.               */   
  127.         MessageBox(hWnd,                        /* Output the buffer in  */
  128.                   (LPSTR)szbuf,                /* a message box format  */
  129.                   (LPSTR)"GetTextCharacterExtra", /* so that the user   */
  130.                    MB_OK);                      /* can have a readable   */
  131.                                                /* and useful format.    */
  132.  
  133.        SetTextCharacterExtra(hDC, 10);
  134.        
  135.        MessageBox(hWnd, (LPSTR)"Set the Intercharacter Spacing to 10.",
  136.                   (LPSTR)"Setting = 10",
  137.                   MB_OK);
  138.  
  139.        sIntSpacing = GetTextCharacterExtra(hDC);
  140.  
  141.        sprintf(szbuf,                          
  142.           "%s%i%s\0",                          
  143.           "New Intercharacter Spacing = ", 
  144.            (int)sIntSpacing, ".");               
  145.         MessageBox(hWnd,                        
  146.                   (LPSTR)szbuf,                
  147.                   (LPSTR)"GetTextCharacterExtra",
  148.                    MB_OK);                      
  149.        }                                       
  150.        break;
  151.  
  152.      case WM_CLOSE: {
  153.  
  154.           DestroyWindow(hWnd);
  155.        }
  156.          break;
  157.     
  158.     case WM_DESTROY:
  159.         PostQuitMessage(0);
  160.         break;
  161.  
  162.     default:
  163.         return(DefWindowProc(hWnd, identifier, wParam, lParam));
  164.         break;
  165.  
  166.    }
  167.  
  168.    return(0L);
  169.  
  170. }
  171.