 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
bashar-t Guest
|
Posted: Sun Jul 30, 2006 8:10 am Post subject: How to use RegisterHotKey? |
|
|
How to use RegisterHotKey?
How to make a global hotkey in Borland C++ builder 2006 or bcb6?
please simple example.
Thanks ! |
|
| Back to top |
|
 |
JD Guest
|
Posted: Sun Jul 30, 2006 3:26 pm Post subject: Re: How to use RegisterHotKey? |
|
|
"bashar-t" <bashar-t@scs-net.org> wrote:
| Quote: |
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 |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|