找回密码
 加入
搜索
查看: 3573|回复: 2

[GUI管理] 窗口无法关闭和热键设置问题(已解决)

[复制链接]
发表于 2010-11-2 21:15:03 | 显示全部楼层 |阅读模式
本帖最后由 levinfish 于 2010-11-2 22:55 编辑

问题1
我做了一个小的程序,发现用热键呼出后,其他功能正常,但是点击关闭对话框后,生成的对话框无法关闭,并且再点击其他键就失效了。请大家看一下什么问题,多谢了。

刚才问了一个人,他让我在程序里面加了一个GUIdelete(),就能够关闭窗口了。如果不加这一句,则直接跳出循环,因此窗口关闭不了。

这时一个简化的代码
#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

HotKeySet('#a','Example')
While 1
   Sleep(100)
WEnd

Func Example()
    Local $Button_1, $Button_2, $msg
    GUICreate("My GUI Button")

    Opt("GUICoordMode", 2)
    $Button_1 = GUICtrlCreateButton("Button 1", 10, 30, 100)
    $Button_2 = GUICtrlCreateButton("Button 2", 0, -1)

    GUISetState()     

     While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
               GUIdelete();------------------------添加这一句后就能关闭了
                ExitLoop
            Case $msg = $Button_1
                MsgBox(0, 'Testing', 'Button 1 was pressed')   
            Case $msg = $Button_2
                MsgBox(0, 'Testing', 'Button 2 was pressed')  
        EndSelect
    WEnd
EndFunc   

问题2

有关热键的设置问题,我现在只能用下面这一种方法设置热键,能不能给出一些其他的热键设置方式
HotKeySet('#a','func')
While 1
   Sleep(100)
WEnd

评分

参与人数 1金钱 +10 收起 理由
hzxymkb + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-11-2 21:42:09 | 显示全部楼层
也不知道对不对!试试吧!

#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
Global $gui

HotKeySet('a', '_Show')

Example()

Func Example()
        Local $Button_1, $Button_2, $msg
        $gui = GUICreate("My GUI Button")

        Opt("GUICoordMode", 2)
        $Button_1 = GUICtrlCreateButton("Button 1", 10, 30, 100)
        $Button_2 = GUICtrlCreateButton("Button 2", 0, -1)

        While 1
                $msg = GUIGetMsg()
                Select
                        Case $msg = $GUI_EVENT_CLOSE
                                ExitLoop
                        Case $msg = $Button_1
                                MsgBox(0, 'Testing', 'Button 1 was pressed')
                        Case $msg = $Button_2
                                MsgBox(0, 'Testing', 'Button 2 was pressed')
                EndSelect
        WEnd
EndFunc   ;==>Example

Func _Show()
        GUISetState(@SW_SHOW, $gui)
EndFunc   ;==>_Show
发表于 2010-11-2 22:43:27 | 显示全部楼层
第一个问题涉及子父窗口操作问题,一般来讲,如果想打开子窗口父窗口操作不了的话,可以锁定父窗口。即:GUISetState(@SW_DISABLE, $Form1),个人意见
以下是给你参考的,祝你进步。
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 447, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 24, 16, 65, 25)
$Button2 = GUICtrlCreateButton("Button1", 100, 15, 65, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        GUISetState(@SW_DISABLE, $Form1)
                        $son1 = GUICreate('son1', 300, 200)
                        $quit = GUICtrlCreateButton("quit", 156, 112, 75, 25, 0)
                        GUISetState()
                        While 1
                                Switch GUIGetMsg()
                                        Case $GUI_EVENT_CLOSE
                                                GUISetState(@SW_ENABLE, $Form1)
                                                GUIDelete($son1)
                                                ExitLoop
                                        Case $quit
                                                GUISetState(@SW_ENABLE, $Form1)
                                                GUIDelete($son1)
                                                ExitLoop
                                EndSwitch
                        WEnd
                Case $Button2
                        MsgBox(0,"","you can do it!","",$Form1)
        EndSwitch
WEnd
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-21 03:35 , Processed in 0.080906 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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