C 註冊全域性熱鍵的方法

2021-05-27 22:23:49 字數 1915 閱讀 5509

在form裡加入以下**即可

protected override void wndproc(ref   message m)

base.wndproc(ref   m);

}public void sethotkey(keys c, bool bctrl, bool bshift, bool balt, bool bwindows)

else if (bshift)

else if (balt)

else if (bwindows)

nativewin32.registerhotkey(handle, 100, modifiers, c);

}public class nativewin32

[dllimport("user32.dll", charset = charset.auto)]

static public extern intptr getforegroundwindow();

[structlayout(layoutkind.sequential, charset = charset.auto)]

public struct stringbuffer

[dllimport("user32.dll", charset = charset.auto)]

public static extern int getwindowtext(intptr hwnd, out   stringbuffer classname, int nmaxcount);

[dllimport("user32.dll", charset = charset.auto)]

public static extern int sendmessage(intptr hwnd, int msg, int wparam, int lparam);

[dllimport("user32.dll", charset = charset.auto)]

public static extern intptr sendmessage(intptr hwnd, int msg, int wparam, intptr lparam);

public const int wm_syscommand = 0x0112;

public const int sc_close = 0xf060;

public delegate bool enumthreadproc(intptr hwnd, intptr lparam);

[dllimport("user32.dll", charset = charset.auto)]

public static extern bool enumthreadwindows(int threadid, enumthreadproc pfnenum, intptr lparam);

[dllimport("user32.dll", charset = charset.auto)]

public static extern intptr findwindowex(intptr parent, intptr next, string sclassname, intptr swindowtitle);

[dllimport("user32.dll", setlasterror = true)]

public static extern bool registerhotkey(intptr hwnd,

int id,

keymodifiers fsmodifiers,

keys vk

);[dllimport("user32.dll", setlasterror = true)]

public static extern bool unregisterhotkey(intptr hwnd,

int id

);[flags()]

public enum keymodifiers

}

Delphi全域性熱鍵的註冊

1.在窗啟動時建立atom aatom atom 定義在private中 1 if findatom zwxhotkey 0 then 2begin 3 aatom globaladdatom zwxhotkey 4end 5 if registerhotkey handle,aatom,mod a...

Delphi 全域性熱鍵註冊 使用

rad studio 10.2.3 測試 全域性變數 var mhotkey01,mhotkey02 integer 1 在程式建立的時候或者窗體顯示的時候註冊熱鍵 begin 原子 mhotkey01 mhotkey01 globaladdatom xiaoyin hotkey ctrl f1 c...

C 註冊系統熱鍵

簡單點說就是為程式制定快捷鍵勒。很多軟體都帶熱鍵功能的,通過以下方式可以實現2個鍵或3個鍵的快捷鍵,相當之實用,具體實現方法看後文吧。先引用using system.runtime.interopservices 的命名空間,然後在合適的位置加上如下 就ok。注意 form1 load和form1 ...