delphi代码:
program open;
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;{$R *.res}
const
WM_HOTKEY = $0312;var
WinH : Longint=0;
Msg : tMsg;begin
RegisterHotKey(0,0,MOD_ALT,ord('X')); //注册Alt+Z
while GetMessage(Msg, 0, 0, 0) do
if Msg.message=WM_HOTKEY then
begin
sleep(500);
SendMessage(Application.Handle,WM_SYSCOMMAND,SC_MONITORPOWER,2);
end;end.
汇编代码:
.386
.Model Flat, StdCall
Option Casemap :NoneInclude windows.inc
Include user32.inc
Include kernel32.inc
Include gdi32.incincludelib gdi32.lib
IncludeLib user32.lib
IncludeLib kernel32.lib
;include macro.asmWinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORDicMyHotKey equ 2010
.const
szFmt_d db '%d', 0.DATA
szClassName db "close windows",0
szCaption db "http://www.kumouse.com",0
szt db "热键:ALT+X 功能:关闭显示器 作者:美丽人生",0
szc db "说明",0.DATA?
hInstance dd ?
hFind HINSTANCE ?.CODE
START:invoke GetModuleHandle,NULL
mov hInstance,eax
invoke WinMain,hInstance,NULL,NULL,SW_SHOWDEFAULT
invoke ExitProcess,0WinMain proc hInst:DWORD,hPrevInst:DWORD,CmdLine:DWORD,CmdShow:DWORD
LOCAL wc :WNDCLASSEX
LOCAL msg :MSG
local hWnd :HWNDmov wc.cbSize,sizeof WNDCLASSEX
mov wc.style,CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
mov wc.lpfnWndProc,offset WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground,COLOR_BTNFACE+1
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,offset szClassName
;invoke LoadIcon,hInst,100
mov wc.hIcon,NULL
;invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,NULL
mov wc.hIconSm,0
invoke RegisterClassEx, ADDR wc
;invoke CreateWindowEx,NULL,ADDR szClassName,CTXT("http://www.kumouse.com"),WS_OVERLAPPEDWINDOW,200,200,400,200,NULL,NULL,hInst,NULL
invoke CreateWindowEx,NULL,ADDR szClassName,addr szCaption,WS_OVERLAPPEDWINDOW,200,200,400,200,NULL,NULL,hInst,NULL
mov hWnd,eax
;invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWndStartLoop:
invoke GetMessage,ADDR msg,NULL,0,0
cmp eax, 0
je ExitLoop
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp StartLoop
ExitLoop:mov eax,msg.wParam
ret
WinMain endpWndProc proc hWin:DWORD,uMsg:DWORD,wParam :DWORD,lParam :DWORD
local cBuf[32]:BYTE.if uMsg==WM_CREATE
invoke RegisterHotKey,hWin,icMyHotKey,MOD_ALT,VK_X ;定义热键
invoke MessageBox,NULL,addr szt,addr szc,1.elseif uMsg == WM_HOTKEY ;处理热键消息
invoke Sleep,500
invoke SendMessage,hWin,WM_SYSCOMMAND,SC_MONITORPOWER,2.elseif uMsg == WM_DESTROY
invoke UnregisterHotKey,hWin,icMyHotKey ;取消定义的热键
invoke PostQuitMessage,NULL
.else
invoke DefWindowProc,hWin,uMsg,wParam,lParam
.endif
ret
WndProc endp
END START
代码下载:
点击下载