在应用措施中利用热键的一段代码
在.h中:
public: // User declarations
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_HOTKEY,TMessage,OnHotKey)
END_MESSAGE_MAP(TForm)
void __fastcall TMainForm::OnHotKey(TMessage &Message); //响应热键动静
在.cpp中:
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
//注册系统热键
if(!RegisterHotKey(Handle,2000,MOD_CONTROL,VK_F12))
//这里注册的热键是Ctrl+F12
ShowMessage("热键注册失败");
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OnHotKey(TMessage &Message)
{
//添加你的代码
TForm::Dispatch(&Message);
if (!MainForm->Visible)
{
MainForm->Show();
MainForm->BringToFront();
}
else
MainForm->Hide();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
{
UnregisterHotKey(Handle, 2000);//退出措施时注销热键
}