欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

画矩形

程序员文章站 2024-03-23 19:30:10
...

#include “stdafx.h”
#include “EatPeasPproject.h”
#include"GMap.h"

#define MAX_LOADSTRING 100
#define WWIDTH 700 //宽
#define WHEIGHT 740 //高
#define PI 3.1415926

// 全局变量:
HINSTANCE hInst; // 当前实例
HWND g_hwnd; //当前窗体
WCHAR szTitle[MAX_LOADSTRING]; // 标题栏文本
WCHAR szWindowClass[MAX_LOADSTRING]; // 主窗口类名

// 此代码模块中包含的函数的前向声明:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY wWinMain(In HINSTANCE hInstance,
In_opt HINSTANCE hPrevInstance,
In LPWSTR lpCmdLine,
In int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// TODO: 在此放置代码。

// 初始化全局字符串
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW(hInstance, IDC_EATPEASPPROJECT, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// 执行应用程序初始化: 
if (!InitInstance (hInstance, nCmdShow))
{
    return FALSE;
}

HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_EATPEASPPROJECT));

while (1)
{
if (PeekMessage(&msg,nullptr,0,0,PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
break;
}

		TranslateMessage(&msg);
		DispatchMessage(&msg);
}

HDC hdc = GetDC(g_hwnd);
//画矩形
//画矩形框
Rectangle(hdc, 100, 100, 200, 200);

	HBRUSH br = CreateSolidBrush(RGB(0, 0, 225));  //画刷
	MSG msg;		

	//填充矩形
	RECT rect;
	rect.left = 200;
	rect.top = 200;
	rect.right = 300;
	rect.bottom = 400;
	FillRect(hdc, &rect, br); 			 

DeleteObject(br);
ReleaseDC(g_hwnd, hdc);
}
return (int) msg.wParam;
}

//
// 函数: MyRegisterClass()
//
// 目的: 注册窗口类。
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEXW wcex; //结构体

//对结构体的成员赋值
wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style          = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc    = WndProc;					 //控制方法
wcex.cbClsExtra     = 0;
wcex.cbWndExtra     = 0;
wcex.hInstance      = hInstance;
wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_EATPEASPPROJECT));
wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_EATPEASPPROJECT);
wcex.lpszClassName  = szWindowClass;
wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

return RegisterClassExW(&wcex);

}

//
// 函数: InitInstance(HINSTANCE, int)
//
// 目的: 保存实例句柄并创建主窗口
//
// 注释:
//
// 在此函数中,我们在全局变量中保存实例句柄并
// 创建和显示主程序窗口。
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // 将实例句柄存储在全局变量中

HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
0, 0, WWIDTH, WHEIGHT, nullptr, nullptr, hInstance, nullptr); //CW_USEDEFAULT, 0(窗体相对于屏幕的坐标位置)

if (!hWnd)
{
return FALSE;
}

g_hwnd = hWnd;

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}