本帖最后由 xiehuahere 于 2012-9-4 11:38 编辑
回复 1# kk_lee69
wordpad工具栏上加个按钮,_GUICtrlButton_Create就可以。
#Include <GuiButton.au3>
#Include <Misc.au3>
_Singleton("test")
Opt("MouseCoordMode", 2)
Local $win = "[CLASS:WordPadClass]"
Local $toolbar = "[CLASSNN:ToolbarWindow322]"
Local $pos, $margin = 2 ;按钮与工具栏的上下边距
Local $btnLeft, $btnTop, $btnWidth = 60, $btnHeight
Run(@ProgramFilesDir & '\Windows NT\Accessories\wordpad.exe')
If Not WinWait($win, "", 2) Then
MsgBox(48+262144, "Warning", "等待wordpad出现已超时!")
Exit
EndIf
If Not WinActivate($win) Then WinActivate($win)
$pos = ControlGetPos($win, "", $toolbar)
$btnLeft = $pos[0] + $pos[2] + 10
$btnTop = $pos[1] + $margin
$btnHeight = $pos[3] - $margin * 2
ConsoleWrite($btnLeft & ", " & $btnTop & ", " & $btnWidth & ", " & $btnHeight & @CRLF)
_GUICtrlButton_Create(WinGetHandle($win), "Test", $btnLeft, $btnTop, $btnWidth, $btnHeight)
HotKeySet("{ESC}", "_OnExit")
; Open DLL for _IsPressed
Local $dll = DllOpen("user32.dll")
While 1
If Not WinExists($win) Then _OnExit()
If WinActive($win) And _IsPressed("01", $dll) Then
$pos = MouseGetPos()
ConsoleWrite($pos[0] & ", " & $pos[1] & @CRLF)
If $pos[0] > $btnLeft And $pos[0] < $btnLeft + $btnWidth And $pos[1] > $btnTop And $pos[1] < $btnTop + $btnHeight Then
MsgBox(64+262144, "Result", "I'm clicked!", 0, WinGetHandle($win))
EndIf
; Wait until mouse released
While _IsPressed("01", $dll)
Sleep(10)
WEnd
EndIf
Sleep(10)
WEnd
Func _OnExit()
DllClose($dll)
Exit
EndFunc
此外还有一些工作要做:wordpad窗口最小化并还原后需要重建按钮;你还可以给按钮加上鼠标悬停效果,等。 |