⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 showfontinfo.cpp

📁 smartphone2003上 用evc编译的 字体选择程序代码, 很有参考价值, api编写
💻 CPP
📖 第 1 页 / 共 2 页
字号:
///////////////////////////////////////////////////////////////////////////////
//
//  This is "Sample Code" and is distributable subject to the terms of the end 
//  user license agreement.
//
///////////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////////
// ShowFontMetrics.cpp
///////////////////////////////////////////////////////////////////////////////
//
//  The program allows users to browse fonts available on the device.  The use 
//  may modify the height, weight and width of each available font and view 
//  sample of the resultant font.  The user may also change the font sample 
//  text.  Additional font metrics are avaiable via "Details"
//
///////////////////////////////////////////////////////////////////////////////

#include <windows.h>
#include <aygshell.h>
#include <tpcshell.h>
#include "resource.h"


TCHAR tszSample[] = _T("The thin red line for the brown fox and lazy dog. 0123456789");

HINSTANCE g_hInst;
HWND g_hWndListBox;
HFONT g_hf;

// function declarations
BOOL CALLBACK ShowFontInfo(
    const HWND hWnd, 
    const UINT Msg, 
    const WPARAM wParam, 
    const LPARAM lParam
    );
BOOL CALLBACK MetricsProc(
    const HWND hWnd, 
    const UINT Msg, 
    const WPARAM wParam, 
    const LPARAM lParam
    );
int  CALLBACK EnumFontProc(
    const LOGFONT *,
    const TEXTMETRIC *, 
    ULONG , 
    LPARAM
    );
void ShowTextMetrics(
    HWND hWnd
    );
void UpdateSampleText(
    HWND hWnd
    );
void ShowFontMetrics(
    HWND hWnd
    );


// Purpose: Determine at runtime if the app is running on a smartphone device
static BOOL IsSmartphone() 
{
    TCHAR tszPlatform[64];

    if (TRUE == SystemParametersInfo(SPI_GETPLATFORMTYPE,
         sizeof(tszPlatform)/sizeof(*tszPlatform),tszPlatform,0))
    {
        if (0 == _tcsicmp(TEXT("Smartphone"), tszPlatform)) 
        {
            return TRUE;
        }
    }
    return FALSE;   
}


///////////////////////////////////////////////////////////////////////////////
// Function Name: WinMain
//
// Purpose: Main entry point into the HelloTAPI program
//
// Arguments: Standard WinMain arguments
//
// Return Values: 0
//
// Description:
//	WinMain function will create a list with pre-populated elements in it for 
//	viewing and manipulation.

int WINAPI WinMain(
    HINSTANCE hInstance, 
    HINSTANCE hPrevInstance,
    LPTSTR lpCmdLine,
    int nShowCmd
    )
{

    INITCOMMONCONTROLSEX ics;

	// store the hInstance
	g_hInst = hInstance;

    ics.dwSize = sizeof(INITCOMMONCONTROLSEX);
    ics.dwICC = ICC_UPDOWN_CLASS | ICC_CAPEDIT_CLASS;

    InitCommonControlsEx(&ics);

    if(TRUE == IsSmartphone())
    {
	    // create the dialog box
	    DialogBox(g_hInst, MAKEINTRESOURCE(IDD_FONTINFO_SPH), 0, (DLGPROC)ShowFontInfo);
    }
    else 
    {
	    // create the dialog box
	    DialogBox(g_hInst, MAKEINTRESOURCE(IDD_FONTINFO_PPC), 0, (DLGPROC)ShowFontInfo);
    }

	return 0;
}


VOID FillControls(
    HWND hWnd
    )
{
    // Set up font information
    HDC hdc;

    //Set the example's text
    SendMessage(GetDlgItem(hWnd, IDC_EDIT1), WM_SETTEXT, NULL, (LPARAM)tszSample);

    //Use hwndLBFont to set sample text
    g_hWndListBox = GetDlgItem(hWnd,IDD_FONTLIST);
    if (NULL == g_hWndListBox) 
    {
	    //couldn't find control, exit w/error
	    EndDialog(hWnd, 1);
    }

    g_hf = NULL;

    //Prepare g_hWndListBox
    SendMessage(g_hWndListBox, LB_RESETCONTENT, 0, 0);
    //Enum fonts
    hdc = GetDC(NULL);
    EnumFonts( hdc, NULL, &EnumFontProc, (LONG)g_hWndListBox );
    ReleaseDC(NULL, hdc);

    //Set selection to first in list
    SendMessage (g_hWndListBox, LB_SETCURSEL, 0, 0);
    //Update edit controls
    ShowTextMetrics(hWnd);
    //Show sample based on edit control values
    UpdateSampleText(hWnd);		
}


