Solved

Detect Rt Mouse in Dialog

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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. …
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

730 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