【已解决】关于GUI内部控件大小控制,如何解决窗口缩放后控件重叠的问题?
本帖最后由 chamlien 于 2016-4-17 11:00 编辑#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
opt('GUIResizeMode',1)
#Region ### START Koda GUI section ### Form=e:\my file\源码\个人开发者审核\ie临时文件助手\form1.kxf
$Form1 = GUICreate("Form1", 785, 451, -1, -1,0x00CF0000)
$Group1 = GUICtrlCreateGroup("Test", 12, 11, 520, 121)
$Input1 = GUICtrlCreateInput("Input1", 138, 40, 380, 23)
GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKLEFT+$GUI_DOCKHEIGHT)
GUISetState(@SW_SHOW)
GUIRegisterMsg(0x0005, '_ChangeSize')
#EndRegion ### END Koda GUI section ###
GUISetOnEvent($GUI_EVENT_CLOSE, "_MainSwitch")
While 1
Sleep(100)
WEnd
Func _ChangeSize()
ControlMove($Form1,'', $Input1, 10,10, 50,23)
EndFunc
Func _MainSwitch()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
GUIDelete($Form1)
Exit
EndSwitch
EndFunc1. 上方窗口缩小后,input控件会超过group控件的位置,如图:
2. 尝试使用 GUIRegisterMsg(0x0005, '_ChangeSize')来改变input的大小,但问题是,程序是先执行GUIRegisterMsg,再执行缩小或放大窗口的动作,也就是GUIRegisterMsg设定的大小会被重新覆盖;
因此,请教一下,怎样才能让input与group控件不重叠?或怎样使GUIRegisterMsg消息动作在放大或缩小窗口之后才执行呢? 本帖最后由 ma395311229 于 2016-4-14 09:08 编辑
是否是你要求的??
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
opt('GUIResizeMode',1)
#Region ### START Koda GUI section ### Form=e:\my file\源码\个人开发者审核\ie临时文件助手\form1.kxf
$Form1 = GUICreate("Form1", 785, 451, -1, -1,0x00CF0000)
$Group1 = GUICtrlCreateGroup("Test", 12, 11, 520, 121)
$Input1 = GUICtrlCreateInput("Input1", 138, 40, 380, 23)
GUICtrlSetResizing(-1, 1)
GUISetState(@SW_SHOW)
GUIRegisterMsg(0x0005, '_ChangeSize')
#EndRegion ### END Koda GUI section ###
GUISetOnEvent($GUI_EVENT_CLOSE, "_MainSwitch")
While 1
Sleep(100)
WEnd
Func _ChangeSize()
ControlMove($Form1,'', $Input1, 10,10, 50,23)
EndFunc
Func _MainSwitch()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
GUIDelete($Form1)
Exit
EndSwitch
EndFunc 回复 2# ma395311229
谢谢你的解答,但不是所要求的。原源码要保持控件的高度不变,左边位置不变,你把那些限制给去掉了。 回复 1# chamlien
那这样呢
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
opt('GUIResizeMode',1)
Global $iWidtha = 785;@DesktopWidth
Global $iHeighta = 451;@DesktopHeight
#Region ### START Koda GUI section ### Form=e:\my file\源码\个人开发者审核\ie临时文件助手\form1.kxf
$Form1 = GUICreate("Form1", $iWidtha, $iHeighta , -1, -1, $WS_OVERLAPPEDWINDOW);,0x00CF0000)
$Group1 = GUICtrlCreateGroup("Test", 12, 11, $iWidtha-265, 121)
$Input1 = GUICtrlCreateInput("Input1", 138, 40, $iWidtha-405, $iHeighta-428)
;GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKLEFT+$GUI_DOCKHEIGHT)
GUISetState(@SW_SHOW)
GUIRegisterMsg(0x0005, '_ChangeSize')
#EndRegion ### END Koda GUI section ###
GUISetOnEvent($GUI_EVENT_CLOSE, "_MainSwitch")
While 1
Sleep(100)
WEnd
Func _ChangeSize()
ControlMove($Form1,'', $Input1, 10,10, 50,23)
EndFunc
Func _MainSwitch()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
GUIDelete($Form1)
Exit
EndSwitch
EndFunc 回复 4# chzj589
谢谢,不过控件还是会往左边缩进,怎样保持左边的位置不动呢? 自顶一下, 本帖最后由 kk_lee69 于 2016-4-15 11:35 编辑
回复 6# chamlien
老實說 我測試 你的源嗎無法測試出你的狀況不知道是甚麼原因
要不要考慮是 作業系統問題 找到了一个折中的方法,控制窗口缩放的最小值,参考来自:http://www.autoitx.com/forum.php?mod=viewthread&tid=24514&highlight=%B4%F3%D0%A1
下面是代码:#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
opt('GUIResizeMode',1)
$Form1 = GUICreate("Form1", 785, 451, -1, -1,0x00CF0000)
$Group1 = GUICtrlCreateGroup("Test", 12, 11, 520, 121)
$Input1 = GUICtrlCreateInput("Input1", 138, 40, 380, 23)
GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKLEFT+$GUI_DOCKHEIGHT)
GUISetState(@SW_SHOW)
GUIRegisterMsg(0x24, "WM_GETMINMAXINFO")
#EndRegion ### END Koda GUI section ###
GUISetOnEvent($GUI_EVENT_CLOSE, "_MainSwitch")
While 1
Sleep(100)
WEnd
Func _MainSwitch()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
GUIDelete($Form1)
Exit
EndSwitch
EndFunc
Func WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lparam)
Local $tBuffer = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lparam)
DllStructSetData($tBuffer, 7, 747);限制窗口的最小宽度为400
Return "GUI_RUNDEFMSG"
EndFunc
是这个效果吗
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Opt('GUIResizeMode', 1)
#region ### START Koda GUI section ### Form=e:\my file\源码\个人开发者审核\ie临时文件助手\form1.kxf
$Form1 = GUICreate("Form1", 785, 451, -1, -1, 0x00CF0000)
$Group1 = GUICtrlCreateGroup("Test", 12, 11, 520, 121)
$Input1 = GUICtrlCreateInput("Input1", 138, 40, 380, 23)
GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKLEFT + $GUI_DOCKHEIGHT)
GUISetState(@SW_SHOW)
GUIRegisterMsg(0x0005, '_ChangeSize')
#endregion ### END Koda GUI section ###
GUISetOnEvent($GUI_EVENT_CLOSE, "_MainSwitch")
While 1
Sleep(100)
WEnd
Func _ChangeSize()
$pos = ControlGetPos($Form1, '', $Group1)
GUICtrlSetPos($Input1, $pos + 126, $pos + 29, $pos - 140, 23)
EndFunc ;==>_ChangeSize
Func _MainSwitch()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
GUIDelete($Form1)
Exit
EndSwitch
EndFunc ;==>_MainSwitch
还是要这个效果?
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
opt('GUIResizeMode',1)
#Region ### START Koda GUI section ### Form=e:\my file\源码\个人开发者审核\ie临时文件助手\form1.kxf
$Form1 = GUICreate("Form1", 785, 451, -1, -1,0x00CF0000)
$Group1 = GUICtrlCreateGroup("Test", 12, 11, 520, 121)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Input1 = GUICtrlCreateInput("Input1", 138, 40, 380, 23)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUISetState(@SW_SHOW)
;GUIRegisterMsg(0x0005, '_ChangeSize')
#EndRegion ### END Koda GUI section ###
GUISetOnEvent($GUI_EVENT_CLOSE, "_MainSwitch")
While 1
Sleep(100)
WEnd
Func _ChangeSize()
ControlMove($Form1,'', $Input1, 10,10, 50,23)
EndFunc
Func _MainSwitch()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
GUIDelete($Form1)
Exit
EndSwitch
EndFunc 回复 9# zldfsz
感谢感谢,原来也挺简单,思路挺重要的,一个GUICtrlSetPos就搞定了,厉害! 回复 10# zldfsz
这个效果控件都是固定的了,感谢,想要的效果已在9楼 回复zldfsz
感谢感谢,原来也挺简单,思路挺重要的,一个GUICtrlSetPos就搞定了,厉害!
chamlien 发表于 2016-4-17 10:59 http://www.autoitx.com/images/common/back.gif
如果大师的代码是你想要的效果,那你应该继续完善最小化、最大化事件。 本帖最后由 chamlien 于 2016-4-17 11:53 编辑
回复 13# afan
这个窗口主要是模仿了IE临时文件助手,最大最小化事件的方法应该很多,下面这个我写的窗口还原还没能解决输入框的位置:#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Opt('GUIResizeMode', 1)
Opt('GUIEventOptions', 1)
#region ### START Koda GUI section ### Form=e:\my file\源码\个人开发者审核\ie临时文件助手\form1.kxf
$Form1 = GUICreate("Form1", 785, 451, -1, -1, 0x00CF0000)
$Group1 = GUICtrlCreateGroup("Test", 12, 11, 520, 121)
GUICtrlSetResizing(-1, $GUI_DOCKMENUBAR + $GUI_DOCKLEFT)
$Input1 = GUICtrlCreateInput("Input1", 138, 40, 380, 23)
GUICtrlSetResizing(-1, $GUI_DOCKMENUBAR + $GUI_DOCKLEFT)
GUISetState(@SW_SHOW)
GUIRegisterMsg(0x0005, '_ChangeSize')
#endregion ### END Koda GUI section ###
GUISetOnEvent($GUI_EVENT_CLOSE, "_MainSwitch")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "_MainSwitch")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "_MainSwitch")
GUISetOnEvent($GUI_EVENT_RESTORE, "_MainSwitch")
While 1
Sleep(100)
WEnd
Func _ChangeSize()
Local $pos = ControlGetPos($Form1, '', $Group1)
GUICtrlSetPos($Input1, $pos + 126, $pos + 29, $pos - 140, 23)
EndFunc ;==>_ChangeSize
Func _MainSwitch()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
GUIDelete($Form1)
Exit
Case $GUI_EVENT_MINIMIZE
GUISetState(@SW_MINIMIZE)
Case $GUI_EVENT_MAXIMIZE
GUISetState(@SW_MAXIMIZE)
_sysWindow()
Case $GUI_EVENT_RESTORE
GUISetState(@SW_RESTORE)
_sysWindow()
EndSwitch
EndFunc ;==>_MainSwitch
Func _sysWindow()
Local $wgroup1 = ControlGetPos($Form1,'', $Group1)
GUICtrlSetPos($Input1, $wgroup1 + 126, $wgroup1 + 29, $wgroup1 - 140, 23)
EndFunc 如果大师的代码是你想要的效果,那你应该继续完善最小化、最大化事件。
afan 发表于 2016-4-17 11:10 http://www.autoitx.com/images/common/back.gif
还是A版考虑得周到
回复 14# chamlien
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Opt('GUIResizeMode', 1)
#region ### START Koda GUI section ### Form=e:\my file\源码\个人开发者审核\ie临时文件助手\form1.kxf
$Form1 = GUICreate("Form1", 785, 451, -1, -1, 0x00CF0000)
$Group1 = GUICtrlCreateGroup("Test", 12, 11, 520, 121)
$Input1 = GUICtrlCreateInput("Input1", 138, 40, 380, 23)
GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKLEFT + $GUI_DOCKHEIGHT)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_WINDOWPOSCHANGED, '_ChangeSize')
GUISetOnEvent($GUI_EVENT_RESTORE, '_ChangeSize')
GUISetOnEvent($GUI_EVENT_RESIZED, '_ChangeSize')
GUISetOnEvent($GUI_EVENT_MAXIMIZE, '_ChangeSize')
#endregion ### END Koda GUI section ###
GUISetOnEvent($GUI_EVENT_CLOSE, "_MainSwitch")
While 1
Sleep(100)
WEnd
Func _ChangeSize()
$pos = ControlGetPos($Form1, '', $Group1)
GUICtrlSetPos($Input1, $pos + 126, $pos + 29, $pos - 140, 23)
EndFunc ;==>_ChangeSize
Func _MainSwitch()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
GUIDelete($Form1)
Exit
EndSwitch
EndFunc ;==>_MainSwitch
页:
[1]
2