找回密码
 加入
搜索
查看: 12099|回复: 17

[GUI管理] 【已解决】使用 $WS_TABSTOP后子窗口可以在父窗口里随意拖动,何解?

  [复制链接]
发表于 2014-9-14 18:57:42 | 显示全部楼层 |阅读模式
本帖最后由 chamlien 于 2014-9-15 17:11 编辑

$Form3 = GUICreate("ID Check", 505, 270, 45, 80, $WS_CHILD, $WS_TABSTOP, $Form1)

上段代码使用后,form3可以在FORM里按住鼠标左键随意拖动,但是使用

$Form3 = GUICreate("Login", 505, 270, 45, 80, $WS_CHILD, "", $Form1)

就不会出现以上情况,此时GUI失去了tab键可以随意切换的功能!

问题:如何保留$WS_TABSTOP样式且子窗口不能拖动?
 楼主| 发表于 2014-9-14 20:27:47 | 显示全部楼层
回复 1# chamlien

以下是我的代码:麻烦测试并帮忙解决一下

#include <WindowsConstants.au3>
$Form1 = GUICreate("父窗口", 600, 450, -1, -1, "")
$Group1 = GUICtrlCreateGroup("", 10, 5, 580, 65)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("一系列按钮", 53, 20, 112, 40, $WS_GROUP)
;GUICtrlSetOnEvent(-1, "form2")

$Form2 = GUICreate("Login", 505, 270, 45, 80, $WS_CHILD, $WS_TABSTOP, $Form1)
GUISetBkColor(0xCCCCFF);这个子窗口蓝色区域能拖动(鼠标左键按住,就能拖来拖去,而父窗口没有移动,为什么)
$2input1 = GUICtrlCreateInput("", 140, 40, 320, 25)
$2label_l1 = GUICtrlCreateLabel("能拖动:", 40, 44, 100, 28, $WS_GROUP)

GUISetState(@SW_SHOW, $Form1)
GUISetState(@SW_SHOW, $Form2)
While 1
        Sleep(100)
       
WEnd

怎样解决呢?
发表于 2014-9-14 21:52:19 | 显示全部楼层
用这个吧($DS_MODALFRAME)

你要想一起移动就要监听这个事件:$WM_MOVE


用类似这种方式解决:

Func WM_MOVE($hWnd, $Msg, $wParam, $lParam)
        ;MsgBox(0, "", "test")
        $XY = WinGetPos($Form1)
        $XY2 = WinGetPos($Form2)
        WinMove($Form1, "", $XY2[0], $XY2[1])
        WinSetOnTop('Form1','',1)
EndFunc



原帖: http://www.autoitx.com/forum.php ... hlight=%D2%C6%B6%AF
 楼主| 发表于 2014-9-14 22:15:32 | 显示全部楼层
回复 3# MicroBlue

并不能解决我的问题呢
发表于 2014-9-15 10:06:39 | 显示全部楼层
本帖最后由 seniors 于 2014-9-15 10:10 编辑

$Form2 = GUICreate("Login", 505, 270, 45, 80, BitOR($WS_CHILD, $WS_TABSTOP), -1 , $Form1)
 楼主| 发表于 2014-9-15 10:25:43 | 显示全部楼层
回复 5# seniors

这个解决了一点问题,但这样如果子窗口有多个input控件,tab键只能切换到第一个,也就是好像$WS_TABSTOP失效了一半,求解
发表于 2014-9-15 11:10:03 | 显示全部楼层
本帖最后由 austere 于 2014-9-15 11:11 编辑

5 楼正解也!~
#include <WindowsConstants.au3>
#include <array.au3>
$Form1 = GUICreate("父窗口", 600, 450, -1, -1, "")
$Group1 = GUICtrlCreateGroup("", 10, 5, 580, 65)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("一系列按钮", 53, 20, 112, 40, $WS_GROUP)
;GUICtrlSetOnEvent(-1, "form2")

