Capture Left Mouse [modified]
-
1. Lets say I have a MFC SDI with a dialog containing 5 edit boxes. 2. I want to left click on any of the five edits and generate "Hello" in it. 3. I have reached the point where I can click anywhere on the dialog and generate "Hello" into one single edit box. 4. I haven't figured out how to determine if the click is in one of the edit boxes rather than anywhere in the dialog. 5. Then I need to know which edit box. So, I need advice on #4 and #5. Here is what I have: CTest.h
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
CTest.cppBEGIN_MESSAGE_MAP(CTest, CDialog) //{{AFX_MSG_MAP(CTest) ON_WM_LBUTTONDOWN() //}}AFX_MSG_MAP END_MESSAGE_MAP() ... void CTest::OnLButtonDown(UINT nFlags, CPoint point) { CDialog::OnLButtonDown(nFlags, point); //this is anywhere on the dialog GetDlgItem(IDC_EDIT_C1L1)->SetWindowText("Hello"); //if I knew where it clicked, I could target correct editbox }
Thanksmodified on Tuesday, January 01, 2008 7:07:59 PM
-
1. Lets say I have a MFC SDI with a dialog containing 5 edit boxes. 2. I want to left click on any of the five edits and generate "Hello" in it. 3. I have reached the point where I can click anywhere on the dialog and generate "Hello" into one single edit box. 4. I haven't figured out how to determine if the click is in one of the edit boxes rather than anywhere in the dialog. 5. Then I need to know which edit box. So, I need advice on #4 and #5. Here is what I have: CTest.h
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
CTest.cppBEGIN_MESSAGE_MAP(CTest, CDialog) //{{AFX_MSG_MAP(CTest) ON_WM_LBUTTONDOWN() //}}AFX_MSG_MAP END_MESSAGE_MAP() ... void CTest::OnLButtonDown(UINT nFlags, CPoint point) { CDialog::OnLButtonDown(nFlags, point); //this is anywhere on the dialog GetDlgItem(IDC_EDIT_C1L1)->SetWindowText("Hello"); //if I knew where it clicked, I could target correct editbox }
Thanksmodified on Tuesday, January 01, 2008 7:07:59 PM
Try as follows...
BOOL CTestDlg::PreTranslateMessage(MSG* pMsg) { if( pMsg->message == WM_LBUTTONDOWN ) { if(( pMsg->hwnd == GetDlgItem( IDC_EDIT1 )->m_hWnd ) || ( pMsg->hwnd == GetDlgItem( IDC_EDIT2 )->m_hWnd )) { ::SetWindowText( pMsg->hwnd, "Hello" ); } } return CDialog::PreTranslateMessage(pMsg); }
- NS - [ODBaseBtn]
-
1. Lets say I have a MFC SDI with a dialog containing 5 edit boxes. 2. I want to left click on any of the five edits and generate "Hello" in it. 3. I have reached the point where I can click anywhere on the dialog and generate "Hello" into one single edit box. 4. I haven't figured out how to determine if the click is in one of the edit boxes rather than anywhere in the dialog. 5. Then I need to know which edit box. So, I need advice on #4 and #5. Here is what I have: CTest.h
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
CTest.cppBEGIN_MESSAGE_MAP(CTest, CDialog) //{{AFX_MSG_MAP(CTest) ON_WM_LBUTTONDOWN() //}}AFX_MSG_MAP END_MESSAGE_MAP() ... void CTest::OnLButtonDown(UINT nFlags, CPoint point) { CDialog::OnLButtonDown(nFlags, point); //this is anywhere on the dialog GetDlgItem(IDC_EDIT_C1L1)->SetWindowText("Hello"); //if I knew where it clicked, I could target correct editbox }
Thanksmodified on Tuesday, January 01, 2008 7:07:59 PM
When you click on an edit control, the message goes to the edit control window, not to the dialog window. You could derive a class from CEdit and use that class to subclass the edit controls. When your CEdit-derived class gets a WM_LBUTTONDOWN message, it could notify its parent by posting an app-specific message. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: