马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
……
#define N 10
……
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
TCHAR szBuffer[128];
int i, j;
size_t iTarget;
TEXTMETRIC tm;
RECT rect;
static int cxChar, cyChar;
switch (message)
{
case WM_CREATE:
hdc = GetDC(hwnd);
GetTextMetrics(hdc, &tm);
cxChar = tm.tmAveCharWidth;
cyChar = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC(hwnd, hdc);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
for (i = 1; i <= N; i++)
{
StringCchPrintf(szBuffer, 128, TEXT("")); /为什么一定要加这一行语句?
for (j = 0; j < 2 * i - 1; j++)
{
StringCchCat(szBuffer, 128, TEXT("x"));
}
StringCchLength(szBuffer, 128, &iTarget);
GetClientRect(hwnd, &rect);
SetTextAlign(hdc, GetTextAlign(hdc) | TA_CENTER);
TextOut(hdc, (rect.right - rect.left) / 2, (rect.bottom - rect.top) / 2 - (N/2 - i +1) * cyChar, szBuffer, iTarget);
}
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
|