$Form2 = GUICreate("Login", 505, 270, 45, 80, BitOR($WS_CHILD, $WS_TABSTOP), -1 , $Form1)
GUISetBkColor(0xCCCCFF);这个子窗口蓝色区域能拖动(鼠标左键按住,就能拖来拖去,而父窗口没有移动,为什么)
$2input1 = GUICtrlCreateInput("", 140, 40, 320, 25)
$2label_l1 = GUICtrlCreateLabel("能拖动:", 40, 44, 100, 28, $WS_GROUP)

GUISetState(@SW_SHOW, $Form1)
GUISetState(@SW_SHOW, $Form2)

While 1
        $nMsg = GUIGetMsg(1)
        If $nMsg[1] == $Form2 Then 
         DllCall( "user32.dll", "BOOL", "ReleaseCapture" )
                DllCall( "user32.dll","LRESULT","SendMessage","HWND",$Form1,"UINT",$WM_SYSCOMMAND,"WPARAM",0xF010 + 2,"LPARAM",0)
        EndIf
WEnd
 楼主| 发表于 2014-9-15 11:29:57 | 显示全部楼层
回复 7# austere

还是有问题的
#include <WindowsConstants.au3>
#include <array.au3>
$Form1 = GUICreate("父窗口", 600, 450, -1, -1, "")
$Group1 = GUICtrlCreateGroup("", 10, 5, 580, 65)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("一系列按钮", 53, 20, 112, 40, $WS_GROUP)
;GUICtrlSetOnEvent(-1, "form2")

$Form2 = GUICreate("Login", 505, 270, 45, 80, BitOR($WS_CHILD, $WS_TABSTOP), -1 , $Form1)
GUISetBkColor(0xCCCCFF);这个子窗口蓝色区域能拖动(鼠标左键按住,就能拖来拖去,而父窗口没有移动,为什么)
$2input1 = GUICtrlCreateInput("", 140, 40, 320, 25)
$2label_l1 = GUICtrlCreateLabel("能拖动:", 40, 44, 100, 28, $WS_GROUP)
$2input2 = GUICtrlCreateInput("", 140, 140, 320, 25)
$2label_l1 = GUICtrlCreateLabel("tab键切换不到:", 40, 144, 100, 28, $WS_GROUP)

GUISetState(@SW_SHOW, $Form1)
GUISetState(@SW_SHOW, $Form2)

While 1
        $nMsg = GUIGetMsg(1)
        If $nMsg[1] == $Form2 Then 
         DllCall( "user32.dll", "BOOL", "ReleaseCapture" )
                DllCall( "user32.dll","LRESULT","SendMessage","HWND",$Form1,"UINT",$WM_SYSCOMMAND,"WPARAM",0xF010 + 2,"LPARAM",0)
        EndIf
WEnd
以上第二个input还是tab键切换不到,tab键只能在“一系列按钮”和“能拖动”这两个控件之间切换
发表于 2014-9-15 12:07:26 | 显示全部楼层
本帖最后由 seniors 于 2014-9-15 12:14 编辑

#include <WindowsConstants.au3>
#include <array.au3>
$Form1 = GUICreate("父窗口", 600, 450, -1, -1, "")
$Group1 = GUICtrlCreateGroup("", 10, 5, 580, 65)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("一系列按钮", 53, 20, 112, 40)
$Form2 = GUICreate("Login", 505, 270, 45, 80, BitOR($WS_CHILD, $WS_TABSTOP), $WS_EX_CONTROLPARENT, $Form1)
GUISetBkColor(0xCCCCFF);这个子窗口蓝色区域能拖动(鼠标左键按住,就能拖来拖去,而父窗口没有移动,为什么)
$2input1 = GUICtrlCreateInput("", 140, 40, 320, 25)
$2label_l1 = GUICtrlCreateLabel("能拖动:", 40, 44, 100, 28)
$2input2 = GUICtrlCreateInput("", 140, 140, 320, 25)
$2label_l1 = GUICtrlCreateLabel("tab键切换不到:", 40, 144, 100, 28)

GUISetState(@SW_SHOW, $Form1)
GUISetState(@SW_SHOW, $Form2)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
        EndSwitch
WEnd
 楼主| 发表于 2014-9-15 13:06:01 | 显示全部楼层
回复 9# seniors

