Solved

Capturing clicks and double-clicks in Rich Edit controls

Posted on 1998-08-24
2
260 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
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 47
Need to retreive data from .TFS file exported by DVR 8 166
NotAlone Challenge 20 72
Line meaning 9 77
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now