回复 3# kk_lee69
下面的例子你看看
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
Opt("GUIOnEventMode", 1)
Global $GUI1, $GUI2, $label6, $label, $BUTTON1, $BUTTON2, $BUTTON3, $BUTTON4, $BBUTTON1, $BBUTTON2, $BBUTTON3, $BBUTTON4
Form1()
While 1
Sleep(1000)
WEnd
Func _Form1Close()
GUIDelete()
Exit
EndFunc ;==>_Form1Close
Func Form1()
Global $GUI1 = GUICreate('A窗口激活')
GUISetOnEvent($GUI_EVENT_CLOSE, "_Form1Close")
$label = GUICtrlCreateLabel("", 13, 60, 355, 60)
GUICtrlSetFont(-1, 14, 800, 0, "微软雅黑")
GUICtrlSetColor($label, 0x000000)
$Button1 = GUICtrlCreateButton("A1", 10, 200, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg")
$Button2 = GUICtrlCreateButton("A2", 100, 200, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg")
$Button3 = GUICtrlCreateButton("A3", 190, 200, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg")
$Button4= GUICtrlCreateButton("A4", 280, 200, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg")
Global $GUI2 = GUICreate('B窗口激活')
GUISetOnEvent($GUI_EVENT_CLOSE, "_Form1Close")
$label6 = GUICtrlCreateLabel("", 13, 60, 355, 60)
GUICtrlSetFont(-1, 14, 800, 0, "微软雅黑")
GUICtrlSetColor($label6, 0x000000)
$BButton1 = GUICtrlCreateButton("B1", 10, 200, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg")
$BButton2 = GUICtrlCreateButton("B2", 100, 200, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg")
$BButton3 = GUICtrlCreateButton("B3", 190, 200, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg")
$BButton4= GUICtrlCreateButton("B4", 280, 200, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg")
GUISetState(@SW_SHOW, $GUI1)
GUISetState(@SW_SHOW, $GUI2)
GUIRegisterMsg($WM_ACTIVATE, "WM_ACTIVATE")
EndFunc ;==>Form1
Func _MSG()
Select
Case @GUI_CtrlId = $BUTTON1
MsgBox(0, "", "点击 A1" )
Case @GUI_CtrlId = $BUTTON2
MsgBox(0, "", "点击 A2" )
Case @GUI_CtrlId = $BUTTON3
MsgBox(0, "", "点击 A3" )
Case @GUI_CtrlId = $BUTTON4
MsgBox(0, "", "点击 A4" )
Case @GUI_CtrlId = $BBUTTON1
MsgBox(0, "", "点击 B1" )
Case @GUI_CtrlId = $BBUTTON2
MsgBox(0, "", "点击 B2" )
Case @GUI_CtrlId = $BBUTTON3
MsgBox(0, "", "点击 B3" )
Case @GUI_CtrlId = $BBUTTON4
MsgBox(0, "", "点击 B4" )
EndSelect
EndFunc ;==>_MSG
Func WM_ACTIVATE($hWnd, $iMsg, $iwParam, $ilParam)
Local $Activemode = _WinAPI_LoWord($iwParam)
Switch $Activemode
Case 0
;$Activemode = "disactive"
Return
Case 1
$Activemode = "其他方式激活"
$Acti = "信息" & @CRLF & "当前激活窗口为 :" & WinGetTitle($hWnd) & @CRLF & "激活方式为 :" & $Activemode
GUICtrlSetData($label6, $Acti)
GUICtrlSetColor($label6, 0x009900)
Case 2
$Activemode = "鼠标点击激活"
$Acti = "信息" & @CRLF & "当前激活窗口为 :" & WinGetTitle($hWnd) & @CRLF & "激活方式为 :" & $Activemode
GUICtrlSetData($label, $Acti)
GUICtrlSetColor($label, 0xFF00FF)
EndSwitch
ConsoleWrite("信息" & @CRLF & "当前激活窗口为 :" & WinGetTitle($hWnd) & @CRLF & "激活方式为 :" & $Activemode)
;MsgBox(0, "", "信息" & @CRLF & "当前激活窗口为 :" & WinGetTitle($hWnd) & @CRLF & "激活方式为 :" & $Activemode)
$Acti = "信息" & @CRLF & "当前激活窗口为 :" & WinGetTitle($hWnd) & @CRLF & "激活方式为 :" & $Activemode
GUICtrlSetData($label, $Acti)
GUICtrlSetColor($label, 0x0000FF)
EndFunc ;==>WM_ACTIVATE
|