Solved

RICHEDIT and WM_LBUTTONDOWN

Posted on 1997-05-16
13
587 Views
Last Modified: 2013-12-03
I have noticed that pressing and holding the left mouse button on a RICHEDIT control puts EVERYTHING in the application on hold.  Messages just don't go through.  The breakpoint set in the application's PreTranslateMessage() (I am using MFC) is never hit until you release the button.

I would like to do some custom processing while the left mouse button is held down.  I can't figure out how to overcome that "feature" of the RICHEDIT control.
0
Comment
Question by:arkady
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
13 Comments
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1397408
Use a worker thread?

What messages are you expecting to get whilst the mouse button is down?

Do you not get mouse move message while holding down the left mouse button?

0
 

Author Comment

by:arkady
ID: 1397409
I would love to get a WM_MOUSEMOVE message, or a WM_TIMER message, but I don't get any messages at all.

I'm ultimatelly trying to implement custom scrolling when user makes a selection in a RICHEDIT control by dragging the mouse beyond the window limits.

I need custon scrolling because for certain (well justified, believe me) reasons the control is created without ES_AUTOVSCROLL and ES_AUTOHSCROLL styles, and that prevents standard scrolling performed by the RICHEDIT control itself.

I guess RICHEDIT control implements some kind of a hook, but I don't know much about it.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1397410
I assume that the rich edit control has its own message pump loop - and probably captures the mouse as well. If so, I don't know if it is possible to hook yourself into that loop somehow. I don't know enough about the internals of the rich edit control to suggest a way - I hope someone else can help you here
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 15

Accepted Solution

by:
NickRepin earned 200 total points
ID: 1397411
Send EM_SETEVENTMASK to Rich edit contol with LPARAM=0xFFFFFFFF.
Now you will receive EN_MSGFILTER notification message.
This message notifies a rich edit control's parent window of a keyboard or mouse event in the control.
So you can do your job in EN_MSGFILTER handler.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1397412
ENM_MOUSEEVENTS (instead of 0xFFFFFFFF) as LPARAM in EN_SETEVENTMASK sends EN_MSGFILTER notifications for mouse events only.
0
 

Author Comment

by:arkady
ID: 1397413
Well, I did set the event mask as suggested, and, regretfully, it didn't really help me.
The RICHEDIT control still notifies me about two events only: WM_LBUTTONDOWN and WM_LBUTTONUP, and I'm interested in getting in between.
As noted before, I'm trying to do some custom processing WHILE the left button is held down, not only WHEN the WM_LBUTTONDOWN event occurs.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1397414
Why  WM_LBUTTONDOWN and WM_LBUTTONUP only?!
My handler receives WM_MOUSEMOVE as well. As I see it is what you need. Please check your code again.

I'm using ENM_MOUSEEVENTS mask.
0
 

Author Comment

by:arkady
ID: 1397415
Sorry for being so persistent, but are you sure you get WM_MOUSEMOVE between pressing and releasing the left button?

0
 

Author Comment

by:arkady
ID: 1397416
I created a trivial dialog-based app, and then created a RICHEDIT control in the dialog.  In OnInitDialog() I set event mask with ENM_MOUSEEVENTS.  At my request, ClassWizard in Visual C++ created an WM_NOTIFY handler, OnNotify(), whilh I implemented as follows:

BOOL CRichDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
   if (((NMHDR*)lParam)->code == EN_MSGFILTER)
   {
      static BOOL bDown = FALSE;

      MSGFILTER* pMF = (MSGFILTER*)lParam;

      switch (pMF->msg)
      {
         case WM_LBUTTONDOWN:
            bDown = TRUE;
            break;
         case WM_LBUTTONUP:
            bDown = FALSE;
            break;
         case WM_MOUSEMOVE:
            if (bDown)
               TRACE2("X = %d\tY = %d\n", LOWORD(pMF->lParam), HIWORD(pMF->lParam));
            break;
         default:
            break;
      }
   }
      
   return CDialog::OnNotify(wParam, lParam, pResult);
}

The TRACE2... statement is never executed.  However, remove  "if (bDown)", and it is executed for each mouse move.
0
 

Author Comment

by:arkady
ID: 1397417
... except, of course, when the left button is down...
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1397418
I am sorry, you are right. Indeed, there are no WM_MOUSEMOVE messages when left button is pressed.

I see the only way. You can return nonzero value when pMF->msg==WM_LBUTTONDOWN. This prevents rich edit control from processing it. Of course, in this case the user will be unable to, say, select text in rich edit control, and you have to do  all this job manually. Eg, by posting several  WM_LBUTTONDOWN, WM_MOUSEMOVE, WM_LBUTTONUP to rich edit.

0
 

Author Comment

by:arkady
ID: 1397419
Yes, I understand about doing all that stuff myself...  I tried to avoid that, but...

Anyway, you did all you could.  I am a novice here, how would you like me to grade you?
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1397420
You can just reject my answer.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question