Code:
#include <windows.h>
#include <math.h>
LRESULT CALLBACK ProcJan (HWND, UINT, WPARAM, LPARAM);
HFONT EzCreateFont (HDC hdc, char * szFaceName, int iDeciPtHeight,
int iDeciPtWidth, int iAttributes, BOOL fLogRes) ;
#define EZ_ATTR_BOLD 1
#define EZ_ATTR_ITALIC 2
#define EZ_ATTR_UNDERLINE 4
#define EZ_ATTR_STRIKEOUT 8
HFONT EzCreateFont (HDC hdc, char * szFaceName, int iDeciPtHeight,
int iDeciPtWidth, int iAttributes, BOOL fLogRes)
{
FLOAT cxDpi, cyDpi ;
HFONT hFont ;
LOGFONT lf ;
POINT pt ;
TEXTMETRIC tm ;
SaveDC (hdc) ;
SetGraphicsMode (hdc, GM_ADVANCED) ;
ModifyWorldTransform (hdc, NULL, MWT_IDENTITY) ;
SetViewportOrgEx (hdc, 0, 0, NULL) ;
SetWindowOrgEx (hdc, 0, 0, NULL) ;
if (fLogRes)
{
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)) ;
}
pt.x = (int) (iDeciPtWidth * cxDpi / 72) ;
pt.y = (int) (iDeciPtHeight * cyDpi / 72) ;
DPtoLP (hdc, &pt, 1) ;
lf.lfHeight = - (int) (fabs (pt.y) / 10.0 + 0.5) ;
lf.lfWidth = 0 ;
lf.lfEscapement = 0 ;
lf.lfOrientation = 0 ;
lf.lfWeight = iAttributes & EZ_ATTR_BOLD ? 700 : 0 ;
lf.lfItalic = iAttributes & EZ_ATTR_ITALIC ? 1 : 0 ;
lf.lfUnderline = iAttributes & EZ_ATTR_UNDERLINE ? 1 : 0 ;
lf.lfStrikeOut = iAttributes & EZ_ATTR_STRIKEOUT ? 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 (iDeciPtWidth != 0)
{
hFont = (HFONT) SelectObject (hdc, hFont) ;
GetTextMetrics (hdc, &tm) ;
DeleteObject (SelectObject (hdc, hFont)) ;
lf.lfWidth = (int) (tm.tmAveCharWidth *
fabs (pt.x) / fabs (pt.y) + 0.5) ;
hFont = CreateFontIndirect (&lf) ;
}
RestoreDC (hdc, -1) ;
return hFont ;
}
int WINAPI WinMain (HINSTANCE hCopia, HINSTANCE hCopiaAnt,
PSTR szLinhaCmd, int iCmdMostrar)
{
static char szNomeAplic[] = "Olawin";
HWND hjan;
MSG msg;
WNDCLASSEX classejan;
classejan.cbSize = sizeof (classejan);
classejan.style = CS_HREDRAW | CS_VREDRAW;
classejan.lpfnWndProc = ProcJan;
classejan.cbClsExtra = 0;
classejan.cbWndExtra = 0;
classejan.hInstance = hCopia;
classejan.hIcon = LoadIcon (NULL, IDI_APPLICATION);
classejan.hCursor = LoadCursor (NULL, IDC_ARROW);
classejan.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
classejan.lpszMenuName = NULL;
classejan.lpszClassName = szNomeAplic;
classejan.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
RegisterClassEx (&classejan);
hjan = CreateWindow (szNomeAplic,
"Programa Ola",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hCopia,
NULL);
ShowWindow (hjan, iCmdMostrar);
UpdateWindow (hjan);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
LRESULT CALLBACK ProcJan (HWND hjan, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
HDC hcd;
PAINTSTRUCT ps;
RECT retang;
switch (iMsg)
{
case WM_PAINT :
hcd = BeginPaint (hjan, &ps);
HFONT f;
f = EzCreateFont(hcd, "Times New Roman", 120, 120, 0, TRUE);
SelectObject(hcd, f);
GetClientRect (hjan, &retang);
DrawText (hcd, "Sample Text", -1, &retang,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint (hjan, &ps);
DeleteObject(f);
return 0;
case WM_DESTROY :
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hjan, iMsg, wParam, lParam);
}