Solved

Detect Rt Mouse in Dialog

Posted on 1997-03-21
1
299 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

839 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