Solved

Capturing clicks and double-clicks in Rich Edit controls

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 48
Add content to output file 4 62
How to determine file rename from EventLog ? 2 41
wordcount challenge 11 107
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

25 Experts available now in Live!

Get 1:1 Help Now