zoukankan      html  css  js  c++  java
  • ClientToScreen 和ScreenToClient 用法 分类: VC++ 2013-10-30 08:15 2184人阅读 评论(0) 收藏

    ClientToScreen( )是把窗口坐标转换为屏幕坐标
    ScreenToClient( )是把屏幕坐标转换为窗口坐标
    屏幕坐标是相对于屏幕左上角的,而窗口坐标是相对于窗口用户区左上角的
    VC下,有些函数使用窗口坐标,有些使用屏幕坐标,使用时要分清。


    一个窗体分为两部分:系统区和客户区
    象标题和菜单之类的是系统区,由系统来控制,客户区就是你的地盘喽!!!
    Width, Height 是指整体的,ClientWidth, ClientHeight是指客户区的,两者相减就是
    系统区的啦!!!
    ClientToScreen是把坐标从当前窗体转化成全屏幕的!!!
    ScreenToClient是把屏幕坐标转化成相对当前窗体的坐标!!!!
     
     //Resize window to proper size based on video standard
     CRect recDstD1( 0, 0, 720, 576 );  
     static_preview_window.ClientToScreen(&recDstD1); //    recDstD1 {top=53 bottom=629 left=200 right=920} CRect

     static_preview_window.SetWindowPos(&CWnd::wndBottom, recDstD1.left, recDstD1.top, recDstD1.right - recDstD1.left + 10, new_height + 10, SWP_NOMOVE | SWP_SHOWWINDOW); 
     

    bool   m_bIsLButtonDawn =false;

    void CDrawDlg::OnMouseMove(UINT nFlags, CPoint point)
    {
    // TODO: Add your message handler code here and/or call default
    CWnd *pwnd=GetDlgItem(IDC_EDIT1);
         CDC *pdc=pwnd->GetDC();
    CRect rect;
    this->ClientToScreen(&point);
    pwnd->ScreenToClient(&point);
    pwnd->GetClientRect(&rect);

    //   HCURSOR hcur=::LoadCursorFromFile("pen.cur");
    //   SetClassLong(GetSafeHwnd(),GCL_HCURSOR,(LONG)hcur);  

    // CPen pen(PS_INSIDEFRAME,-1,RGB(255,255,255));
    //      CPen* olePen=pdc->SelectObject(&pen);
    if(rect.PtInRect(point) &&   m_bIsLButtonDawn )
    {

       pdc->DPtoLP(&m_fp);
       pdc->MoveTo(m_fp);
       pdc->DPtoLP(&point);
       pdc->LineTo(point);

    }
       m_fp=point;
    //   pdc->SelectObject(olePen);
    ReleaseDC(pdc);
    CDialog::OnMouseMove(nFlags, point);
    }

    void CDrawDlg::OnLButtonUp(UINT nFlags, CPoint point)
    {
       m_bIsLButtonDawn =false;
    // TODO: Add your message handler code here and/or call default
    /**//*
        CWnd *pwnd=GetDlgItem(IDC_EDIT1);
          CDC *pdc=pwnd->GetDC();
       CRect rect;
       this->ClientToScreen(&point);
       pwnd->ScreenToClient(&point);
       pwnd->GetClientRect(&rect);
      
       if(rect.PtInRect(point))
       {
        pdc->DPtoLP(&m_fp);
        pdc->MoveTo(m_fp);
        pdc->DPtoLP(&point);
        pdc->LineTo(point);

       }
       ReleaseDC(pdc);*/

    CDialog::OnLButtonUp(nFlags, point);
    }

    void CDrawDlg::OnLButtonDown(UINT nFlags, CPoint point)
    {
    // TODO: Add your message handler code here and/or call default
    CWnd *pwnd=GetDlgItem(IDC_EDIT1);
    CDC *pDC=pwnd->GetDC();
    CRect rect;
    this->ClientToScreen(&point);
    pwnd->ScreenToClient(&point);
    pwnd->GetClientRect(&rect);
    if(rect.PtInRect(point))
    {
       m_fp.x=point.x;
       m_fp.y=point.y;
    }
    ReleaseDC(pDC);
       m_bIsLButtonDawn =true;
    CDialog::OnLButtonDown(nFlags, point);

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    IDEA怎么自动生成serialVersionUID
    使用gcc的-l参数的时候,怎么查找函数所在库的位置
    有一个10 G 的文件,你只有有一个 2 G 的内存,找出重复最多的数字
    gdb调试使用教程
    使用autoscan自动生成makefile文件
    如何查看yum命令安装的软件的安装目录
    手机QQ邮箱app有未读邮件,图标右上角没有红色小圆点的解决方案
    谷歌google帐号(邮箱)注册时,提示此电话号码无法用于验证
    Notepad++编写的shell脚本在linux下无法执行的解决方法
    linux如何配置普通用户(非root用户)的sudo权限
  • 原文地址:https://www.cnblogs.com/mao0504/p/4706746.html
Copyright © 2011-2022 走看看