Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- LRESULT CALLBACK WindowProc(HWND window, UINT msg, WPARAM wparam, LPARAM lparam)
- {
- static HWND text;
- static HFONT hfont;
- switch (msg) {
- case WM_SIZE:
- {
- RECT rc;
- GetClientRect(window, &rc);
- MoveWindow(text, 0, 0, rc.right, rc.bottom, TRUE);
- HDC hDC = GetDC(window);
- hfont = CreateFont(
- -MulDiv(rc.bottom / 2, GetDeviceCaps(hDC, LOGPIXELSY), 72),
- -MulDiv(rc.bottom / 25, GetDeviceCaps(hDC, LOGPIXELSY), 72),
- 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
- OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
- DEFAULT_PITCH, "Verdana");
- ReleaseDC(window, hDC);
- SendMessage(text, WM_SETFONT, (WPARAM)hfont, TRUE);
- DeleteObject(hfont);
- } break;
- case WM_CREATE:
- {
- RECT rc;
- CREATESTRUCT cs = *((CREATESTRUCT *) lparam);
- GetClientRect(window, &rc);
- text = CreateWindow(
- "STATIC",
- "THIS IS A MEMORY LEAK TEST",
- (WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE | SS_CENTER),
- 0, 0, rc.right, rc.bottom,
- window, 0, cs.hInstance, 0);
- } break;
- case WM_DESTROY:
- {
- PostQuitMessage(0);
- } break;
- }
- return DefWindowProc(window, msg, wparam, lparam);
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR CmdLine, int nCmdLine)
- {
- const char *CLASS_NAME = "Font Test";
- WNDCLASS wc = {0};
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = WindowProc;
- wc.hInstance = hInstance;
- wc.hbrBackground = CreateSolidBrush(RGB(0xF0, 0xF0, 0xF0));
- wc.lpszClassName = CLASS_NAME;
- RegisterClass(&wc);
- HWND window = CreateWindow(
- CLASS_NAME,
- "Font Test",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- 0, 0, hInstance, 0);
- if (!window)
- return 0;
- ShowWindow(window, nCmdLine);
- MSG msg;
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement