Strange behaviour

Help
2004-10-12
2013-04-15
  • Steven Weiss

    Steven Weiss - 2004-10-12

    Hi,
    I discovered some strange behaviour which only occurs on 1.5.0. I subclassed an edit and wanted to route all WM_LBUTTONUP to the parent (perhaps you remember...)so I wrote this

    struct EditSource : wnd_extend<edit, EditSource>, auto_mapping<EditSource>
    {
      static bool matches_hwnd(HWND hwnd)
      {
        LONG_PTR id = ::GetWindowLongPtr(hwnd, GWLP_ID);
        return id == IDC_EDIT_SOURCE;
      }
    };

    struct Edit_handler : event_handler<Edit_handler, edit, EditSource>
    {
      handle_event OnLButtonUp (l_param_lo x, l_param_hi y)
      {
        POINT pt = { x, y };       
        int pos = window()->char_from_pos(pt);       
        wnd<MainDlg> dlg = cast<MainDlg> (window()->parent());
        dlg->ClickOnFile(static_cast<unsigned> (pos));
           
        return event<WM_LBUTTONUP> ().HANDLED_BY(&me::OnLButtonUp);
      }
    };

    well, the mechanism works perfectly. but now if you click in the edit and release the mouse and move your cursor out of the window the edit gets selected as if you moved the cursor in the edit while holding the mouse button. this is so annoying...

    it's a bit hard to describe, i think it will be best to try it by yourself

     
    • John Torjo

      John Torjo - 2004-10-12

      Just a thought:

      In case you subclass controls and listen to events, I recommend you allow default processing to take over (or in advanced words, DefWindowProc).

      This means that after you process the message, mark it as "unhandled".

      It'll go something like:

      handle_event OnLButtonUp (l_param_lo x, l_param_hi y, answer a)
      {
        ...
        a = event_not_handled;
        return ...;
      }

      In your case, the edit control never got to process the "left button up" event, thus it thought the mouse was still pressed ;)

      Best,
      John

       
      • John Torjo

        John Torjo - 2004-10-12

        ... ;)

        but, you do have a point. It' my mistake that the behavior is as is.

        It should be like this: if you specifically set an answer as handled, the default handler won't be called. Otherwise, call it. I will update ;)

        Best,
        John

         
        • John Torjo

          John Torjo - 2004-10-12

          ...Thought about it for a while

          It's a little harder to implement than than meets the eye (to simply update the code to work like I've said above).

          I will add it, but later - in 2 weeks or so. Until then, please use what I've described.

          Best,
          John

           
    • Steven Weiss

      Steven Weiss - 2004-10-12

      it works now :-)
      before i posted i tried it but with reversed logic...means i set
      a = event_handled;

      don't know how i got this idea...

      mfg steven

       

Log in to post a comment.