我在想一个区域内显示多个按扭,我右击按扭时,就能够拖动按扭。

解决方案 »

  1.   

    CRect rtStatic;
    GetDlgItem(id))->GetWindowRect(rtStatic);
    判断鼠标是否在控件上
      

  2.   

    可是,我根本不知道有几个按扭,也不知道按扭ID是多少,判断鼠票是否在控件上,那需要遍历所有ID。
      

  3.   

    1.用::ChildWindowFromPointEx函数
     获取鼠标坐标后 调用 ChildWindowFromPointEx 函数获取控件句柄
    2。GetWindowLong 函数获取控件id
     ::GetWindowLong(控件句柄,GWL_ID);
      

  4.   

    http://blog.csdn.net/visualeleven/article/details/7177775
    看下这个,对话框界面上拖动按钮
      

  5.   


    部长,你写的东西非常清楚,可是当运行到“GetParent()->ScreenToClient(&rc);”时就会出错,获取当前MOUSE的坐标出错,错误提示是“testMouseMove.exe 中的 0x78aa4b2c (mfc90ud.dll) 处未处理的异常: 0xC0000005: 读取位置 0x00000020 时发生访问冲突”。
      

  6.   


    我是要得到当前控件的地址,getcursorpos是获取MOUSE当前所点的坐标,不是我想要的坐标。你可以看一下这个http://blog.csdn.net/visualeleven/article/details/7177775,你看了就清楚了
      

  7.   

    实现方式有多种另外上述错误是
    GetParent()返回 NULL引起的,把GetParent()->ScreenToClient(&rc); 改为
     ClientToScreen (&rc);  
      

  8.   

    刚这个问题解决了,可是还是实现不了,代码会在下面的代码里在形成一个死循环。
    int CWnd::RunModalLoop(DWORD dwFlags)
    {
    ASSERT(::IsWindow(m_hWnd)); // window must be created
    ASSERT(!(m_nFlags & WF_MODALLOOP)); // window must not already be in modal state // for tracking the idle time state
    BOOL bIdle = TRUE;
    LONG lIdleCount = 0;
    BOOL bShowIdle = (dwFlags & MLF_SHOWONIDLE) && !(GetStyle() & WS_VISIBLE);
    HWND hWndParent = ::GetParent(m_hWnd);
    m_nFlags |= (WF_MODALLOOP|WF_CONTINUEMODAL);
    MSG *pMsg = AfxGetCurrentMessage(); // acquire and dispatch messages until the modal state is done
    for (;;)
    {
    ASSERT(ContinueModal()); // phase1: check to see if we can do idle work
    while (bIdle &&
    !::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE))
    {
    ASSERT(ContinueModal()); // show the dialog when the message queue goes idle
    if (bShowIdle)
    {
    ShowWindow(SW_SHOWNORMAL);
    UpdateWindow();
    bShowIdle = FALSE;
    } // call OnIdle while in bIdle state
    if (!(dwFlags & MLF_NOIDLEMSG) && hWndParent != NULL && lIdleCount == 0)
    {
    // send WM_ENTERIDLE to the parent
    ::SendMessage(hWndParent, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)m_hWnd);
    }
    if ((dwFlags & MLF_NOKICKIDLE) ||
    !SendMessage(WM_KICKIDLE, MSGF_DIALOGBOX, lIdleCount++))
    {
    // stop idle processing next time
    bIdle = FALSE;
    }
    } // phase2: pump messages while available
    do
    {
    ASSERT(ContinueModal()); // pump message, but quit on WM_QUIT
    if (!AfxPumpMessage())
    {
    AfxPostQuitMessage(0);
    return -1;
    } // show the window when certain special messages rec'd
    if (bShowIdle &&
    (pMsg->message == 0x118 || pMsg->message == WM_SYSKEYDOWN))
    {
    ShowWindow(SW_SHOWNORMAL);
    UpdateWindow();
    bShowIdle = FALSE;
    } if (!ContinueModal())
    goto ExitModal; // reset "no idle" state after pumping "normal" message
    if (AfxIsIdleMessage(pMsg))
    {
    bIdle = TRUE;
    lIdleCount = 0;
    } } while (::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE));
    }

      

  9.   

    HWND WindowFromPoint(          POINT Point
    );if(::GetParent(hWnd)==GetSafeHwnd())
    {
    int GetDlgCtrlID(          HWND hwndCtl
    );
    }