OnLButtonDown process
-
Hello and good day. I have this one big dialog with different objects (buttons, listboxes, picturebox, static text, etc.) in it. All of these have a common process that should be called first when the user left clicks the mouse over the object. I have checked the
OnLButtonDown
method but it seems that it is not called when the user clicks over a component (for a button, it processes the OnClick method and doesn't process the OnLButtonDown). Now, the reason I want to do this is because I don't want to add an OnClick for every component I have then place the same codes over again; but instead just check a coordinates table and see if the user clicked over an object. Is this possible with OnLButtonDown or would there be any other functions I can use to achieve what I am trying to do? Thank you for the time and help. -
Hello and good day. I have this one big dialog with different objects (buttons, listboxes, picturebox, static text, etc.) in it. All of these have a common process that should be called first when the user left clicks the mouse over the object. I have checked the
OnLButtonDown
method but it seems that it is not called when the user clicks over a component (for a button, it processes the OnClick method and doesn't process the OnLButtonDown). Now, the reason I want to do this is because I don't want to add an OnClick for every component I have then place the same codes over again; but instead just check a coordinates table and see if the user clicked over an object. Is this possible with OnLButtonDown or would there be any other functions I can use to achieve what I am trying to do? Thank you for the time and help.Llasus wrote:
Now, the reason I want to do this is because I don't want to add an OnClick for every component I have then place the same codes over again;
Actually you have only to call the same piece of code, in each event handler. I think it is not a big overhead. Why do you want to go against Windows event handling mechanism?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Hello and good day. I have this one big dialog with different objects (buttons, listboxes, picturebox, static text, etc.) in it. All of these have a common process that should be called first when the user left clicks the mouse over the object. I have checked the
OnLButtonDown
method but it seems that it is not called when the user clicks over a component (for a button, it processes the OnClick method and doesn't process the OnLButtonDown). Now, the reason I want to do this is because I don't want to add an OnClick for every component I have then place the same codes over again; but instead just check a coordinates table and see if the user clicked over an object. Is this possible with OnLButtonDown or would there be any other functions I can use to achieve what I am trying to do? Thank you for the time and help.Llasus wrote:
would there be any other functions I can use to achieve what I am trying to do?
overide the PreTranslateMessage function in the dialog class and check for the WM_LBUTTONDOWN message.
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) { if( pMsg->message == WM_LBUTTONDOWN ) { if( pMsg->hwnd != m_hWnd )// ignore the message if user has clicked on the dialog { // Do the processing } } return CDialog::PreTranslateMessage( pMsg ); }
nave [OpenedFileFinder]
-
Llasus wrote:
Now, the reason I want to do this is because I don't want to add an OnClick for every component I have then place the same codes over again;
Actually you have only to call the same piece of code, in each event handler. I think it is not a big overhead. Why do you want to go against Windows event handling mechanism?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeCPallini wrote:
Actually you have only to call the same piece of code, in each event handler. I think it is not a big overhead. Why do you want to go against Windows event handling mechanism?
The problem is, there are tons of objects in there, and I think by adding one OnClick for each objects will cause the code to be longer than what it should be. Like adding OnClick for each textbox and there are 20 of them and all of those 20 contains just one call of a function. :)
-
Llasus wrote:
would there be any other functions I can use to achieve what I am trying to do?
overide the PreTranslateMessage function in the dialog class and check for the WM_LBUTTONDOWN message.
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) { if( pMsg->message == WM_LBUTTONDOWN ) { if( pMsg->hwnd != m_hWnd )// ignore the message if user has clicked on the dialog { // Do the processing } } return CDialog::PreTranslateMessage( pMsg ); }
nave [OpenedFileFinder]
-
CPallini wrote:
Actually you have only to call the same piece of code, in each event handler. I think it is not a big overhead. Why do you want to go against Windows event handling mechanism?
The problem is, there are tons of objects in there, and I think by adding one OnClick for each objects will cause the code to be longer than what it should be. Like adding OnClick for each textbox and there are 20 of them and all of those 20 contains just one call of a function. :)
Actually MFC allows to map messages of multiple controls to a single handler, provided their
ID
s are contiguous, see for instance [^] :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Actually MFC allows to map messages of multiple controls to a single handler, provided their
ID
s are contiguous, see for instance [^] :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Hello and good day. I have this one big dialog with different objects (buttons, listboxes, picturebox, static text, etc.) in it. All of these have a common process that should be called first when the user left clicks the mouse over the object. I have checked the
OnLButtonDown
method but it seems that it is not called when the user clicks over a component (for a button, it processes the OnClick method and doesn't process the OnLButtonDown). Now, the reason I want to do this is because I don't want to add an OnClick for every component I have then place the same codes over again; but instead just check a coordinates table and see if the user clicked over an object. Is this possible with OnLButtonDown or would there be any other functions I can use to achieve what I am trying to do? Thank you for the time and help.What about WM_MOUSEACTIVATE? Sincerely, Spy++
-
What about WM_MOUSEACTIVATE? Sincerely, Spy++
Within the WM_MOUSEACTIVATE handler, I guess you could call GetDlgCtrlID(GetFocus()) to get the identity of the control.
-
What about WM_MOUSEACTIVATE? Sincerely, Spy++
//In DlgProc: if ((msg == WM_MOUSEACTIVATE) && (HIWORD(lParam) == WM_LBUTTONDOWN)) { POINT pt; GetCursorPos(&pt); int ctrlID = GetDlgCtrlID(WindowFromPoint(pt))); }
-
//In DlgProc: if ((msg == WM_MOUSEACTIVATE) && (HIWORD(lParam) == WM_LBUTTONDOWN)) { POINT pt; GetCursorPos(&pt); int ctrlID = GetDlgCtrlID(WindowFromPoint(pt))); }
You can write your answers at one message. ;)
-
CPallini wrote:
Actually you have only to call the same piece of code, in each event handler. I think it is not a big overhead. Why do you want to go against Windows event handling mechanism?
The problem is, there are tons of objects in there, and I think by adding one OnClick for each objects will cause the code to be longer than what it should be. Like adding OnClick for each textbox and there are 20 of them and all of those 20 contains just one call of a function. :)
Llasus wrote:
...cause the code to be longer than what it should be.
You can't seriously think this is a problem, can you? :rolleyes: :omg: See here for more.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Llasus wrote:
...cause the code to be longer than what it should be.
You can't seriously think this is a problem, can you? :rolleyes: :omg: See here for more.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
//In DlgProc: if ((msg == WM_MOUSEACTIVATE) && (HIWORD(lParam) == WM_LBUTTONDOWN)) { POINT pt; GetCursorPos(&pt); int ctrlID = GetDlgCtrlID(WindowFromPoint(pt))); }