首页 > 代码库 > GetClientRect
GetClientRect
这个函数好像就是对应于视口的,获取视口的宽高
#include <windows.h>LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){ static TCHAR szAppName[] = TEXT ("坐标") ; HWND hwnd ; MSG msg ; WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc= WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor= LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass)) { MessageBox (NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow (szAppName, TEXT ("坐标尺寸"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL) ; ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ;}LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ HDC hdc ; PAINTSTRUCT ps ; RECT rect; switch (message) { case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; HPEN hPen,hOldPen; hPen=CreatePen(PS_SOLID,1,RGB(0,12,255)); hOldPen=(HPEN)SelectObject(hdc,hPen);//1 Ellipse(hdc,-100, -100, 100, 100); GetClientRect(hwnd,&rect); // MoveToEx(hdc,rect.right/2,0,NULL); // LineTo(hdc,rect.right/2,rect.bottom);// MoveToEx(hdc,rect.left,rect.bottom/2,NULL);// LineTo(hdc,rect.right,rect.bottom/2);//2 Ellipse(hdc,-50,-50,50,50);// MoveToEx(hdc,0,0,NULL);// LineTo(hdc,100,100);//3 SetViewportOrgEx(hdc,200,150,NULL);// Ellipse(hdc,-50,-50,50,50);// MoveToEx(hdc,0,0,NULL);// LineTo(hdc,100,100);//3.1 SetViewportOrgEx(hdc,rect.right/2,rect.bottom/2,NULL);// Ellipse(hdc,-50,-50,50,50);// MoveToEx(hdc,0,0,NULL);// LineTo(hdc,100,100);//3.2 SetViewportOrgEx(hdc,rect.right/2,rect.bottom/2,NULL);// Ellipse(hdc,-100,-100,100,100);// MoveToEx(hdc,rect.left,0,NULL);// LineTo(hdc,rect.right,0); // MoveToEx(hdc,0,rect.top,NULL); // LineTo(hdc,0,rect.bottom);//4 SetMapMode(hdc,MM_ANISOTROPIC);// SetViewportOrgEx(hdc,380,220,NULL);// Ellipse(hdc,-100,-100,100,100);// MoveToEx(hdc,-380,0,NULL);// LineTo(hdc,380,0);// MoveToEx(hdc,0,-220,NULL);// LineTo(hdc,0,220);// MoveToEx(hdc,0,0,NULL);// LineTo(hdc,120,120); LOGBRUSH logbrush; HBRUSH hBrush,hOldBrush; logbrush.lbStyle=BS_SOLID; logbrush.lbColor=RGB(128,128,128); logbrush.lbHatch=HS_HORIZONTAL; hBrush=CreateBrushIndirect(&logbrush); hOldBrush=(HBRUSH)SelectObject(hdc,hBrush); Rectangle(hdc,-100,-100,100,100); MoveToEx(hdc,0,0,NULL); LineTo(hdc,200,200); DeleteObject(hPen); DeleteObject(hBrush); SelectObject(hdc,hOldPen); SelectObject(hdc,hOldBrush); EndPaint (hwnd, &ps) ; break; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ;}
文章相关链接 http://www.ucancode.net/faq/Coordinate-SetViewportOrg-SetWindowExt-SetViewportExt-SetMapMode.htm
GetClientRect
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。