MFC-ClientToScreen把客户区坐标系转换为屏幕坐标系

 

win32API

    HWND hWnd = GetSafeHwnd();

    POINT Point = { 20,20 };
    BOOL b=::ClientToScreen(hWnd, &Point);//把客户区坐标系转换为屏幕坐标系
    /*
    参数1:HWND hWnd  客户区窗口句柄
    参数2:LPPOINT lpPoint   要转换的客户端坐标
            如果函数成功,则新的屏幕坐标将复制到此结构中
    返回值:如果该函数成功,则返回值为非零值。
            如果函数失败,则返回值为零
    */

    int x = Point.x;
    int y = Point.y;

    CString str;
    str.Format(_T("x=%d\r\n"),x);
    ::OutputDebugString(str);
    str.Format(_T("y=%d\r\n"), y);
    ::OutputDebugString(str);

 

 

MFC

    HWND hWnd = GetSafeHwnd();
    CWnd* pWnd = CWnd::FromHandlePermanent(hWnd); //HWND转化为CWND

    POINT Point = { 20,20 };

    pWnd->ClientToScreen(&Point);//把客户区坐标系转换为屏幕坐标系

    int x = Point.x;
    int y = Point.y;

    CString str;
    str.Format(_T("x=%d\r\n"),x);
    ::OutputDebugString(str);
    str.Format(_T("y=%d\r\n"), y);
    ::OutputDebugString(str);

 

    CString str;
    CRect rect;
    HWND hWnd = GetSafeHwnd();
    CWnd* pWnd = CWnd::FromHandlePermanent(hWnd); //HWND转化为CWND

    pWnd->GetClientRect(&rect);

    pWnd->ClientToScreen(&rect);//把客户区坐标系转换为屏幕坐标系

    int x = rect.left;
    int y = rect.top;
    int x1 = rect.right;
    int y1 = rect.bottom;

    
    str.Format(_T("x=%d\r\n"),x);
    ::OutputDebugString(str);
    str.Format(_T("y=%d\r\n"), y);
    ::OutputDebugString(str);

 

 

 

 

 

 

 

 

posted @ 2023-04-25 07:45  天子骄龙  阅读(242)  评论(0)    收藏  举报