【已解决】使用 $WS_TABSTOP后子窗口可以在父窗口里随意拖动,何解?
本帖最后由 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样式且子窗口不能拖动? 回复 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
怎样解决呢? 用这个吧($DS_MODALFRAME)
你要想一起移动就要监听这个事件:$WM_MOVE
用类似这种方式解决:
Func WM_MOVE($hWnd, $Msg, $wParam, $lParam)
;MsgBox(0, "", "test")
$XY = WinGetPos($Form1)
$XY2 = WinGetPos($Form2)
WinMove($Form1, "", $XY2, $XY2)
WinSetOnTop('Form1','',1)
EndFunc
原帖: http://www.autoitx.com/forum.php?mod=viewthread&tid=9044&highlight=%D2%C6%B6%AF 回复 3# MicroBlue
并不能解决我的问题呢 本帖最后由 seniors 于 2014-9-15 10:10 编辑
$Form2 = GUICreate("Login", 505, 270, 45, 80, BitOR($WS_CHILD, $WS_TABSTOP), -1 , $Form1) 回复 5# seniors
这个解决了一点问题,但这样如果子窗口有多个input控件,tab键只能切换到第一个,也就是好像$WS_TABSTOP失效了一半,求解 本帖最后由 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 == $Form2 Then
DllCall( "user32.dll", "BOOL", "ReleaseCapture" )
DllCall( "user32.dll","LRESULT","SendMessage","HWND",$Form1,"UINT",$WM_SYSCOMMAND,"WPARAM",0xF010 + 2,"LPARAM",0)
EndIf
WEnd 回复 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 == $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键只能在“一系列按钮”和“能拖动”这两个控件之间切换 本帖最后由 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 回复 9# seniors
这样tab键可以,但是蓝色区域又可以拖动了.... 暂时找不到其它方法,就先用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 回复 11# seniors
不错!~赞一个~ 回复 11# seniors
非常感谢!!问题已经解决! 回复 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
在一运行时,按下空格键就等于点击了第一个按钮,回车键也是等于点击了第一个按钮,如何避免呢? 因为,刚开始运行时,窗口的焦点在第一个按钮,所以此时按空格或者回车就相当于是按了第一个按钮
解决办法,可以用GUICtrlSetState ( 控件ID, 状态 )
GUICtrlSetState($2input1, $GUI_FOCUS)
页:
[1]
2