Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Capture Left Mouse [modified]

Capture Left Mouse [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Oliver123
    wrote on last edited by
    #1

    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.cpp BEGIN_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 } Thanks

    modified on Tuesday, January 01, 2008 7:07:59 PM

    N M 2 Replies Last reply
    0
    • O Oliver123

      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.cpp BEGIN_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 } Thanks

      modified on Tuesday, January 01, 2008 7:07:59 PM

      N Offline
      N Offline
      Nishad S
      wrote on last edited by
      #2

      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 Reply Last reply
      0
      • O Oliver123

        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.cpp BEGIN_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 } Thanks

        modified on Tuesday, January 01, 2008 7:07:59 PM

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        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:

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups