您好,我有一个小代码,我需要帮助来解决它。
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 195, 47, 192, 124, BitOR($WS_SIZEBOX, $WS_SYSMENU))
$Button1 = GUICtrlCreateButton("OK", 16, 8, 75, 25)
$Button2 = GUICtrlCreateButton("CANCEL", 104, 8, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
AutoItSetOption('WinTitleMatchMode', 2)
Local $aPos[4], $aNewPos[4]
$aPos = WinGetPos($Form1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
MsgBox(0, '', 'Button OK is pressed')
Case $Button2
MsgBox(0, '', 'Button CANCEL is presses')
EndSwitch
WEnd
我尝试检查窗口大小和位置编辑。 但我无法循环,因为脚本在 while 中停止了。
谢谢
我尝试过编辑 while、调用位置等
因为我仍然不能 100% 确定你想要实现的目标。 我将发布两个解决方案。
包括:
#包括
#include
#include
#include
$hGUI = GUICreate("Test", 500, 500, 10, 10, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
Global $fResized = False
GUISetState()
GUIRegisterMsg($WM_MOVE, "_WM_MOVE")
GUIRegisterMsg($WM_SIZE, "_WM_SIZE")
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
; If the flag is set
If $fResized Then
MsgBox(0, "Hi", "Now you can run your function")
; Clear the flag again
$fResized = False
EndIf
WEnd
Func _WM_MOVE($hWnd, $iMsg, $wParam, $lParam)
If $hWnd = $hGUI Then
ConsoleWrite("Moving at " & @MSEC & ' to ' & _ArrayToString(WinGetPos($hGUI)) & @CRLF)
EndIf
EndFunc ;==>_WM_MOVE
Func _WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
; Set the flag
$fResized = True
If $hWnd = $hGUI Then
ConsoleWrite("Resized at " & @MSEC & ' to ' & _ArrayToString(WinGetPos($hGUI)) & @CRLF)
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_SIZE
包括:#include
#include
#include
#include
Opt( "MustDeclareVars", 1)
Global $g_hEventProc = DllCallbackRegister("_EventProc", "none", "ptr;dword;hwnd;long;long;dword;dword")
Global $g_hEventHook = _WinAPI_SetWinEventHook($EVENT_MIN, $EVENT_MAX, DllCallbackGetPtr($g_hEventProc))
Global $g_hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
Global $g_hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($g_hStub_KeyProc), _WinAPI_GetModuleHandle(0))
OnAutoItExitRegister(OnAutoItExit)
Local $iPid = Run(@SystemDir & "\notepad.exe")
While ProcessExists($iPid)
Sleep(1000)
WEnd
;======================================
Func _EventProc($g_hEventHook, $iEvent, $hWnd, $iObjectID, $iChildID, $iThreadId, $iEventTime)
Switch $iEvent
Case $EVENT_SYSTEM_MOVESIZESTART
ConsoleWrite("Start : a window is being moved or resized . " & _
"Window title : " & WinGetTitle($hWnd) & @crlf)
Case $EVENT_SYSTEM_MOVESIZEEND
ConsoleWrite("End : the movement or resizing of a window has finished . " & _
"Window title : " & WinGetTitle($hWnd) & @crlf & @crlf)
EndSwitch
EndFunc ;==>_EventProc
;======================================
Func _KeyProc($nCode, $wParam, $lParam)
If $nCode _KeyProc
;======================================
Func OnAutoItExit()
_WinAPI_UnhookWinEvent($g_hEventHook)
DllCallbackFree($g_hEventProc)
_WinAPI_UnhookWindowsHookEx($g_hHook)
DllCallbackFree($g_hStub_KeyProc)
EndFunc ;==>_OnAutoItExit