本帖最后由 superhj1987 于 2010-03-30 14:12:02 编辑

解决方案 »

  1.   

    这个应该让rcClip有全局作用域吧
    你把它作为窗口类的成员变量再试试
      

  2.   

    试了一下,在OnInitDialog中是不起作用的,个人理解是窗口还没显示出来,另外一个可能是在OnInitDialog中的窗口坐标和显示出来窗口坐标不一样,移动了,所以不起作用,在OnPaint中是可以的,但只要一移动窗口,ClipCursor就会失效,void CDialogTestDlg::OnPaint()
    {
    CRect rcClip;
    GetWindowRect(&rcClip);
    bool bRet = ClipCursor(&rcClip); if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0); // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CDialog::OnPaint();
    }
    }
      

  3.   

    在OnInitDialog中,你查看下GetWindowRect(&rcClip); 
    中rcClip的值就知道了,这时获得值的左上角的点并不是窗口显示后的点
      

  4.   

    把代码写在OnPaint有用,但是鼠标不是应该只在对话框内移动吗,我的上面怎么可以在屏幕上随便移动?