OnLButtonDown Handler

I have a context menu in a CView-derived class. I also have a OnLButtonDown handler for the view.
Whenever a context menu is dismissed by a LButton click outside the menu, the
LButtonDown handler is called which I do not want to be called.
   Q: The LButtonDown Handler should not be called on the dismissal of Context menu By Lbutton click outside the menu.
   I have tried using The Rect (initialised to client area) as the last parameter of TrackPopupMenu but it did not work.
Any help is greatly appreciated
mfc_speakAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vachoohoCommented:
Try
TRackPopupMenu() with TPM_RETURNCMD flag and SendMessage(WM_COMMAND, nID returned from TrackPopupMenu())

this could not call the LButtonDown
but need check

0
Vinayak KumbarSr Program ManagerCommented:
Hi,

I am not sure U can do it in a straight way!?, But I can suggest U a work around.

U can do it using a flag declared in that class
BOOL m_bPopUpMenuPresent;

In the constuctor set it to FALSE;

In the Context Menu Handler, after TrackPopupMenu()
make
m_bPopUpMenuPresent = TRUE;

In LButtonDown() function do the following things

if(!m_bPopUpMenuPresent)
{
      //Do whatever U want On normal LButtonDown
}
else
{
      m_bPopUpMenuPresent = FALSE;
}

That will solve the problem.

Try it out.
0
mikeblasCommented:
Windows works by allowing the user's click to be effective, even when they're clicking to dismiss a popup context menu. (Try it yourself in any app!)

If you don't want your application to work in this standard way, you'll have to follow the advice of VinExpert and maintain a flag that lets you know the user might be dismissing the context menu. You'll also have to clear that flag in response to any of the commands on the context menu, or the user pressing ESC on the context menu, or the user killing focus, or...

..B ekiM
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Vinayak KumbarSr Program ManagerCommented:
Hi,

If maintaining the flag is the way, then we have to handle that in lot of places(overhead!!!)
0
mikeblasCommented:
Look: you're doing something very unstandard. Doing things that aren't standard is never easy--you have to work around everything and go against the stream. Managing a flag to avoid reentry is really very little overhead, anyway.

..B ekiM
0
mfc_speakAuthor Commented:
Hi mike,

I wish to know whether there is any way to dig into TrackpopupMenu code and prevent it from sending a WM_LBUTTONDOWN whenever the menu is dismissed
0
mfc_speakAuthor Commented:
I have Accepted VinExpert's comment as answer since it did work correctly.
But it did not work when the menu was dismissed with ESC key or by clicking outside the view
       Hence I would close the question only if these 2 conditions are handled
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

When the user clicks outside the view and comes back, it is not working.

For that U have to map WM_SETFOCUS and make that flag as FALSE.

But what about ESC???...
0
mikeblasCommented:
Good luck with your project.

..B ekiM
0
Vinayak KumbarSr Program ManagerCommented:
Hi mfc_speak,

I got it for ESC also in some way. For that I suggest some modifications. Move that flag m_bPopUpMenuPresent to the app's .h file and follow the abouve comments. but while accessing the flag(say CMenuApp is ur app class) do
CMenuApp *pApp = (CMenuApp *)AfxGetApp();
if(pApp->m_bPopUpMenuPresent)...

Then set focus will solve one problem. Now for escape.
Map the OnIdle() function to the app class and place the follwing code
if(m_bPopUpMenuPresent)       
{
     m_bPopUpMenuPresent = FALSE;
}

I dont know how good is putting that in OnIdle(), But it is solving our problem. So can't we do that?.

Hope it solves Ur Problem
VinExpert
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.