这个实验的难点在于把下面这首诗竖向排列 “故人西辞黄鹤楼”, “烟花三月下扬州”, “孤帆远影碧空尽”, “唯见长江天际流”,
#include<windows.h>
long WINAPI WndProc
(
HWND hWnd,
UINT iMessage,
UINT wParam,
LONG lParam
);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance, int nCmdShow);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG Message;
if (!InitWindowsClass(hInstance)) return FALSE;
if (!InitWindows(hInstance, nCmdShow))return FALSE;
while (GetMessage(&Message, 0, 0, 0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
long WINAPI WndProc(HWND hWnd, UINT iMessage, UINT wParam, LONG lParam)
{
HPEN hP;
HBRUSH hB;
static long nXChar, nYChar;
HDC hDC;
short x;
TEXTMETRIC tm;
short LnCount = 4;
PAINTSTRUCT PtStr;
const static TCHAR* textbuf[] =
{
L"故人西辞黄鹤楼",
L"烟花三月下扬州",
L"孤帆远影碧空尽",
L"唯见长江天际流",
};
switch (iMessage)
{
case WM_PAINT:
hDC = BeginPaint(hWnd, &PtStr);
for (int i = 4; i > 0; i--)
{
nXChar = 350 +( i+1) * 25;
nYChar = 10;
for (int j = 0; j < 7; j++)
{
nYChar = 10 + j * 25;
TextOut(hDC, nXChar, nYChar, (LPCWSTR)textbuf[4-i] + j, 1);
}
}
SetMapMode(hDC, MM_TEXT);
hP = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
SelectObject(hDC, hP);
MoveToEx(hDC, 80, 70, NULL);
LineTo(hDC, 40, 10);
MoveToEx(hDC, 40,10 , NULL);
LineTo(hDC, 120, 10);
MoveToEx(hDC, 80, 70, NULL);
LineTo(hDC, 120, 10);
Ellipse(hDC, 40, 70, 120, 160);
MoveToEx(hDC, 80, 160, NULL);
LineTo(hDC, 50, 190);
LineTo(hDC, 50, 220);
LineTo(hDC, 110, 220);
LineTo(hDC, 110, 190);
LineTo(hDC, 80, 160);
hB = (HBRUSH)GetStockObject(BLACK_BRUSH);
SelectObject(hDC, hB);
RoundRect(hDC, 180, 10, 260, 70, 10, 10);
Pie(hDC, 180, 70, 260, 160, 210, 70, 230, 70);
Rectangle(hDC, 180, 160, 260, 220);
EndPaint(hWnd, &PtStr);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return(DefWindowProc(hWnd, iMessage, wParam, lParam));
}
}
BOOL InitWindows(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hWnd = CreateWindow(L"Bitmap", L"202可视化_实验一",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
BOOL InitWindowsClass(HINSTANCE hInstance)
{
WNDCLASS WndClass;
WndClass.cbWndExtra = 0;
WndClass.cbClsExtra = 0;
WndClass.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH));
WndClass.hCursor = LoadCursor(NULL, MAKEINTRESOURCE(WHITE_BRUSH));
WndClass.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_APPLICATION));
WndClass.hInstance = hInstance;
WndClass.lpfnWndProc = WndProc;
WndClass.lpszClassName = L"Bitmap";
WndClass.lpszMenuName = L"Menu";
WndClass.style = 0;
return RegisterClass(&WndClass);
}
结果如图所示:
|