可视化编程——实验一

这个实验的难点在于把下面这首诗竖向排列
“故人西辞黄鹤楼”,
“烟花三月下扬州”,
“孤帆远影碧空尽”,
“唯见长江天际流”,

#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);
}

结果如图所示:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值