| 導購 | 订阅 | 在线投稿
分享
 
 
 

DELPHI中使用熱鍵

來源:互聯網網民  2006-09-16 05:50:28  評論

在windows中規定應用程序熱鍵的唯一標識符取值範圍在0x0000~0xBFFF之間,動態鏈接庫的取值範圍在0xC000~0XFFFF之間。

熱鍵的輔助按鍵還包括Mod_Ctrl,Mod_Alt和Mod_Shift,對于windows兼容鍵盤,還包括windows標志鍵,Mod_Win。

熱鍵設置成功後,在程序運行過程中如果有預定義的熱鍵被按下,windows系統都會給應用程序發送一個wm_hotkey消息。

下面用一個例子演示它的使用

編譯程序、運行,如果此程序不是當前桌面顯示在最前邊的窗體,按下ctrl+alt+a後,程序界面將出現在桌面的最上。

示例程序開發平台:D7+WINXP

轉載請注明出處。

DELPHI中使用熱鍵
unit Unit1;
DELPHI中使用熱鍵

DELPHI中使用熱鍵
interface
DELPHI中使用熱鍵

DELPHI中使用熱鍵
uses
DELPHI中使用熱鍵
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
DELPHI中使用熱鍵

DELPHI中使用熱鍵
type
DELPHI中使用熱鍵
TForm1 = class(TForm)
DELPHI中使用熱鍵
procedure FormCreate(Sender: TObject);
DELPHI中使用熱鍵
procedure FormClose(Sender: TObject; var Action: TCloseAction);
DELPHI中使用熱鍵
private
DELPHI中使用熱鍵
DELPHI中使用熱鍵
...{ Private declarations }
DELPHI中使用熱鍵
public
DELPHI中使用熱鍵
DELPHI中使用熱鍵
...{ Public declarations }
DELPHI中使用熱鍵
hotkeyid :integer; //記錄熱鍵標識
DELPHI中使用熱鍵
//處理wm_hotkey消息
DELPHI中使用熱鍵
procedure WMhotkeyhandle(var msg:Tmessage);
DELPHI中使用熱鍵
message wm_hotkey;
DELPHI中使用熱鍵

DELPHI中使用熱鍵
end;
DELPHI中使用熱鍵

DELPHI中使用熱鍵
var
DELPHI中使用熱鍵
Form1: TForm1;
DELPHI中使用熱鍵

DELPHI中使用熱鍵
implementation
DELPHI中使用熱鍵

DELPHI中使用熱鍵
DELPHI中使用熱鍵
...{$R *.DFM}
DELPHI中使用熱鍵
procedure TForm1.Wmhotkeyhandle
DELPHI中使用熱鍵
(var msg:Tmessage);
DELPHI中使用熱鍵
begin
DELPHI中使用熱鍵
//判斷是否是ctrl+alt+a
DELPHI中使用熱鍵
if (msg.LParamHi=$41) and
DELPHI中使用熱鍵
(msg.lparamLo=MOD_CONTROL or mod_Alt) then
DELPHI中使用熱鍵
begin
DELPHI中使用熱鍵
msg.Result:=1;//正常返回
DELPHI中使用熱鍵
application.BringToFront;//將窗體顯示在最前邊
DELPHI中使用熱鍵
end;
DELPHI中使用熱鍵
end;
DELPHI中使用熱鍵

DELPHI中使用熱鍵
procedure TForm1.FormCreate(Sender: TObject);
DELPHI中使用熱鍵
begin
DELPHI中使用熱鍵
//通過原子表獲得一個關于hotkey的唯一標識,注意本文前邊提到的範圍
DELPHI中使用熱鍵
hotkeyid:=GlobalAddAtom(pchar('UserDefineHotKey'))-$C000;
DELPHI中使用熱鍵
//注冊ctrl+alt+a
DELPHI中使用熱鍵
registerhotkey(handle,hotkeyid,MOD_CONTROL or mod_Alt,$41);
DELPHI中使用熱鍵

DELPHI中使用熱鍵
end;
DELPHI中使用熱鍵

DELPHI中使用熱鍵
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
DELPHI中使用熱鍵
begin
DELPHI中使用熱鍵
unregisterhotkey(handle,hotkeyid);//
DELPHI中使用熱鍵
DeleteAtom(HotKeyID);
DELPHI中使用熱鍵
end;
DELPHI中使用熱鍵

DELPHI中使用熱鍵
end.
DELPHI中使用熱鍵

 
特别声明:以上内容(如有图片或视频亦包括在内)为网络用户发布,本站仅提供信息存储服务。
 
在windows中規定應用程序熱鍵的唯一標識符取值範圍在0x0000~0xBFFF之間,動態鏈接庫的取值範圍在0xC000~0XFFFF之間。 熱鍵的輔助按鍵還包括Mod_Ctrl,Mod_Alt和Mod_Shift,對于windows兼容鍵盤,還包括windows標志鍵,Mod_Win。 熱鍵設置成功後,在程序運行過程中如果有預定義的熱鍵被按下,windows系統都會給應用程序發送一個wm_hotkey消息。 下面用一個例子演示它的使用 編譯程序、運行,如果此程序不是當前桌面顯示在最前邊的窗體,按下ctrl+alt+a後,程序界面將出現在桌面的最上。 示例程序開發平台:D7+WINXP 轉載請注明出處。 [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]unit Unit1; [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]interface [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]uses [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]type [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TForm1 = class(TForm) [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure FormCreate(Sender: TObject); [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure FormClose(Sender: TObject; var Action: TCloseAction); [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] private [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url] ...{ Private declarations } [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] public [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url] ...{ Public declarations } [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] hotkeyid :integer; //記錄熱鍵標識 [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //處理wm_hotkey消息 [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure WMhotkeyhandle(var msg:Tmessage); [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] message wm_hotkey; [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Form1: TForm1; [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]implementation [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$R *.DFM} [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.Wmhotkeyhandle [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url](var msg:Tmessage); [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //判斷是否是ctrl+alt+a [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] if (msg.LParamHi=$41) and [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] (msg.lparamLo=MOD_CONTROL or mod_Alt) then [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] begin [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] msg.Result:=1;//正常返回 [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] application.BringToFront;//將窗體顯示在最前邊 [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.FormCreate(Sender: TObject); [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //通過原子表獲得一個關于hotkey的唯一標識,注意本文前邊提到的範圍 [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] hotkeyid:=GlobalAddAtom(pchar('UserDefineHotKey'))-$C000; [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //注冊ctrl+alt+a [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] registerhotkey(handle,hotkeyid,MOD_CONTROL or mod_Alt,$41); [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] unregisterhotkey(handle,hotkeyid);// [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] DeleteAtom(HotKeyID); [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end. [url=/bbs/detail_501490.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 
 熱帖排行
 
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有