Share via


Configuring the ClearType Sample Application

To add the ClearType sample application to your platform, you need to create a project in your platform and add the source files to this project. This enables you to compile, link, and include the application in your platform.

The sample application code in this section uses the CreateFontIndirect function. This creates a logical font with characteristics are defined by the LOGFONT structure. The code also shows the use of SystemParametersInfo function. This is used to specify gamma values for the font.

To configure the ClearType sample application

  1. From the File menu, choose New Project or File, and then, on the Projects tab, choose WCE Application.

  2. In the Project name box, type a name for the project. By default, Platform Builder stores the project in a directory immediately subordinate to your platform directory. For example, %_WINCEROOT%\Public\<Platform Name>\<Project Name>. Choose OK.

  3. In the New Project Wizard dialog box, choose An empty project, and then choose Finish. A new project subdirectory is created in the platform directory.

  4. Use Windows Explorer to navigate to the project subdirectory. Using a text editor, create a new file called cleartype_sample.cpp. Cut and paste the following code into the file you just created. Save your changes.

    Note   To make the following code example easier to read, error checking is not included. This code example should not be used in a release configuration unless it has been modified to include secure error handling.

    /**********************************************************************
    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
    PARTICULAR PURPOSE.
    
    Copyright (c) 1999 Microsoft Corporation. All Rights Reserved.
    
    MODULE: 
      cleartype_sample.cpp
    
    ABSTRACT: 
      This application code draws ClearType fonts with different settings.
    **********************************************************************/
    
    #include <windows.h>
    #include <tchar.h>
    
    int WINAPI WinMain
    (
        HINSTANCE hInstance,
        HINSTANCE hInstPrev,
    #ifdef  UNDER_CE
        LPWSTR    pszCmdLine,
    #else
        LPSTR     pszCmdLine,
    #endif
        int       nCmdShow
    )
    {
    // This retrieves the device context (DC) for the primary display driver. This is not associated with a window.
    // This is only used for simplicity of the example.
    HDC hdc = GetDC(NULL);
    int nSmooth, nOldSmooth;
    // A rectangle to hold the text.
    RECT rc = { 10, 10, 100, 100};
    LOGFONT lf;
    HFONT hFontNew, hFontOld;
    int nTextHeight;
    
    // Clear out the lf structure to use when creating the font.
    memset(&lf, 0, sizeof(LOGFONT));
    
    // Retrieve the old Cleartype gamma.
    SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0, &nOldSmooth, FALSE);
    
    // Draw text with the default system font. First calculate the size of the rectangle to use.
    DrawText(hdc, TEXT("This is the default system font."), -1, &rc, DT_CALCRECT | DT_LEFT | DT_TOP);
    DrawText(hdc, TEXT("This is the default system font."), -1, &rc, DT_LEFT | DT_TOP);
    
    // Draw a Cleartype font using compatible widths. This has the same widths as the standard, but with cleartype smoothing.
    nTextHeight = rc.bottom - rc.top;
    rc.top += nTextHeight;
    rc.bottom += nTextHeight;
    lf.lfQuality = CLEARTYPE_COMPAT_QUALITY;
    hFontNew = CreateFontIndirect(&lf);
    hFontOld = (HFONT) SelectObject(hdc, hFontNew);
    DrawText(hdc, TEXT("This is a Cleartype font using compatible widths."), -1, &rc, DT_CALCRECT | DT_LEFT | DT_TOP);
    DrawText(hdc, TEXT("This is a Cleartype font using compatible widths."), -1, &rc, DT_LEFT | DT_TOP);
    SelectObject(hdc, hFontOld);
    DeleteObject(hFontNew);
    
    // Draw a Cleartype font with the standard font smoothing.
    nTextHeight = rc.bottom - rc.top;
    rc.top += nTextHeight;
    rc.bottom += nTextHeight;
    lf.lfQuality = CLEARTYPE_QUALITY;
    hFontNew = CreateFontIndirect(&lf);
    hFontOld = (HFONT) SelectObject(hdc, hFontNew);
    DrawText(hdc, TEXT("This is a Cleartype font."), -1, &rc, DT_CALCRECT | DT_LEFT | DT_TOP);
    DrawText(hdc, TEXT("This is a Cleartype font."), -1, &rc, DT_LEFT | DT_TOP);
    SelectObject(hdc, hFontOld);
    DeleteObject(hFontNew);
    
    // Draw a Cleartype font with a font smoothing of 1000.
    nSmooth = 1000;
    SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0, &nSmooth, FALSE);
    nTextHeight = rc.bottom - rc.top;
    rc.top += nTextHeight;
    rc.bottom += nTextHeight;
    lf.lfQuality = CLEARTYPE_QUALITY;
    hFontNew = CreateFontIndirect(&lf);
    hFontOld = (HFONT) SelectObject(hdc, hFontNew);
    DrawText(hdc, TEXT("This is a ClearType font w/ 1000 font smoothing."), -1, &rc, DT_CALCRECT | DT_LEFT | DT_TOP);
    DrawText(hdc, TEXT("This is a ClearType font w/ 1000 font smoothing."), -1, &rc, DT_LEFT | DT_TOP);
    SelectObject(hdc, hFontOld);
    DeleteObject(hFontNew);
    
    // Draw a ClearType font with a font smoothing of 2200.
    nSmooth = 2200;
    SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0, &nSmooth, FALSE);
    nTextHeight = rc.bottom - rc.top;
    rc.top += nTextHeight;
    rc.bottom += nTextHeight;
    lf.lfQuality = CLEARTYPE_QUALITY;
    hFontNew = CreateFontIndirect(&lf);
    hFontOld = (HFONT) SelectObject(hdc, hFontNew);
    DrawText(hdc, TEXT("This is a ClearType font w/ 2200 font smoothing."), -1, &rc, DT_CALCRECT | DT_LEFT | DT_TOP);
    DrawText(hdc, TEXT("This is a ClearType font w/ 2200 font smoothing."), -1, &rc, DT_LEFT | DT_TOP);
    
    SelectObject(hdc, hFontOld);
    DeleteObject(hFontNew);
    
    // Sleep 20 seconds to let the user see the text.
    Sleep(20000);
    
    SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0, &nOldSmooth, FALSE);
    
    DeleteDC(hdc);
    }
    
  5. In the Platform Builder Workspace window, ensure that the FileView tab is active.

  6. Right-click the Source Files folder, and choose Add Files to Folder. Select cleartype_sample.cpp and choose OK.

You are now done with configuring the ClearType sample application.

See Also

How to Implement ClearType | Working with ClearType Fonts

Last updated on Wednesday, April 13, 2005

© 2005 Microsoft Corporation. All rights reserved.