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); //各向同性(会去干预映射过程,将多余裁剪)
//SetMapMode(hdc, MM_ANISOTROPIC); //各向异性(不会去干预,会自适应)
SetWindowExtEx(hdc, , , NULL);
//相当于取出原来逻辑窗口的100*100像素放大为现在视口的1/2*1/2(1/4) 所以现在视口所显示的最大尺寸为200*200
SetViewportExtEx(hdc, cxClient / , cyClient / , NULL);
//设置视口原点在中心
SetViewportOrgEx(hdc, cxClient / , cyClient / , NULL); //MM_ISOTROPIC: windows为了保证按比例将整个视口落在视图中,会将多余的尺寸排除在外,若是有背景,则多余为黑色,会以最大比例占据窗口(前提是和原来设置和视口和窗口之比不变的前提下)
//MM_ANISOTROPIC:则不会,而是成比例拉伸
Rectangle(hdc, -, -, , );
Ellipse(hdc, -, -, , ); EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage();
return ;
} return DefWindowProc(hwnd, message, wParam, lParam);
}

上面只修改了大小对应,下面则修改了方向:

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); //各向同性(会去干预映射过程,将多余裁剪)
SetMapMode(hdc, MM_ANISOTROPIC); //各向异性(不会去干预,会自适应)
SetWindowExtEx(hdc, , , NULL);
//相当于取出原来逻辑窗口的100*100像素放大为现在视口的1/2*1/2(1/4) 所以现在视口所显示的最大尺寸为200*200 //修改这里两个值得正负可以修改视口的x,y指向
//默认MM_TEXT x向右为正 y向下为正
SetViewportExtEx(hdc, cxClient / , cyClient / , NULL);
//修改后 x向左为正 y向上为正
SetViewportExtEx(hdc, -cxClient / , -cyClient / , NULL);
//.... //设置视口原点在中心
SetViewportOrgEx(hdc, cxClient / , cyClient / , NULL); //MM_ISOTROPIC: windows为了保证按比例将整个视口落在视图中,会将多余的尺寸排除在外,若是有背景,则多余为黑色,会以最大比例占据窗口(前提是和原来设置和视口和窗口之比不变的前提下)
//MM_ANISOTROPIC:则不会,而是成比例拉伸
Rectangle(hdc, -, -, , );
Ellipse(hdc, -, -, , ); //发现采用默认MM_TEXT方式
TextOut(hdc, -, -, L"Love", );
TextOut(hdc, , , L"HAHA", ); MoveToEx(hdc, , -, NULL);
LineTo(hdc, , );
MoveToEx(hdc, -, , NULL);
LineTo(hdc, , ); EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage();
return ;
} return DefWindowProc(hwnd, message, wParam, lParam);
}
04-25 02:13