Solved

Capturing clicks and double-clicks in Rich Edit controls

Posted on 1998-08-24
2
265 Views
Last Modified: 2013-11-20
Environment: VC++ 5.0, Win NT 4.0

I am writing an application using Rich Edit controls in a modal dialog box.  I want to capture when the user clicks or doubleclicks on the Rich Edit control, but have so far been unable to do this.  When I do this with CEdit's, it works right away, so I must have to do something more than simply adding the function OnClickRichEdit through the dialog editor.  What can I do?

/Claus
0
Comment
Question by:Claus
[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
2 Comments
 
LVL 1

Accepted Solution

by:
amby earned 50 total points
ID: 1321213
A solution is to define a new window proc for your control in your application...

example:
--------

long OldWndProc;

CMyDialog::InitDialog(...)
{
  //... Code Before

  OldWndProc=SetWindowLong(m_MyRichEdit.m_hWnd, GWL_WNDPROC, (long) NewWndProc);

  //... Code After
}

LRESULT CALLBACK NewWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
  // this is the new wnd proc
  switch (uMsg) {

  case WM_LBUTTONDOWN:
    //... code
    break;

  case WM_LBUTTONUP:
    //... code
    break;
  }

  return CallWindowProc((WNDPROC)OldWndProc, hwnd, uMsg, wParam, lParam);
}

another solution is to make a class derived from CRichEditControl but someone here has already done this and it is really lot of work

in this second case, you declare

class CMyRichEditControl : public CRichEditControl
{
  ...

  // Generated message map functions
  //{{AFX_MSG(CMyRichEditControl)
    afx_msg MYRETVAL OnlButtonDown(WPARAM, LPARAM ); // added manually
    ...
  //}}AFX_MSG
  DECLARE_MESSAGE_MAP()
};

in the definition file:
-----------------------

BEGIN_MESSAGE_MAP(CMyRichEditControl, CRichEditControl)
  //{{AFX_MSG_MAP(CMixerMainDlg)
  ON_MESSAGE(WM_LBUTTONDOWN, OnlButtonDown)
END_MESSAGE_MAP()

MYRETVAL CMyRichEditControl::OnlButtonDown(WPARAM wParam, LPARAM lParam)
{
  //... blah blah
}


I prefer first solution...
0
 

Author Comment

by:Claus
ID: 1321214
I found a better solution myself in the meantime.  I can catch the messages in the PreTranslateMessage of the main dialog box.  The code looks somewhat like this:

BOOL CTbuilderDlg::PreTranslateMessage(MSG* pMsg)
{
      CRichEditCtrl *sub;

      sub = (CRichEditCtrl *)GetDlgItem(IDC_SUB2);

      switch ( pMsg->message)
      {
            case WM_LBUTTONDBLCLK:
                  if (pMsg->hwnd == sub->m_hWnd)
                        MessageBox("", "", MB_OK);
                  break;
      }

      return CDialog::PreTranslateMessage(pMsg);
}

/Claus

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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