Thread View: borland.public.cppbuilder.nativeapi
2 messages
2 total messages
Started by bashar-t
Sun, 30 Jul 2006 06:29
How to use RegisterHotKey?
Author: bashar-t
Date: Sun, 30 Jul 2006 06:29
Date: Sun, 30 Jul 2006 06:29
5 lines
1016 bytes
1016 bytes
How to use RegisterHotKey? How to make a global hotkey in Borland C++ builder 2006 or bcb6? please simple example. Thanks !
Re: How to use RegisterHotKey?
Author: JD
Date: Sun, 30 Jul 2006 10:26
Date: Sun, 30 Jul 2006 10:26
96 lines
3219 bytes
3219 bytes
"bashar-t" <bashar-t@scs-net.org> wrote:
>
>How to use RegisterHotKey?
>How to make a global hotkey in Borland C++ builder 2006 or bcb6?
>please simple example.
Bob posted a link to a simple groups google. From that link,
I found this in about 2 minutes:
<start>
In the main forms OnCreate handler assign the hotkey:
If not RegisterHotkey( Handle, 1, MOD_ALT or MOD_SHIFT, VK_F9 ) Then
ShowMessage('Unable to assign Alt-Shift-F9 as hotkey.');
In the main forms OnClose event remove the handler:
UnRegisterHotkey( Handle, 1 );
Add a handler for the WM_HOTKEY message to the form:
private // form declaration
Procedure WMHotkey( Var msg: TWMHotkey );
message WM_HOTKEY;
Procedure TForm1.WMHotkey( Var msg: TWMHotkey );
Var
S: String;
Begin
If msg.hotkey = 1 Then Begin
...do stuff
End;
End;
<end>
That translates to (with minor modifications):
#define MY_HOTKEY 0x0000 //0x0000 through 0xBFFF are valid
private: // User declarations
bool Registered;
MESSAGE void __fastcall WMHotKey( TWMHotKey &Message );
public:
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER( WM_HOTKEY, TWMHotKey, WMHotKey )
END_MESSAGE_MAP( TForm )
__fastcall TForm1(TComponent* Owner);
__fastcall ~TForm1();
//-------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
Registered = ::RegisterHotkey( Handle,
MY_HOTKEY,
MOD_ALT | MOD_SHIFT,
VK_F9 );
if( ! Registered )
{
ShowMessage( "Unable to assign Alt-Shift-F9 as hotkey." );
}
}
//-------------------------------------------------------------
__fastcall TForm1::~TForm1()
{
if( Registered )
{
::UnRegisterHotkey( Handle, MY_HOTKEY );
}
}
//-------------------------------------------------------------
MESSAGE void __fastcall TForm1::WMHotKey( TWMHotKey &Message )
{
TForm::Dispatch( &Message );
if( Message.HotKey == MY_HOTKEY )
{
// There you go.
}
}
//-------------------------------------------------------------
10 minutes total. You should have been able to do that
yourself with what Bob gave you.
~ JD
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads