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 @   天子骄龙  阅读(195)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
历史上的今天:
2019-04-25 命令链接按钮QCommandLinkButton
点击右上角即可分享
微信分享提示

目录导航