Solved

Detect Rt Mouse in Dialog

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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…
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

744 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

11 Experts available now in Live!

Get 1:1 Help Now