求教大佬,最近测试一个父子窗口例子。
发现个问题,界面1与界面2同时打开的时候,按钮弹窗正常,但是先打开界面1关闭后,再打开界面2,按钮弹窗就异常了~~,感觉是$WM_COMMAND消息有问题,但是不知道哪错了- -!!!
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Global $Main_Form,$MainButton1,$ck_Form,$Button1,$Button2,$ck_in_Form,$ck_in_ok,$ck_in_esc,$ck_out_Form,$ck_out_ok,$ck_out_esc
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
main()
Do
Sleep(10)
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func main();父界面
$Main_Form = GUICreate("父界面", 556, 310, -1, -1)
$MainButton1 = GUICtrlCreateButton("子界面", 212, 80, 75, 25)
GUISetState(@SW_SHOW,$Main_Form)
EndFunc
Func ck();子界面
$ck_Form = GUICreate("子界面", 456, 210, -1, -1)
$Button1 = GUICtrlCreateButton("界面1", 72, 80, 75, 25)
$Button2 = GUICtrlCreateButton("界面2", 232, 80, 75, 25)
GUISetState(@SW_SHOW,$ck_Form)
EndFunc
Func ck_in();界面1
$ck_in_Form = GUICreate("界面1", 172, 296, -1, -1, $WS_SYSMENU, $WS_EX_APPWINDOW,$ck_Form)
$ck_in_ok = GUICtrlCreateButton("入库",12, 38, 83, 41)
$ck_in_esc = GUICtrlCreateButton("取消", 12,88, 83, 41)
GUISetState(@SW_SHOW,$ck_in_Form)
EndFunc ;==>ck_Inventory_manager_in
Func ck_out();界面2
$ck_out_Form = GUICreate("界面2", 172, 296, -1, -1, $WS_SYSMENU, $WS_EX_APPWINDOW,$ck_Form)
$ck_out_ok = GUICtrlCreateButton("出库", 12, 38, 83, 41)
$ck_out_esc = GUICtrlCreateButton("取消", 12, 88, 83, 41)
GUISetState(@SW_SHOW,$ck_out_Form)
EndFunc ;==>ck_Inventory_manager_in
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) ;感觉是这边有问题,但是不太清楚,求有时间的大佬解析下。
Switch $hWnd
Case $Main_Form,$ck_Form,$ck_in_Form,$ck_out_Form ;主界面
ck_Event_COMMAND($hWnd, BitAND($wParam, 0x0000FFFF), BitShift($wParam, 16), $lParam)
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Func ck_Event_COMMAND($hWnd, $iControl, $iMsg, $ilParam)
Switch $iControl
Case $MainButton1
;GUISetState(@SW_HIDE, $main_Form)
ck()
Case $Button1
ck_in()
Case $Button2
ck_out()
Case $ck_in_ok
MsgBox("", "", "入库")
Case $ck_out_ok
MsgBox("", "", "出库")
Case $ck_in_esc;
MsgBox("", "", "入库退出")
GUIDelete($ck_in_Form)
WinActivate("子界面")
Case $ck_out_esc
MsgBox("", "", "出库退出")
GUIDelete($ck_out_Form)
WinActivate("子界面")
EndSwitch
EndFunc ;==>ck_Inventory_manager_Event_COMMAND
Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
Local $SC_CLOSE = 0xF060
Local $nID = BitAND($wParam, 0x0000FFFF)
Switch $nID
Case $SC_CLOSE
If $hWnd = $Main_Form Then
Exit
Else
GUIDelete($hWnd)
EndIf
EndSwitch
EndFunc ;==>WM_SYSCOMMAND
|