1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
void myDrawText(HWND thisHwnd){
// Start Font
HFONT hf = 0;
HDC hdc;
long lfHeight;
HGDIOBJ g_hfFont = GetStockObject(DEFAULT_GUI_FONT);
int i = 14;
hdc = GetDC(thisHwnd);
lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
hf = CreateFont(lfHeight, 0, 0, 0, 0, TRUE, 0, 0, 0, 0, 0, 0, 0, "Times New Roman");
if(hf)
{
DeleteObject(g_hfFont);
g_hfFont = (HGDIOBJ)hf;
}
else
{
MessageBox(thisHwnd, "Font creation failed!", "Error", MB_OK | MB_ICONEXCLAMATION);
}
// End font
// Start Text
char szSize[100];
char szTitle[] = "These are the dimensions of your client area:";
HGDIOBJ hfOld = SelectObject(hdc, g_hfFont);
COLORREF g_rgbText = RGB(0,0,0);
COLORREF g_rgbBackground = RGB(255,255,255);
BOOL g_bOpaque = TRUE;
RECT rc;
LPRECT prc = &rc;
GetClientRect(thisHwnd, prc);
prc->top = 20;
SetBkColor(hdc, g_rgbBackground);
i = SetTextColor(hdc, g_rgbText);
if(g_bOpaque){
SetBkMode(hdc, OPAQUE);
}
else{
SetBkMode(hdc, TRANSPARENT);
}
i = DrawText(hdc, szTitle, -1, prc, DT_WORDBREAK);
i = wsprintf(szSize, "\n{This is the left = %d,\n This is the top = %d \n\n\n\n\n, %d \n, %d \n}", prc->left, prc->top, prc->right, prc->bottom);
i = DrawText(hdc, szSize, i, prc, DT_CENTER | DT_VCENTER | DT_NOCLIP );
SelectObject(hdc, hfOld);
ReleaseDC(NULL, hdc);
// End Text
}
|