学习windows编程 day4 之 自定义映射
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; int iMapMode; static int cxClient, cyClient; switch (message) { case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rect); //创建自定义映射 iMapMode = GetMapMode(hdc); SetMapMode(hdc, MM_ISOTROPIC); SetWindowExtEx(hdc, 100, 100, NULL); //相当于取出原来逻辑窗口的100*100像素放大为现在视口的1/2*1/2(1/4) 所以现在视口所显示的最大尺寸为200*200 SetViewportExtEx(hdc, cxClient / 2, cyClient / 2, NULL); //设置视口原点在中心 SetViewportOrgEx(hdc, cxClient / 2, cyClient / 2, NULL); //windows为了保证按比例将整个视口落在视图中,会将多余的尺寸排除在外,若是有背景,则多余为黑色(会被裁剪掉),会以最大比例占据窗口(前提是和原来设置和视口和窗口之比不变的前提下) Rectangle(hdc, -100, -100, 100, 100); Ellipse(hdc, -80, -80, 80, 80); EndPaint(hwnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }
相关推荐
mapaler 2020-06-21
MIKUScallion 2020-06-11
wallowyou 2020-03-05
Samlss 2020-02-22
linmufeng 2020-02-18
luvhl 2020-01-10
LodbkMi 2019-04-24
Dickzeng 2019-07-01
Irelia 2019-07-01
laxexue 2019-06-30
飞翔的鱼 2019-06-30
我的iOS王者之路 2019-06-28
yixiaof 2019-06-28
zsh 2018-07-02
yaosir 2019-06-28
xiaocaibai 2016-03-31
bertZuo 2019-06-27