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. OnLButtonDown and Up

OnLButtonDown and Up

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsgame-devtutorialquestionannouncement
3 Posts 2 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.
  • M Offline
    M Offline
    mcsherry
    wrote on last edited by
    #1

    On a dialog based application I have attached an OpenGL window which is overlaid on a static control. When the user does a left mouse button down followed by a left mouse button up on the opengl window I want an event to occur. However i have the following constraints: If the user leaves the area of the opengl window and release the left mouse button i don't want the event to happen If they then press the left mouse button down outside of the opengl model and then release it whilst in the opengl window i don't want the event to happen. However if they press the left mouse button inside the opengl window, then leave the opengl window but then come back into it and then release the mouse button the event should happen I've tried using the left button down event on the main dialog however if the user clicks (down or up) on any of the other buttons on the dialog then the main dialog doesn't handle the event. Does anyone know how to handle this set of events (or even what I'm talking about? :-D)? TIA, Andy

    M 1 Reply Last reply
    0
    • M mcsherry

      On a dialog based application I have attached an OpenGL window which is overlaid on a static control. When the user does a left mouse button down followed by a left mouse button up on the opengl window I want an event to occur. However i have the following constraints: If the user leaves the area of the opengl window and release the left mouse button i don't want the event to happen If they then press the left mouse button down outside of the opengl model and then release it whilst in the opengl window i don't want the event to happen. However if they press the left mouse button inside the opengl window, then leave the opengl window but then come back into it and then release the mouse button the event should happen I've tried using the left button down event on the main dialog however if the user clicks (down or up) on any of the other buttons on the dialog then the main dialog doesn't handle the event. Does anyone know how to handle this set of events (or even what I'm talking about? :-D)? TIA, Andy

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

      This is an MFC example, but if you're using straight APIs you can do the same. ::MessageBeep() should get called on the left button up message according to your requirements (unless I need more caffeine)...

      void CMyWindow::OnLButtonDown(UINT nFlags, CPoint point)
      {
          CWnd::OnLButtonDown(nFlags, point);

      SetCapture();
          fInCapture = true;
      }

      void CMyWindow::OnLButtonUp(UINT nFlags, CPoint point)
      {
          if (fInCapture)
          {
              ReleaseCapture();
              fInCapture = false;

      CRect clirect;
              GetClientRect(&clirect);
              if (PtInRect(&clirect, point))
              {
      //** test
                  ::MessageBeep(-1);
      //** end test
              }
          }

      CWnd::OnLButtonUp(nFlags, point);
      }

      Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      M 1 Reply Last reply
      0
      • M Mark Salsbery

        This is an MFC example, but if you're using straight APIs you can do the same. ::MessageBeep() should get called on the left button up message according to your requirements (unless I need more caffeine)...

        void CMyWindow::OnLButtonDown(UINT nFlags, CPoint point)
        {
            CWnd::OnLButtonDown(nFlags, point);

        SetCapture();
            fInCapture = true;
        }

        void CMyWindow::OnLButtonUp(UINT nFlags, CPoint point)
        {
            if (fInCapture)
            {
                ReleaseCapture();
                fInCapture = false;

        CRect clirect;
                GetClientRect(&clirect);
                if (PtInRect(&clirect, point))
                {
        //** test
                    ::MessageBeep(-1);
        //** end test
                }
            }

        CWnd::OnLButtonUp(nFlags, point);
        }

        Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        M Offline
        M Offline
        mcsherry
        wrote on last edited by
        #3

        cheers Mark, worked a treat

        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