Get mouse clicked component
-
Current, I have a parent CWnd, which is displaying many other child CWnds. All my message handling job are being done in parent CWnd, as I do not have access to child CWnds' code. I wish to know which child CWnds is being clicked. I can detect the right click
afx_msg void OnContextMenu(
CWnd* pWnd,
CPoint pos
);pWnd will be the clicked child window. However, how about left click? I know I can get the mouse coordinate, and perform some calculation accordingly to iterate through see which child CWnds falll into the point. However, I just don't want to go through all this. I which I can have something like.
CWnd* childWind = mouseEvent.getParent();
-
Current, I have a parent CWnd, which is displaying many other child CWnds. All my message handling job are being done in parent CWnd, as I do not have access to child CWnds' code. I wish to know which child CWnds is being clicked. I can detect the right click
afx_msg void OnContextMenu(
CWnd* pWnd,
CPoint pos
);pWnd will be the clicked child window. However, how about left click? I know I can get the mouse coordinate, and perform some calculation accordingly to iterate through see which child CWnds falll into the point. However, I just don't want to go through all this. I which I can have something like.
CWnd* childWind = mouseEvent.getParent();
for simple child controls, override parent CWnd's PreTranslateMessage().
BOOL CMyWnd::PreTranslateMessage(MSG* pMsg)
{
BOOL b = CDialog::PreTranslateMessage(pMsg);if(pMsg->message == WM\_LBUTTONDOWN) { if(pMsg->hwnd == m\_edit.GetSafeHwnd()) MessageBox("Edit control); } return b;
}
if you need to get mouse click on edit field of combo box, or scroll bar of list box, i think you have to to subclass them.
-
Current, I have a parent CWnd, which is displaying many other child CWnds. All my message handling job are being done in parent CWnd, as I do not have access to child CWnds' code. I wish to know which child CWnds is being clicked. I can detect the right click
afx_msg void OnContextMenu(
CWnd* pWnd,
CPoint pos
);pWnd will be the clicked child window. However, how about left click? I know I can get the mouse coordinate, and perform some calculation accordingly to iterate through see which child CWnds falll into the point. However, I just don't want to go through all this. I which I can have something like.
CWnd* childWind = mouseEvent.getParent();
Please try it :) :
/*virtual*/ BOOL CYourParentWnd::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
*pResult = 0;NMHDR* pHeader = (NMHDR*) lParam;
switch (pHeader->code) {
case NM_CLICK:
{
CWnd* pcChild = CWnd::FromHandle(pHeader->hwndFrom);
//..
}
break;
//..
}return FALSE;
}They sought it with thimbles, they sought it with care; They pursued it with forks and hope; They threatened its life with a railway-share; They charmed it with smiles and soap. :)
-
Please try it :) :
/*virtual*/ BOOL CYourParentWnd::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
*pResult = 0;NMHDR* pHeader = (NMHDR*) lParam;
switch (pHeader->code) {
case NM_CLICK:
{
CWnd* pcChild = CWnd::FromHandle(pHeader->hwndFrom);
//..
}
break;
//..
}return FALSE;
}They sought it with thimbles, they sought it with care; They pursued it with forks and hope; They threatened its life with a railway-share; They charmed it with smiles and soap. :)
-
are you sure that WM_NOTIFY will be sent to parent window by all controls on mouse click?
No, I am not sure for "all" controls... ...but I would test it in the author's context :)
They sought it with thimbles, they sought it with care; They pursued it with forks and hope; They threatened its life with a railway-share; They charmed it with smiles and soap. :)
-
No, I am not sure for "all" controls... ...but I would test it in the author's context :)
They sought it with thimbles, they sought it with care; They pursued it with forks and hope; They threatened its life with a railway-share; They charmed it with smiles and soap. :)