这个函数好像就是对应于视口的,获取视口的宽高

#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

posted on 2014-11-05 15:07  文森博客  阅读(743)  评论(0编辑  收藏  举报