Solved

Detect Rt Mouse in Dialog

Posted on 1997-03-21
1
294 Views
Last Modified: 2011-09-20
I am trying to detect a right mouse button cllick in an edit control within a dialog.
I have coded :
BEGIN_MESSAGE_MAP
   On_WM_RBUTTONDOWN()
  ...
END_MESSAGE_MAP

-- in dialog class definition --
Protected:
  afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
  ...

-- in dialog class coding --
void CSect2::OnRButtonDown(UINT nFlags, CPoint point)
{
    CWnd*  pCurWnd;

   pCurWnd = WindowFromPoint(point);
   if (pCurWnd == GetDlgItem(IDC_ITEM))
   {
       ......
   }

In debug mode, I get a break if mouse cllick is in dialog window outside of the edit control, but no break if mouse click is in edit control.
How do I detect a right mouse click in the edit control ?
Any help is appreciated.  Thanks.
0
Comment
Question by:PLRoss
1 Comment
 

Accepted Solution

by:
joesynaptics earned 100 total points
ID: 1162321

One way you can deal with this is to subcalss the MFC Edit
control.

A reference for this process is "Inside Visual C++", page
346 ff.

Assume you have a edit field IDC_EDIT1.

Construct a new class CMyEdit which derives from CEdit.

In that class, map the WM_RBUTTON_DOWN message as you
did in the example above.

Write a handler for CMyEdit::OnRButtonDown.

Declare a CMyEdit in your dialog class definition.
Lets say that you call it m_foo.

In your OnInitDialog function for your dialog class:

m_foo.SubclassDlgItem(IDC_EDIT1, this);


Disclosure:
My answer is adapted from  "Indisde Visual C++" by
David J. Kruglinski, Microsoft Press, used without
permission.  Any errors are my responsibility, not
his, of course.

--Joe Decker




0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

777 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