找回密码
 加入
搜索
查看: 3533|回复: 5

[GUI管理] 请教如何在点击Button的同时关闭主窗口

  [复制链接]
发表于 2011-3-10 14:26:15 | 显示全部楼层 |阅读模式
请教如何在点击Button的同时关闭主窗口:

下面的代码中,点击按钮1或者其他两个按钮,关闭主窗口form1,然后出现MsgBox的提示消息?
搞了半天没整明白,希望各位大大帮助下俺这个新人
#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#Include <GuiImageList.au3>
#Include <GuiButton.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("form1", 688, 201, -1, -1,Bitor($WS_CAPTION,$WS_SYSMENU))
$Pic1 = GUICtrlCreatePic(@ScriptDir & "\banner.jpg", 0, 0, 687, 93)
$Button1 = GUICtrlCreateButton("按钮1", 400, 109, 75, 75 )
_GUICtrlButton_SetImageList($Button1, _GetImageListHandle("shell32.dll",-20, True),2,-1,12)
$Button2 = GUICtrlCreateButton("按钮2", 500, 109, 75, 75 )
_GUICtrlButton_SetImageList($Button2, _GetImageListHandle("shell32.dll",-279, True),2,-1,12)
$Button3 = GUICtrlCreateButton("按钮3", 600, 109, 75, 75 )
_GUICtrlButton_SetImageList($Button3, _GetImageListHandle("shell32.dll",-258, True),2,-1,12)
$Label1 = GUICtrlCreateLabel("      ★ 说明事项:" & @LF & "" & @LF & "      ★ 待添加" & @LF & "" & @LF & "      ★ 待添加", 0, 112, 350, 65)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        MsgBox(0, 0, "我是按扭")
                Case $Button2
                        MsgBox(0, 0, "我是按扭")
                Case $Button3
                        MsgBox(0, 0, "我是按扭")
        EndSwitch
WEnd


Func _GetImageListHandle($sFile, $nIconID = 0, $fLarge = False)
        Local $iSize = 16
        If $fLarge Then $iSize = 32
        
        Local $hImage = _GUIImageList_Create($iSize, $iSize, 5, 3)
        If StringUpper(StringMid($sFile, StringLen($sFile) - 2)) = "BMP" Then
                _GUIImageList_AddBitmap($hImage, $sFile)
        Else
                _GUIImageList_AddIcon($hImage, $sFile, $nIconID, $fLarge)
        EndIf
        Return $hImage
EndFunc   ;==>_GetImageListHandle
发表于 2011-3-10 15:21:32 | 显示全部楼层
#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#Include <GuiImageList.au3>
#Include <GuiButton.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("form1", 688, 201, -1, -1,Bitor($WS_CAPTION,$WS_SYSMENU))
$Pic1 = GUICtrlCreatePic(@ScriptDir & "\banner.jpg", 0, 0, 687, 93)
$Button1 = GUICtrlCreateButton("按钮1", 400, 109, 75, 75 )
_GUICtrlButton_SetImageList($Button1, _GetImageListHandle("shell32.dll",-20, True),2,-1,12)
$Button2 = GUICtrlCreateButton("按钮2", 500, 109, 75, 75 )
_GUICtrlButton_SetImageList($Button2, _GetImageListHandle("shell32.dll",-279, True),2,-1,12)
$Button3 = GUICtrlCreateButton("按钮3", 600, 109, 75, 75 )
_GUICtrlButton_SetImageList($Button3, _GetImageListHandle("shell32.dll",-258, True),2,-1,12)
$Label1 = GUICtrlCreateLabel("      ★ 说明事项:" & @LF & "" & @LF & "      ★ 待添加" & @LF & "" & @LF & "      ★ 待添加", 0, 112, 350, 65)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                                        Case $Button1
                                                GUIDelete($Form1)
                        MsgBox(0, 0, "没了主窗体,只能在进程管理器中结束了")
                Case $Button2
                        MsgBox(0, 0, "我是按扭")
                Case $Button3
                        MsgBox(0, 0, "我是按扭")
        EndSwitch
WEnd


Func _GetImageListHandle($sFile, $nIconID = 0, $fLarge = False)
        Local $iSize = 16
        If $fLarge Then $iSize = 32
        
        Local $hImage = _GUIImageList_Create($iSize, $iSize, 5, 3)
        If StringUpper(StringMid($sFile, StringLen($sFile) - 2)) = "BMP" Then
                _GUIImageList_AddBitmap($hImage, $sFile)
        Else
                _GUIImageList_AddIcon($hImage, $sFile, $nIconID, $fLarge)
        EndIf
        Return $hImage
EndFunc   ;==>_GetImageListHandle
 楼主| 发表于 2011-3-10 15:51:05 | 显示全部楼层
首先感谢,但是实际还没有达到我想要的
GUISetState(@SW_HIDE, $Form1)或者GUIDelete($Form1)都不能结束主窗体的进程,都只能在任务管理器中结束...这点比较郁闷,不知道有更好的办法没有
发表于 2011-3-10 16:12:00 | 显示全部楼层
本帖最后由 xyold1 于 2011-3-10 16:13 编辑

主窗体的进程是脚本的进程,若将其结束,相当于点了关闭按钮,那么整个脚本也就over了
要是想这样,那么GUIDelete($Form1)后,再msgbox再exit
 楼主| 发表于 2011-3-10 16:28:10 | 显示全部楼层
是的,所以一直找帮助也没找到办法,目前我就是用的GUIDelete($Form1)和exit

再次感谢,希望能有更好的解决办法
发表于 2011-3-17 12:59:15 | 显示全部楼层
good example....
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-21 10:58 , Processed in 0.078007 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表