Solved

detecting a right-click

Posted on 2001-08-21
6
582 Views
Last Modified: 2012-06-21
I wanted to make a program that doesn't have a common windows title bar and that can be dragged by clicking anywhere in the form (winamp style).
So I used the following function :

void __fastcall TForm1::WMNCHitTest(TMessage &Msg)
{
    Msg.Result = HTCAPTION;
}

This funtion traps the WM_NCHITTEST message and by returning HTCAPTION allows the form to be dragged (just like if I clicked in the title bar).
As said in a help file : "The WM_NCHITTEST message is sent to a window when the cursor moves, or when A mouse button is PRESSED or RELEASED ". So the "OnMouse" events don't work anymore. The problem is, I want to detect a right-click in order to show a popup menu and as all the mouse events are trapped by that function, how can I know if a right button was clicked ?

Thanks
0
Comment
Question by:wizcool
6 Comments
 

Author Comment

by:wizcool
ID: 6411985
I forgot to say that I'm using C++Builder.
0
 
LVL 2

Expert Comment

by:LoungeLizard
ID: 6412112
Click on the form, go to the properties box on the left, select (double click) the OnMouseDown event, and then in your code examine the provided objects (Button and Shift) to determine which button was pressed.

BTW, there is an standard way of getting a pop-up menu in C++ Builder, although I can't remember exactly where you find it. I'll look this afternoon and let you know.
0
 
LVL 9

Accepted Solution

by:
BeyondWu earned 200 total points
ID: 6412265
I'm familiar with C++Builder.I use VC.
I think you should not catch the WM_NCHITTEST.(remove it)
void __fastcall TForm1::WMNCHitTest(TMessage &Msg)
{
   Msg.Result = HTCAPTION;
}

you can only catch WM_LBUTTONDOWN, if you want to move the window when the user press the left button.
void __fastcall TForm1::WMLBUTTONDOWN(TMessage &Msg)
{
   //Msg.Result = HTCAPTION;
   ::SendMessage(hThisWnd,WM_NCLBUTTONDOWN,WPARAM(HTCAPTION),MAKELPARAM(x,y));
   // MAKELPARAM(x,y) is the current mouse point.
   // maybe you can find it in the TMessage.
}

Now you can catch the right-click.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 9

Expert Comment

by:BeyondWu
ID: 6412268
Sorry, it should be "I'm not familiar with C++Builder"
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6412909
1. Usually use next code
void __fastcall TForm1::WMNCHitTest(TMessage &Msg)
{
if(GetAsyncKeyState(VK_LBUTTON)<0)
Msg.Result = HTCAPTION;
else
Msg.Result = HTCLIENT;
}
2. For detect Right click from WMNCHitTest
(or from any other function) you can use
GetAsyncKeyState API:
if (GetAsyncKeyState(VK_RBUTTON)<0 ) //right button?
  {
   ...
  }
0
 

Author Comment

by:wizcool
ID: 6420304
Although both BeyondWu's and AlexVirochovsky's solutions worked I can only accept one. So I accepted BeyondWu's because i liked it better and because he also answered first.

Thanks to you all.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

757 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

20 Experts available now in Live!

Get 1:1 Help Now