wizcool
asked on
detecting a right-click
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(TMessa ge &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
So I used the following function :
void __fastcall TForm1::WMNCHitTest(TMessa
{
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
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, it should be "I'm not familiar with C++Builder"
1. Usually use next code
void __fastcall TForm1::WMNCHitTest(TMessa ge &Msg)
{
if(GetAsyncKeyState(VK_LBU TTON)<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_RBUTT ON)<0 ) //right button?
{
...
}
void __fastcall TForm1::WMNCHitTest(TMessa
{
if(GetAsyncKeyState(VK_LBU
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_RBUTT
{
...
}
ASKER
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.
Thanks to you all.
ASKER