本帖最后由 chzj589 于 2017-7-7 10:23 编辑
回复 13# 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
Global $BUTTON5, $BUTTON6, $BUTTON7, $BUTTON8, $ilParam, $hWnd, $Activemode, $label5
Global $GUI3, $CBUTTON1, $CBUTTON2, $CBUTTON3, $CBUTTON4, $CBUTTON5, $CBUTTON6, $CBUTTON7, $CBUTTON8
Form1()
#include <GUI2.au3>
#include <GUI3.au3>
While 1
Sleep(1000)
WEnd
Func _Form1Close()
GUIDelete()
Exit
EndFunc ;==>_Form1Close
Func Form1()
Global $GUI1 = GUICreate('A窗口激活')
GUISetOnEvent($GUI_EVENT_CLOSE, "_Form1Close")
$label5 = GUICtrlCreateLabel("", 13, 60, 355, 60)
GUICtrlSetFont(-1, 14, 800, 0, "微软雅黑")
GUICtrlSetColor($label5, 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")
$BUTTON5 = GUICtrlCreateButton("A5", 10, 230, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg")
$BUTTON6 = GUICtrlCreateButton("A6", 100, 230, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg")
$BUTTON7 = GUICtrlCreateButton("A7", 190, 230, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg")
$BUTTON8 = GUICtrlCreateButton("A8", 280, 230, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg")
GUISetState(@SW_SHOW, $GUI1)
;------------------------------------------A窗口--------------------------------------------------------
;------------------------------------------以下B窗口----------------------------------------------------
_GUI2()
;------------------------------------------以下C窗口----------------------------------------------------
_GUI3()
GUIRegisterMsg($WM_ACTIVATE, "WM_ACTIVATE")
EndFunc ;==>Form1
Func _MSG();A窗口
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 = $BUTTON5
MsgBox(0, "", "点击 A5")
Case @GUI_CtrlId = $BUTTON6
MsgBox(0, "", "点击 A6")
Case @GUI_CtrlId = $BUTTON7
MsgBox(0, "", "点击 A7")
Case @GUI_CtrlId = $BUTTON8
MsgBox(0, "", "点击 A8")
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)
GUICtrlSetData($label5, $Acti)
GUICtrlSetColor($label5, 0xFF0000)
Case 2
$Activemode = "鼠标点击激活"
$Acti = "信息" & @CRLF & "当前激活窗口为 :" & WinGetTitle($hWnd) & @CRLF & "激活方式为 :" & $Activemode
GUICtrlSetData($label, $Acti)
GUICtrlSetColor($label, 0xFF00FF)
Case 3
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
文件名:GUI2.au3
Func _GUI2();B窗口
Global $GUI2 = GUICreate('B窗口激活')
GUISetOnEvent($GUI_EVENT_CLOSE, "_Form1Close")
$label = 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, "_msg2")
$BBUTTON2 = GUICtrlCreateButton("B2", 100, 200, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg2")
$BBUTTON3 = GUICtrlCreateButton("B3", 190, 200, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg2")
$BBUTTON4 = GUICtrlCreateButton("B4", 280, 200, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg2")
GUISetState(@SW_SHOW, $GUI2)
;------------------------------------------B窗口----------------------------------------------------
EndFunc ;==>_GUI2
Func _MSG1();B窗口
Select
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 ;==>_MSG1
文件名:GUI3.au3
Func _GUI3();C窗口
Global $GUI3 = GUICreate('C窗口激活')
GUISetOnEvent($GUI_EVENT_CLOSE, "_Form1Close")
$label6 = GUICtrlCreateLabel("", 13, 60, 355, 60)
GUICtrlSetFont(-1, 14, 800, 0, "微软雅黑")
GUICtrlSetColor($label, 0x000000)
$CBUTTON1 = GUICtrlCreateButton("C1", 10, 200, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg3")
$CBUTTON2 = GUICtrlCreateButton("C2", 100, 200, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg3")
$CBUTTON3 = GUICtrlCreateButton("C3", 190, 200, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg3")
$CBUTTON4 = GUICtrlCreateButton("C4", 280, 200, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg3")
$CBUTTON5 = GUICtrlCreateButton("C5", 10, 230, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg3")
$CBUTTON6 = GUICtrlCreateButton("C6", 100, 230, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg3")
$CBUTTON7 = GUICtrlCreateButton("C7", 190, 230, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg3")
$CBUTTON8 = GUICtrlCreateButton("C8", 280, 230, 80, 25, 0)
GUICtrlSetCursor(-1, "SIZEALL");鼠标指针
GUICtrlSetFont(-1, 9, 400, 0, "微软雅黑")
GUICtrlSetOnEvent(-0x00000001, "_msg3")
GUISetState(@SW_SHOW, $GUI3)
;------------------------------------------C窗口----------------------------------------------------
EndFunc ;==>_GUI3
Func _MSG3();C窗口
Select
Case @GUI_CtrlId = $CBUTTON1
MsgBox(0, "", "点击 C1")
Case @GUI_CtrlId = $CBUTTON2
MsgBox(0, "", "点击 C2")
Case @GUI_CtrlId = $CBUTTON3
MsgBox(0, "", "点击 C3")
Case @GUI_CtrlId = $CBUTTON4
MsgBox(0, "", "点击 C4")
Case @GUI_CtrlId = $CBUTTON5
MsgBox(0, "", "点击 C5")
Case @GUI_CtrlId = $CBUTTON6
MsgBox(0, "", "点击 C6")
Case @GUI_CtrlId = $CBUTTON7
MsgBox(0, "", "点击 C7")
Case @GUI_CtrlId = $CBUTTON8
MsgBox(0, "", "点击 C8")
EndSelect
EndFunc ;==>_MSG3
这样你想复制_GUI2()的代码,就直椄把 #include <GUI2.au3>整个拉走 |