///////////////////////////////////////////////////////////////////////////////
// Function Name: ShowFontInfo
// 
// Purpose: Message Handler for IDD_FONTINFO Dialog Box
//
// Arguments: Standard Dialog Procedure Arguments
//
//
// Side Effects:
//     
// Return Values:
//	Only returns to exit the dialog
//	
// Description:
//	Dialog Procedure will allow for initial population of the list box with
//  test values.  Then respond to commands to manipulate font properties

BOOL CALLBACK ShowFontInfo(
    const HWND hWnd, 
    const UINT Msg, 
    const WPARAM wParam, 
    const LPARAM lParam
    )
{
    BOOL bReturn = TRUE;
    int nLastFontSel = 0;
    
    switch (Msg)
    {
    case WM_INITDIALOG:
        // Specify that the dialog box should stretch full screen
        SHINITDLGINFO shidi;
        ZeroMemory(&shidi, sizeof(shidi));
        shidi.dwMask = SHIDIM_FLAGS;
        if (TRUE == IsSmartphone()) 
        {
            shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;
        }
        else
        {
            shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIZEDLGFULLSCREEN;
        }

        shidi.hDlg = hWnd;
        
        // If we could not initialize the dialog box, return an error
        if (FALSE == SHInitDialog(&shidi))
        {
            MessageBox(hWnd, TEXT("Failed to init dialog"), TEXT("Failure"), MB_OK);
            
            //Failed to init, so quit app
            EndDialog (hWnd, FALSE);
            bReturn = TRUE;
        }
        
        // Set up the menu bar
        SHMENUBARINFO shmbi;
        ZeroMemory(&shmbi, sizeof(shmbi));
        shmbi.cbSize = sizeof(shmbi);
        shmbi.hwndParent = hWnd;
        shmbi.nToolBarId = IDR_SHOWFONT_MENUBAR;
        shmbi.hInstRes = g_hInst;
        
        // If we could not initialize the dialog box, return an error
        if (FALSE == SHCreateMenuBar(&shmbi))
        {
            MessageBox(hWnd, TEXT("Failed to create menu bar"), TEXT("Failure"), MB_OK);
            
            //Failed to init, so quit app
            EndDialog (hWnd, FALSE);
            bReturn = TRUE;
        }
        
        // set the title bar
        SetWindowText(hWnd, TEXT("Font Information"));
        
        //Now find out if we are a smartphone device
        if (IsSmartphone())
        {
            // In order to make Back work properly, it's necessary to 
            // override it and then call the appropriate SH API
            (void)SendMessage(shmbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK, 
                MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, 
                SHMBOF_NODEFAULT | SHMBOF_NOTIFY));
        }
        
        
        FillControls(hWnd);
        
        break;
        
    case WM_COMMAND:
        switch (LOWORD(wParam)) 
        {
        case IDM_SHOWFONT_EXIT:
            EndDialog (hWnd, TRUE);
            break;
        case IDM_SHOWFONT_METRICS:
            DialogBox (g_hInst, MAKEINTRESOURCE(IDD_METRICS), hWnd, (DLGPROC)MetricsProc);
            break;
            
        case IDD_FONTLIST:
            if(LBN_SELCHANGE == HIWORD(wParam)) 
            {
                ShowTextMetrics(hWnd);
                UpdateSampleText(hWnd);
            }
            break;
        case IDD_HEIGHT:  //Fall through
        case IDD_WIDTH:   //Fall through
        case IDD_WEIGHT:
            //Edit box lost focus, update sample
            if(EN_KILLFOCUS == HIWORD(wParam))
            {
                UpdateSampleText(hWnd);
            }
            break;
        case IDOK: //Fall through
        case IDCANCEL:
            EndDialog(hWnd, 0);
            break;
        }
        break;
        
    case WM_CLOSE:
        if(g_hf) 
        {
            DeleteObject(g_hf);
        }
        EndDialog (hWnd, 0);
        break;
        
    case WM_HOTKEY:
        // The following is necessary to get the appropriate Back key behavior 
        // (handle on key-up as per recommendations)
        if(VK_TBACK == HIWORD(lParam)) {
            SHSendBackToFocusWindow(Msg, wParam, lParam);				
        }
        break;
        
        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -