本帖最後由 rictirse 於 2012-11-5 23:48 編輯
在notepad上 掛上close BTN[code=autoit]#include <WindowsConstants.au3>
Global $aExtrnlBtn_Ctrls[1][5], $aExtrnlBtn_OldParentPos = -1, $sExtrnlBtn_MainTitle
Global $iWinMine_PID = ProcessExists("notepad.exe")
Opt("GUIOnEventMode", 1)
If Not $iWinMine_PID Then
$iWinMine_PID = Run("notepad.exe") ;run it
EndIf
$hWinMine_Wnd = _ProcessWaitWindow($iWinMine_PID, 1, 5)
$nSolve_Bttn = _ExternalButton_Create("Close", "Close Tasker", "_Exit", 100, 20, 290, 22, $hWinMine_Wnd)
While ProcessExists($iWinMine_PID)
Sleep(10)
_ExternalButton_Follow()
WEnd
Func _ProcessWaitWindow($iPID, $iVisibleOnly = 0, $iWait = 0)
Local $hRet = -1, $iErr = 0, $iTimer = TimerInit(), $iOpt_WWD = Opt("WinWaitDelay", 1), $aWinList
If IsString($iPID) Then
$iPID = ProcessExists($iPID)
EndIf
If $iWait > 0 Then
$iWait *= 1000
EndIf
While 1
$aWinList = WinList()
For $i = 1 To UBound($aWinList)-1
If (($iVisibleOnly And BitAND(WinGetState($aWinList[$i][1]), 2)) Or Not $iVisibleOnly) And WinGetProcess($aWinList[$i][1]) = $iPID Then
$hRet = $aWinList[$i][1] ;WinHandle
ExitLoop 2
EndIf
Next
If $iWait > 0 And TimerDiff($iTimer) >= $iWait Then
$iErr = 1
ExitLoop
EndIf
Sleep(10)
WEnd
Opt("WinWaitDelay", $iOpt_WWD)
Return SetError($iErr, 0, $hRet)
EndFunc
Func _ExternalButton_Create($sBttnTxt, $sBttnTip, $sBttnFnc, $iBttnWidth, $iBttnHeight, $iFloatLeft, $iFloatTop, $hParent)
Local $hButton_GUI, $nButton
$hButton_GUI = GUICreate("", $iBttnWidth, $iBttnHeight, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
$nButton = GUICtrlCreateButton($sBttnTxt, 0, 0, $iBttnWidth, $iBttnHeight)
GUICtrlSetTip($nButton, $sBttnTip)
GUICtrlSetOnEvent(-1, $sBttnFnc)
GUISetState(@SW_SHOW, $hButton_GUI)
$aExtrnlBtn_Ctrls[0][0] += 1
ReDim $aExtrnlBtn_Ctrls[$aExtrnlBtn_Ctrls[0][0]+1][5]
$aExtrnlBtn_Ctrls[$aExtrnlBtn_Ctrls[0][0]][0] = $hParent
$aExtrnlBtn_Ctrls[$aExtrnlBtn_Ctrls[0][0]][1] = $hButton_GUI
$aExtrnlBtn_Ctrls[$aExtrnlBtn_Ctrls[0][0]][2] = $nButton
$aExtrnlBtn_Ctrls[$aExtrnlBtn_Ctrls[0][0]][3] = $iFloatLeft
$aExtrnlBtn_Ctrls[$aExtrnlBtn_Ctrls[0][0]][4] = $iFloatTop
Return $nButton
EndFunc
Func _ExternalButton_Follow()
Local $hParent, $hButton_GUI, $nButton, $iFloatLeft, $iFloatTop, $aParentPos, $aParentClientSize, $iBorder_Size, $iX, $iY
For $i = 1 To $aExtrnlBtn_Ctrls[0][0]
$hParent = $aExtrnlBtn_Ctrls[$i][0]
$hButton_GUI = $aExtrnlBtn_Ctrls[$i][1]
$nButton = $aExtrnlBtn_Ctrls[$i][2]
$iFloatLeft = $aExtrnlBtn_Ctrls[$i][3]
$iFloatTop = $aExtrnlBtn_Ctrls[$i][4]
If $hParent <> -1 And Not WinExists($hParent) Then
GUISetState(@SW_HIDE, $hButton_GUI)
$hParent = -1
ElseIf $hParent = -1 And WinExists($sExtrnlBtn_MainTitle) Then
GUISetState(@SW_SHOW, $hButton_GUI)
$hParent = WinGetHandle($sExtrnlBtn_MainTitle)
ElseIf $hParent = -1 Then
ContinueLoop
EndIf
$aParentPos = WinGetPos($hParent)
If @error Or Not IsArray($aParentPos) Then
ContinueLoop
EndIf
$aParentClientSize = WinGetClientSize($hParent)
If Not WinActive($hParent) And Not WinActive($hButton_GUI) Then
$aParentPos[0] = -3200
$aParentPos[1] = -3200
EndIf
If $i > 1 Or ($aExtrnlBtn_OldParentPos = -1 Or $aExtrnlBtn_OldParentPos[0] <> $aParentPos[0] Or $aExtrnlBtn_OldParentPos[1] <> $aParentPos[1] Or $aExtrnlBtn_OldParentPos[2] <> $aParentPos[2]) Then
$aExtrnlBtn_OldParentPos = $aParentPos
$iBorder_Size = ($aParentPos[2] - $aParentClientSize[0]) / 2
$iX = $aParentPos[0] + $iFloatLeft
$iY = $aParentPos[1] + $iBorder_Size + $iFloatTop
WinMove($hButton_GUI, "", $iX, $iY)
EndIf
Next
EndFunc
Func _Exit()
ProcessClose ("notepad.exe")
EndFunc[/code] |