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. WM_LBUTTONUP does not trigger, please help

WM_LBUTTONUP does not trigger, please help

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpannouncement
8 Posts 5 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.
  • I Offline
    I Offline
    Isuru_Perera
    wrote on last edited by
    #1

    I have a simple code where a user moves a window and when the user releases the window, a message box is displayed. here is my code for that. void CFldWnd::OnLButtonDown(UINT nFlags, CPoint point) { SendMessage(WM_NCLBUTTONDOWN, HTCAPTION); CWnd::OnLButtonDown(nFlags, point); } void CFldWnd::OnLButtonUp(UINT nFlags, CPoint point) { MessageBox("Button up"); CWnd::OnLButtonUp(nFlags, point); } the window moving part works fine but when i release the left mouse button, messagebox is not displayed. but when i double click on the window, message box is displayed. please help!!!! thanx in advance!

    C R I I O 5 Replies Last reply
    0
    • I Isuru_Perera

      I have a simple code where a user moves a window and when the user releases the window, a message box is displayed. here is my code for that. void CFldWnd::OnLButtonDown(UINT nFlags, CPoint point) { SendMessage(WM_NCLBUTTONDOWN, HTCAPTION); CWnd::OnLButtonDown(nFlags, point); } void CFldWnd::OnLButtonUp(UINT nFlags, CPoint point) { MessageBox("Button up"); CWnd::OnLButtonUp(nFlags, point); } the window moving part works fine but when i release the left mouse button, messagebox is not displayed. but when i double click on the window, message box is displayed. please help!!!! thanx in advance!

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      Try listening for WM_NCLBUTTONUP, but this would trigger also when the user simply clicks somewhere in the non-client area of the window.

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

      1 Reply Last reply
      0
      • I Isuru_Perera

        I have a simple code where a user moves a window and when the user releases the window, a message box is displayed. here is my code for that. void CFldWnd::OnLButtonDown(UINT nFlags, CPoint point) { SendMessage(WM_NCLBUTTONDOWN, HTCAPTION); CWnd::OnLButtonDown(nFlags, point); } void CFldWnd::OnLButtonUp(UINT nFlags, CPoint point) { MessageBox("Button up"); CWnd::OnLButtonUp(nFlags, point); } the window moving part works fine but when i release the left mouse button, messagebox is not displayed. but when i double click on the window, message box is displayed. please help!!!! thanx in advance!

        R Offline
        R Offline
        Romualdas Cukuras
        wrote on last edited by
        #3

        If the mouse is over the window, it will receive WM_LBUTTONUP, if the mouse is outside - it will not. To overcome this situation, you need to 'SetCapture' on WM_LBUTTONDOWN and 'ReleaseCapture' on WM_LBUTTONUP...

        1 Reply Last reply
        0
        • I Isuru_Perera

          I have a simple code where a user moves a window and when the user releases the window, a message box is displayed. here is my code for that. void CFldWnd::OnLButtonDown(UINT nFlags, CPoint point) { SendMessage(WM_NCLBUTTONDOWN, HTCAPTION); CWnd::OnLButtonDown(nFlags, point); } void CFldWnd::OnLButtonUp(UINT nFlags, CPoint point) { MessageBox("Button up"); CWnd::OnLButtonUp(nFlags, point); } the window moving part works fine but when i release the left mouse button, messagebox is not displayed. but when i double click on the window, message box is displayed. please help!!!! thanx in advance!

          I Offline
          I Offline
          Isuru_Perera
          wrote on last edited by
          #4

          TThank u 4 ur quick responses.. i tried both of them but the problem still exists.. I commented SendMessage(WM_NCLBUTTONDOWN,HTCATION); and put some variable assigning code there and both LBUTTONDOWN and LBUTTONUP triggers.. when put back SendMessage(WM_NCLBUTTONDOWN,HTCATION);, LBUTTONUP does not trigger.. i dont know wat to do..

          1 Reply Last reply
          0
          • I Isuru_Perera

            I have a simple code where a user moves a window and when the user releases the window, a message box is displayed. here is my code for that. void CFldWnd::OnLButtonDown(UINT nFlags, CPoint point) { SendMessage(WM_NCLBUTTONDOWN, HTCAPTION); CWnd::OnLButtonDown(nFlags, point); } void CFldWnd::OnLButtonUp(UINT nFlags, CPoint point) { MessageBox("Button up"); CWnd::OnLButtonUp(nFlags, point); } the window moving part works fine but when i release the left mouse button, messagebox is not displayed. but when i double click on the window, message box is displayed. please help!!!! thanx in advance!

            I Offline
            I Offline
            Iain Clarke Warrior Programmer
            wrote on last edited by
            #5

            The mouse up message does happen - you can check this with Spy++. But the window moving stuff happens in response to the WM_NCLBUTTONDOWN message you've manually sent. That starts a message loop looking for mouse messages that is not the MFC message loops. It moves the window until you let go of the mouse, or press escape. If you want your window to be movable with the mouse, a far more elegant way of doing it is responding to the WM_NCHITTEST message.

            class CMyMovableDialog : public CDialog
            {
            ...
            afx_msg LRESULT OnNcHitTest(CPoint point);
            ...
            };
            ...
            ON_WM_NCHITTEST()
            ...
            LRESULT CMyMovableDialog::OnNcHitTest(CPoint point)
            {
            return HTCAPTION; // make it think everywhere is a caption!
            }

            I hope that helps, Iain.

            I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[^]

            I 1 Reply Last reply
            0
            • I Iain Clarke Warrior Programmer

              The mouse up message does happen - you can check this with Spy++. But the window moving stuff happens in response to the WM_NCLBUTTONDOWN message you've manually sent. That starts a message loop looking for mouse messages that is not the MFC message loops. It moves the window until you let go of the mouse, or press escape. If you want your window to be movable with the mouse, a far more elegant way of doing it is responding to the WM_NCHITTEST message.

              class CMyMovableDialog : public CDialog
              {
              ...
              afx_msg LRESULT OnNcHitTest(CPoint point);
              ...
              };
              ...
              ON_WM_NCHITTEST()
              ...
              LRESULT CMyMovableDialog::OnNcHitTest(CPoint point)
              {
              return HTCAPTION; // make it think everywhere is a caption!
              }

              I hope that helps, Iain.

              I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[^]

              I Offline
              I Offline
              Isuru_Perera
              wrote on last edited by
              #6

              well, this still does not solve my problem, when i catch OnNcHitTest, i cannot even trigger the LBUTTONDOWN event.. anyway i learnt something out of your reply, thanx mate!

              I 1 Reply Last reply
              0
              • I Isuru_Perera

                well, this still does not solve my problem, when i catch OnNcHitTest, i cannot even trigger the LBUTTONDOWN event.. anyway i learnt something out of your reply, thanx mate!

                I Offline
                I Offline
                Iain Clarke Warrior Programmer
                wrote on last edited by
                #7

                Isuru_Perera wrote:

                well, this still does not solve my problem

                Well, I'm not sure what the problem actually is. You had a mystery of a "missing" WM_LBUTTONUP, which is now explained. So, what's the actual problem that you're trying to solve? Iain,

                I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[^]

                1 Reply Last reply
                0
                • I Isuru_Perera

                  I have a simple code where a user moves a window and when the user releases the window, a message box is displayed. here is my code for that. void CFldWnd::OnLButtonDown(UINT nFlags, CPoint point) { SendMessage(WM_NCLBUTTONDOWN, HTCAPTION); CWnd::OnLButtonDown(nFlags, point); } void CFldWnd::OnLButtonUp(UINT nFlags, CPoint point) { MessageBox("Button up"); CWnd::OnLButtonUp(nFlags, point); } the window moving part works fine but when i release the left mouse button, messagebox is not displayed. but when i double click on the window, message box is displayed. please help!!!! thanx in advance!

                  O Offline
                  O Offline
                  ouly
                  wrote on last edited by
                  #8

                  I get it,too.But when i process wm_syscommand in winproc , it run away,hope help. if(message==WM_SYSCOMMAND) { return 0; } return ViewItem::WindowProc(message, wParam, lParam);

                  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