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. Mouse out of dialog

Mouse out of dialog

Scheduled Pinned Locked Moved C / C++ / MFC
questiondebugging
7 Posts 4 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.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    If I launch a non modal dialog from a CFormView, how can I know if the mouse leave the surface of the CNonModalDlg ? Preferable I should know inside of CNonModalDialog ... I override

    OnMouseMove(UINT nFlags, CPoint point)

    void CNonMOdalDlg::OnMouseMove(UINT nFlags, CPoint point)
    {
    // TODO: Add your message handler code here and/or call default

    CPoint pt(point);	// to not mess up point
    
    CRect rectDialog;
    
    GetWindowRect(&rectDialog);
    ScreenToClient(&rectDialog);
    
    if(! rectDialog.PtInRect(pt))
    	TRACE("################################ooouttt\\n");
    
    CDialog::OnMouseMove(nFlags, point);
    

    }

    but when I leave the dialog surface, the TRACE are not signal me ...

    L D 2 Replies Last reply
    0
    • _ _Flaviu

      If I launch a non modal dialog from a CFormView, how can I know if the mouse leave the surface of the CNonModalDlg ? Preferable I should know inside of CNonModalDialog ... I override

      OnMouseMove(UINT nFlags, CPoint point)

      void CNonMOdalDlg::OnMouseMove(UINT nFlags, CPoint point)
      {
      // TODO: Add your message handler code here and/or call default

      CPoint pt(point);	// to not mess up point
      
      CRect rectDialog;
      
      GetWindowRect(&rectDialog);
      ScreenToClient(&rectDialog);
      
      if(! rectDialog.PtInRect(pt))
      	TRACE("################################ooouttt\\n");
      
      CDialog::OnMouseMove(nFlags, point);
      

      }

      but when I leave the dialog surface, the TRACE are not signal me ...

      L Offline
      L Offline
      leon de boer
      wrote on last edited by
      #2

      You set mouse capture to make it send mouse messages to your window even when out of it's area. SetCapture function (Windows)[^] There is an example in there of tracking the cursor and you can also have tracking events. TrackMouseEvent function (Windows)[^]

      In vino veritas

      1 Reply Last reply
      0
      • _ _Flaviu

        If I launch a non modal dialog from a CFormView, how can I know if the mouse leave the surface of the CNonModalDlg ? Preferable I should know inside of CNonModalDialog ... I override

        OnMouseMove(UINT nFlags, CPoint point)

        void CNonMOdalDlg::OnMouseMove(UINT nFlags, CPoint point)
        {
        // TODO: Add your message handler code here and/or call default

        CPoint pt(point);	// to not mess up point
        
        CRect rectDialog;
        
        GetWindowRect(&rectDialog);
        ScreenToClient(&rectDialog);
        
        if(! rectDialog.PtInRect(pt))
        	TRACE("################################ooouttt\\n");
        
        CDialog::OnMouseMove(nFlags, point);
        

        }

        but when I leave the dialog surface, the TRACE are not signal me ...

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Flaviu2 wrote:

        ...the TRACE are not signal me ...

        Does the if() condition evaluate to true?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        _ 1 Reply Last reply
        0
        • D David Crow

          Flaviu2 wrote:

          ...the TRACE are not signal me ...

          Does the if() condition evaluate to true?

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          _ Offline
          _ Offline
          _Flaviu
          wrote on last edited by
          #4

          As long I get out with mouse from CNonModalDlg surface, the handler are not fire at all anymore.

          L L 2 Replies Last reply
          0
          • _ _Flaviu

            As long I get out with mouse from CNonModalDlg surface, the handler are not fire at all anymore.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            And that is correct behaviour, unless you have captured the mouse as described in leon's answer above.

            1 Reply Last reply
            0
            • _ _Flaviu

              As long I get out with mouse from CNonModalDlg surface, the handler are not fire at all anymore.

              L Offline
              L Offline
              leon de boer
              wrote on last edited by
              #6

              You wont ever get the mouse move messages while the mouse is out of the client area unless you set the capture. Richard and I aren't joking there is nothing wrong. Read the detail it is very clear WM_MOUSEMOVE message (Windows)[^] WM_MOUSEMOVE message Posted to a window when the cursor moves. If the mouse is not captured, the message is posted to the window that contains the cursor. Otherwise, the message is posted to the window that has captured the mouse. You need to set capture on the mouse if you want the message outside the area. You can grab it when your dialog takes focus or sometimes it is when you select something like select a piece of text to draw. I can't mind read what you are trying to do but you need to set capture on the mouse to get that message outside the client area of the window. So perhaps start with the simple what starts the fact you want to track the mouse is there an event, a selection process? You want to track the mouse for some reason and whatever starts that process is where you set the capture. When it completes you release the capture. The set capture just needs your window handle and the release call requires no parameters it's a really simple thing and you just need to put the two lines of code in the right place. The only native window that behaves like that with default behaviour are menu boxes which start the capture when you left mouse click down. They release mouse capture on left mouse click up. That is how you can click an move along menu trees. Perhaps do the same on your dialog so you get the idea. On you dialog handler set capture to start on the left mouse click down and release capture on left mouse click up and you will suddenly see the track outside your window so long as you hold the left button mouse down just like on a menu.

              In vino veritas

              _ 1 Reply Last reply
              0
              • L leon de boer

                You wont ever get the mouse move messages while the mouse is out of the client area unless you set the capture. Richard and I aren't joking there is nothing wrong. Read the detail it is very clear WM_MOUSEMOVE message (Windows)[^] WM_MOUSEMOVE message Posted to a window when the cursor moves. If the mouse is not captured, the message is posted to the window that contains the cursor. Otherwise, the message is posted to the window that has captured the mouse. You need to set capture on the mouse if you want the message outside the area. You can grab it when your dialog takes focus or sometimes it is when you select something like select a piece of text to draw. I can't mind read what you are trying to do but you need to set capture on the mouse to get that message outside the client area of the window. So perhaps start with the simple what starts the fact you want to track the mouse is there an event, a selection process? You want to track the mouse for some reason and whatever starts that process is where you set the capture. When it completes you release the capture. The set capture just needs your window handle and the release call requires no parameters it's a really simple thing and you just need to put the two lines of code in the right place. The only native window that behaves like that with default behaviour are menu boxes which start the capture when you left mouse click down. They release mouse capture on left mouse click up. That is how you can click an move along menu trees. Perhaps do the same on your dialog so you get the idea. On you dialog handler set capture to start on the left mouse click down and release capture on left mouse click up and you will suddenly see the track outside your window so long as you hold the left button mouse down just like on a menu.

                In vino veritas

                _ Offline
                _ Offline
                _Flaviu
                wrote on last edited by
                #7

                Kindly thank you all of you, I solved my problem. It is always a pleasure to talk here ! I am trying to create a graphic menu, a menu that is in fact a CDialog, created in non modal way.

                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