2012-01-23 43 views
3

所以我創建了一個自定義的移動和大小這個彈出窗口,按下CTRL移動父窗口,並在邊界在客戶端移動和alt點擊大小的任何地方。問題是,現在我正在這個窗口內創建子窗口,並且在這裏出現「錯誤」。我找不到如何將消息發送到父窗口。 這是我試過的。如何無邊框從兒童在使用WM_NCHITTEST

我的父窗口

case WM_NCHITTEST: 
    //determines if the window should be moving, sizing or don't do a thing 
    return DoHitTest(pWnd, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); 

case WM_NCLBUTTONDOWN: 
    //just set the cursor for visual notice 
if (GetAsyncKeyState(VK_CONTROL) & 0x8000) 
    SetCursor(LoadCursor(NULL, IDC_SIZEALL)); 
break; 

的WndProc中處理這些消息,這是doHitTest方法

int WindowGnaq::DoHitTest(WindowBase* pWnd, int x, int y) 
{ 
    if(GetAsyncKeyState(VK_CONTROL) & 0x8000) 
     return HTCAPTION; 

    if(m_bAdjustable && GetAsyncKeyState(VK_MENU) & 0x8000) 
    { 
     short spare = 5; 
     RECT r; 
     pWnd->GetRect(r); 
     r.right -= 1; 
     r.bottom -= 1; 

     if (x < (r.left + spare) && y < (r.top + spare)) 
      return HTTOPLEFT; 
     else if (x < (r.left + spare) && y > (r.bottom - spare)) 
      return HTBOTTOMLEFT; 
     else if (x < (r.left + spare)) 
      return HTLEFT; 
     else if (x > (r.right - spare) && y < (r.top + spare)) 
      return HTTOPRIGHT; 
     else if (x > (r.right - spare) && y > (r.bottom - spare)) 
      return HTBOTTOMRIGHT; 
     else if (x > (r.right - spare)) 
      return HTRIGHT; 
     else if (y < (r.top + spare)) 
      return HTTOP; 
     else if (y > (r.bottom - spare)) 
      return HTBOTTOM; 
    } 
    return HTCLIENT; 
} 

,這就是我想要孩子的窗口過程中

case WM_NCHITTEST: 
     //this just moves the mouse to the border i don't have but doesn't make me able to move 
     return SendMessage(m_pParent->GetHandle(), WM_SYSCOMMAND, SC_MOVE, -1); 
     //this doesn't to anything 
     return PostMessage(m_pParent->GetHandle(), msg, wParam, lParam); 

     //this makes the childwindow move instead of the parent 
     return SendMessage(m_pParent->GetHandle(), msg, wParam, lParam); 

回答

4

的兒童窗口程序應在響應返回HTTRANSPARENTWM_NCHITTEST,和(援引MSDN"the message will be sent to underlying windows in the same thread until one of them returns a code that is not HTTRANSPARENT"

+0

日Thnx,完美的作品 – ColmanJ