Visual C++ win32应用程序编写窗口时,在窗口里画了些图形,最大化后这些图形没放大,怎么才能按比例放大
代码:LRESULTCALLBACKWndProc(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam){intwmId,wmE...
代码:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
POINT points[]={220,0,220,500};
POINT pointss[]={420,0,420,500};
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// 分析菜单选择:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
HPEN hPen,hOldPen;
hPen=CreatePen(PS_SOLID,1,RGB(0,0,0));
hOldPen=(HPEN)SelectObject(hdc,hPen);
Polyline(hdc,points,2);
Polyline(hdc,pointss,2);
DeleteObject(hPen);
SelectObject(hdc,hOldPen);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// “关于”框的消息处理程序。
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
} 展开
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
POINT points[]={220,0,220,500};
POINT pointss[]={420,0,420,500};
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// 分析菜单选择:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
HPEN hPen,hOldPen;
hPen=CreatePen(PS_SOLID,1,RGB(0,0,0));
hOldPen=(HPEN)SelectObject(hdc,hPen);
Polyline(hdc,points,2);
Polyline(hdc,pointss,2);
DeleteObject(hPen);
SelectObject(hdc,hOldPen);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// “关于”框的消息处理程序。
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
} 展开
展开全部
Polyline(hdc,points,2);
Polyline(hdc,pointss,2);
这两行是以绝对坐标绘制的,单位为像素,所以当然没有按比例放大
如果要按比例放大,那么首先要Get当前DC的长和宽,然后根据比例计算出位置和长宽,需要你写代码计算的!
Polyline(hdc,pointss,2);
这两行是以绝对坐标绘制的,单位为像素,所以当然没有按比例放大
如果要按比例放大,那么首先要Get当前DC的长和宽,然后根据比例计算出位置和长宽,需要你写代码计算的!
追问
那怎么能得到当前dc的长和宽?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在窗口过程中处理WM_SIZE消息
例子:()
int cxClient, cyClient;
switch (uMsg)
{
case WM_SIZE:
cxClient = LOWORD(lParam); //cxClient为客户区的宽
cyClient = HIWORD(lParam); //cyClient为客户区的高
return 0;
case WM_PAINT:
//在这里根据cxClient和cyClient的值来确定绘图的坐标,后面代码就省略了
}
不懂再问我
例子:()
int cxClient, cyClient;
switch (uMsg)
{
case WM_SIZE:
cxClient = LOWORD(lParam); //cxClient为客户区的宽
cyClient = HIWORD(lParam); //cyClient为客户区的高
return 0;
case WM_PAINT:
//在这里根据cxClient和cyClient的值来确定绘图的坐标,后面代码就省略了
}
不懂再问我
追问
case WM_PAINT:
points[0].x=0; points[0].y=cyClient/3;points[1].x=cxClient;points[1].y=cyClient/3;
pointss[0].x=0;pointss[0].y=cyClient*2/3; pointss[1].x=cxClient; points[1].y=cyClient*2/3;
Polyline(hdc,points,2);Polyline(hdc,pointss,2);break;
这么编怎么不对啊,我就是想画两条线,把窗口等分成三份
追答
static int cxClient, cyClient;
你再试试
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询