以記事本為例,每5s鐘保存一次正在編輯的文檔
;很簡單也很有用
;記事本自動保存程序,使用 fasm 編譯通過
format pe console
entry start
include "Win32AXP.inc"
start:
invoke SetTimer,NULL,0,5000,TimerProc;每隔5000ms調用一次 TimeProc 函數
mov [TimerID],eax
@@:
invoke GetMessage,lpMsg,NULL,0,0;
test eax,eax
je @f
invoke TranslateMessage,lpMsg
invoke DispatchMessage,lpMsg
jmp @b
@@:
invoke KillTimer,NULL,[TimerID]
ret
TimerProc:
invoke FindWindow,'notepad',NULL ;找到記事本窗口的HANDLE
test eax,eax
je @f
invoke SendMessage,eax,WM_COMMAND,3,0;發送 WM_COMMAND 保存文件消息
@@:
ret
data import
library user32,"user32.dll"
import user32,\
SetTimer,'SetTimer',\
KillTimer,'KillTimer',\
StdIn,'StdIn',\
FindWindow,'FindWindowA',\
wsprintf,'wsprintfA',\
StdOut,'StdOut',\
GetMessage,'GetMessageA',\
DispatchMessage,'DispatchMessageA',\
TranslateMessage,'TranslateMessage',\
SendMessage,'SendMessageA'
end data
lpMsg MSG
TimerID rd 1
buffer rb 40h