#define _CRT_SECURE_NO_WARNINGS #define _CRT_NON_CONFORMING_SWPRINTFS #include<Windows.h> #include<tchar.h> LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow ) { TCHAR szAppName[] = TEXT("StokFont"); HWND hwnd; MSG msg; WNDCLASSEX wndClass; wndClass.cbSize = sizeof(WNDCLASSEX); wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wndClass.hInstance = hInstance; wndClass.lpfnWndProc = WindowProc; wndClass.lpszClassName = szAppName; wndClass.lpszMenuName = NULL; wndClass.style = CS_VREDRAW | CS_HREDRAW; if (!RegisterClassEx(&wndClass)) { MessageBox(NULL, TEXT("it requires Windows NT!"), TEXT("TIPS"), 0); return -1; } hwnd = CreateWindow( szAppName, TEXT("StokFont Window"), WS_OVERLAPPEDWINDOW|WS_VSCROLL, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); while (GetMessage(&msg, 0, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static struct { int idStockFont; TCHAR* szStockFont; }stockFonts[] { { OEM_FIXED_FONT, TEXT("OEM_FIXED_FONT") }, { ANSI_FIXED_FONT, TEXT("ANSI_FIXED_FONT") }, { ANSI_VAR_FONT, TEXT("ANSI_VAR_FONT") }, { SYSTEM_FONT, TEXT("SYSTEM_FONT") }, { DEVICE_DEFAULT_FONT, TEXT("DEVICE_DEFAULT_FONT") }, { SYSTEM_FIXED_FONT, TEXT("SYSTEM_FIXED_FONT") }, { DEFAULT_GUI_FONT, TEXT("DEFAULT_GUI_FONT") } }; static TCHAR szFormat[] = TEXT("%s:FaceName:%s CharSet:%d"); static int iFont, cxChar, cyChar; static TEXTMETRIC tm; HDC hdc; PAINTSTRUCT ps; TCHAR szBuffer[50],szTextName[LF_FACESIZE]; switch (message) { case WM_CREATE: SetScrollRange(hwnd, SB_VERT, 0, 6, TRUE); hdc = GetDC(hwnd); GetTextMetrics(hdc, &tm); cxChar = max(3 * tm.tmAveCharWidth, 2 * tm.tmMaxCharWidth); cyChar = tm.tmHeight + tm.tmExternalLeading + 3; ReleaseDC(hwnd, hdc); break; case WM_DISPLAYCHANGE: InvalidateRect(hwnd, NULL, TRUE); break; case WM_VSCROLL: switch (LOWORD(wParam)) { case SB_TOP: iFont = 0; break; case SB_BOTTOM: iFont = 6; break; case SB_LINEUP: case SB_PAGEUP: iFont--; break; case SB_LINEDOWN: case SB_PAGEDOWN: iFont++; break; case SB_THUMBTRACK: iFont = HIWORD(wParam); break; } iFont = max(0, min(6, iFont)); SetScrollPos(hwnd, SB_VERT, iFont, TRUE); InvalidateRect(hwnd, NULL, TRUE); break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); GetTextFace(hdc, LF_FACESIZE, szTextName); TextOut(hdc, 0, 0, szBuffer, _stprintf(szBuffer, szFormat, stockFonts[iFont].szStockFont, szTextName, tm.tmCharSet)); for (int i = 0; i <= 16; i++) { MoveToEx(hdc, (i + 4)*cxChar, cyChar * 2, NULL); LineTo(hdc, (i + 4)*cxChar, cyChar * 19); MoveToEx(hdc, 3 * cxChar, (i + 3)*cyChar, NULL); LineTo(hdc, 20 * cxChar, (i + 3)*cyChar); } SetTextAlign(hdc, TA_TOP | TA_CENTER); for (int i = 0; i < 16; i++) { TextOut(hdc, (i + 4)*cxChar+cxChar/2, cyChar * 2+1, szBuffer, _stprintf(szBuffer, TEXT("%X-"), i)); TextOut(hdc, 4 * cxChar, (i + 3)*cyChar+1, szBuffer, _stprintf(szBuffer, TEXT("-%X"), i)); } for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { TextOut(hdc, (j + 4)*cxChar + cxChar / 2, (i + 3)*cyChar, szBuffer, _stprintf(szBuffer, TEXT("%c"), (TCHAR)(i * 16 + j + 1))); } } EndPaint(hwnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hwnd, message, wParam, lParam); }
还是状态太差了,一个很简单的程序写了好长时间 。