这样tab键可以,但是蓝色区域又可以拖动了....
发表于 2014-9-15 15:03:48 | 显示全部楼层
暂时找不到其它方法,就先用NCHITTEST来侦测吧
#include <WindowsConstants.au3>
#include <array.au3>
$Form1 = GUICreate("父窗口", 600, 450, -1, -1, "")
$Group1 = GUICtrlCreateGroup("", 10, 5, 580, 65)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("一系列按钮", 53, 20, 112, 40)

$Form2 = GUICreate("Login", 505, 270, 45, 80, BitOR($WS_CHILD, $WS_TABSTOP), $WS_EX_CONTROLPARENT, $Form1)
GUISetBkColor(0xCCCCFF);这个子窗口蓝色区域能拖动(鼠标左键按住,就能拖来拖去,而父窗口没有移动,为什么)
$2input1 = GUICtrlCreateInput("", 140, 40, 320, 25)
$2label_l1 = GUICtrlCreateLabel("能拖动:", 40, 44, 100, 28)
$2input2 = GUICtrlCreateInput("", 140, 140, 320, 25)
$2label_l1 = GUICtrlCreateLabel("tab键切换不到:", 40, 144, 100, 28)

GUISetState(@SW_SHOW, $Form1)
GUISetState(@SW_SHOW, $Form2)
GUIRegisterMsg($WM_NCHITTEST, 'WM_NCHITTEST')

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
        EndSwitch
WEnd

Func WM_NCHITTEST($hWnd, $Msg, $wParam, $lParam)
        Switch $hWnd
                Case $Form2
                        Return $HTCLIENT
        EndSwitch
EndFunc   ;==>WM_NCHITTEST
发表于 2014-9-15 15:09:07 | 显示全部楼层
回复 11# seniors


    不错!~  赞一个~
 楼主| 发表于 2014-9-15 17:11:18 | 显示全部楼层
回复 11# seniors

非常感谢!!问题已经解决!
 楼主| 发表于 2014-9-15 18:20:56 | 显示全部楼层
回复 11# seniors

新问题来了:

#include <WindowsConstants.au3>
#include <array.au3>
$Form1 = GUICreate("父窗口", 600, 450, -1, -1)
$Group1 = GUICtrlCreateGroup("", 10, 5, 580, 65)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("一系列按钮", 53, 20, 112, 40, $WS_GROUP)

$Form2 = GUICreate("Login", 505, 270, 45, 80, BitOR($WS_CHILD, $WS_TABSTOP), $WS_EX_CONTROLPARENT, $Form1)
GUISetBkColor(0xCCCCFF);这个子窗口蓝色区域能拖动(鼠标左键按住,就能拖来拖去,而父窗口没有移动,为什么)
$2input1 = GUICtrlCreateInput("", 140, 40, 320, 25)
$2label_l1 = GUICtrlCreateLabel("能拖动:", 40, 44, 100, 28)
$2input2 = GUICtrlCreateInput("", 140, 140, 320, 25)
$2label_l1 = GUICtrlCreateLabel("tab键切换不到:", 40, 144, 100, 28)

GUISetState(@SW_SHOW, $Form1)
GUISetState(@SW_SHOW, $Form2)
GUIRegisterMsg($WM_NCHITTEST, 'WM_NCHITTEST')

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                                        Case $Button1
                                                MsgBox(0,0,"按下了空格键就等于点击了...")
        EndSwitch
WEnd

Func WM_NCHITTEST($hWnd, $Msg, $wParam, $lParam)
        Switch $hWnd
                Case $Form2
                        Return $HTCLIENT
        EndSwitch
EndFunc   ;==>WM_NCHITTEST

在一运行时,按下空格键就等于点击了第一个按钮,回车键也是等于点击了第一个按钮,如何避免呢?
发表于 2014-9-15 19:03:32 | 显示全部楼层
因为,刚开始运行时,窗口的焦点在第一个按钮,所以此时按空格或者回车就相当于是按了第一个按钮
解决办法,可以用GUICtrlSetState ( 控件ID, 状态 )
GUICtrlSetState($2input1, $GUI_FOCUS)
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-27 06:59 , Processed in 0.085757 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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