PS Задача на мой взгляд не сложная (код взял из книги Петзольда с изменениями), но неожиданно надпись Test залезла под белое поле static ... Не понятно почему, ведь поле создается в первую очередь, а надпись должна быть на поле.
Добавлено через 14 минут и 2 секунды Часть кода где, возможно, зарыта ошибка
| Код | void About::ShowDlg(HWND hwnd, HINSTANCE hinstance) { HWND habout, hpicture; POINT point; RECT rect; DWORD dwStyle; HDC hdc; HFONT hFont; EnableWindow(hwnd, FALSE); // dwStyle = WS_POPUPWINDOW | WS_CAPTION; habout = CreateWindowEx(0, IDC_ABOUT, " About", dwStyle, 0, 0, 0, 0, hwnd, NULL, hinstance, NULL); GetWindowRect(hwnd, &rect); point.x = (long) (rect.left + (rect.right - rect.left - IDC_ABOUT_WIDTH) / 2); point.y = (long) (rect.top + (rect.bottom - rect.top - IDC_ABOUT_HEIGHT) / 2); MoveWindow(habout, point.x, point.y, IDC_ABOUT_WIDTH, IDC_ABOUT_HEIGHT, FALSE); ShowWindow(habout, SW_SHOW); // dwStyle = WS_CHILD | WS_VISIBLE | SS_WHITERECT; hpicture = CreateWindowEx(0, "static", 0, dwStyle, 0, 0, 300, 48, habout, NULL, hinstance, NULL); ShowWindow(hpicture, SW_SHOW); // char szText[] = "T e s t"; hdc = GetDC(hpicture); hFont = EasyCreateFont(hdc, "Times New Roman", 20, 0, 1, TRUE); SelectObject(hdc, hFont); TextOut(hdc, 10, 35, szText, strlen(szText)); ReleaseDC(hpicture, hdc); DeleteObject(SelectObject(hdc, GetStockObject(SYSTEM_FONT))); }
HFONT EasyCreateFont(HDC hdc, char * szFaceName, int iPtHeight, int iPtWidth, int iparam, BOOL flag) { FLOAT cxDpi, cyDpi; HFONT hFont; LOGFONT lf; POINT point; TEXTMETRIC tm; SaveDC(hdc); SetGraphicsMode(hdc, GM_ADVANCED); ModifyWorldTransform(hdc, NULL, MWT_IDENTITY); SetViewportOrgEx(hdc, 0, 0, NULL); SetWindowOrgEx(hdc, 0, 0, NULL); if (flag) { cxDpi = (FLOAT) GetDeviceCaps(hdc, LOGPIXELSX); cyDpi = (FLOAT) GetDeviceCaps(hdc, LOGPIXELSY); } else { cxDpi = (FLOAT) (25.4 * GetDeviceCaps(hdc, HORZRES) / GetDeviceCaps(hdc, HORZSIZE)); cyDpi = (FLOAT) (25.4 * GetDeviceCaps(hdc, VERTRES) / GetDeviceCaps(hdc, VERTSIZE)); } point.x = (int) ((iPtWidth * 10.0) * cxDpi / 72); point.y = (int) ((iPtHeight * 10.0) * cyDpi / 72); DPtoLP(hdc, &point, 1); lf.lfHeight = - (int) (abs(point.y) / 10.0 + 0.5); lf.lfWidth = 0; lf.lfEscapement = 0; lf.lfOrientation = 0; lf.lfWeight = iparam & 1 ? 700 : 0; lf.lfItalic = iparam & 2 ? 1 : 0; lf.lfUnderline = iparam & 4 ? 1 : 0; lf.lfStrikeOut = iparam & 8 ? 1 : 0; lf.lfCharSet = 0; lf.lfOutPrecision = 0; lf.lfClipPrecision = 0; lf.lfQuality = 0; lf.lfPitchAndFamily = 0; strcpy(lf.lfFaceName, szFaceName); hFont = CreateFontIndirect(&lf); if (iPtWidth != 0) { hFont = (HFONT) SelectObject(hdc, hFont); GetTextMetrics(hdc, &tm); DeleteObject(SelectObject(hdc, hFont)); lf.lfWidth = (int) (tm.tmAveCharWidth * abs(point.x) / abs(point.y) + 0.5); hFont = CreateFontIndirect(&lf); } RestoreDC(hdc, -1); return hFont; }
|
|