BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to use RegisterHotKey?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API)
View previous topic :: View next topic  
Author Message
bashar-t
Guest





PostPosted: Sun Jul 30, 2006 8:10 am    Post subject: How to use RegisterHotKey? Reply with quote



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





PostPosted: Sun Jul 30, 2006 3:26 pm    Post subject: Re: How to use RegisterHotKey? Reply with quote



"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.