SetWindowOrgEx() 与 SetViewOrgEx () 函数的测试

来源:互联网 发布:知乎 如何提问 编辑:程序博客网 时间:2024/06/05 20:25

在Sysmets3程序的改进过程中 两次使用 SetWindowOrgEx ()函数出错  (两次分别移动了窗口原点的横坐标和纵坐标)   


对此进行以下测试

#include <windows.h>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM) ;int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){static TCHARszAppName[] = TEXT ("窗口视口测试") ;HWNDhwnd ;MSGmsg ;WNDCLASSwndclass ;wndclass.cbClsExtra = 0 ;wndclass.cbWndExtra = 0 ;wndclass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH) ;wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;wndclass.hInstance = hInstance ;wndclass.lpfnWndProc = WndProc ;wndclass.lpszClassName = szAppName ;wndclass.lpszMenuName = NULL ;wndclass.style = CS_HREDRAW | CS_VREDRAW ;if (!RegisterClass (&wndclass)){MessageBox (NULL, TEXT("This program requires Windows NT!"), szAppName, MB_ICONERROR) ;return 0 ;}hwnd = CreateWindow (szAppName, TEXT("测试SetWindowOrgEx()"), WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_HSCROLL,  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) {HDChdc ;PAINTSTRUCTps ;switch (message){case WM_PAINT :hdc = BeginPaint (hwnd , &ps) ;TextOut (hdc, 0, 0, TEXT("0"), 1) ;TextOut (hdc, 0, 300, TEXT("300"), 3) ;TextOut (hdc, 300, 0, TEXT("300"), 3) ;TextOut (hdc, 0, 200, TEXT("200"), 3) ;TextOut (hdc, 200, 0, TEXT("200"), 3) ;TextOut (hdc, 0, 100, TEXT("100"), 3) ;TextOut (hdc, 100, 0, TEXT("100"), 3) ;TextOut (hdc, 300, 300, TEXT("1"), 1) ;SetWindowOrgEx(hdc, 0, 100, NULL) ;SetViewportOrgEx (hdc, 0, -100, NULL) ;TextOut (hdc, 300, 300, TEXT("2"), 1) ;SetWindowOrgEx(hdc, 100, 0, NULL) ;TextOut (hdc, 300, 300, TEXT("3"), 1) ;EndPaint (hwnd, &ps) ;return 0 ;case WM_DESTROY :PostQuitMessage (0) ;return 0 ;}return DefWindowProc (hwnd, message, wParam, lParam) ;}



结果证明SetWindowOrgEx()函数每次移动都是基于同一个点    ,而不是上一次的位置



0 0
原创粉丝点击