Показать полную графическую версию : [решено] По нажатию кнопки в GUI снизу появляется дополнительный сектор окна
Добрый день! Нужно, чтобы по нажатию кнопки снизу появлялась до этого не существовавшая часть окна (ширина равна ширине изначального GUI, высота произвольна).
Как реализовать такую возможность на примере нижеследующего скрипта?
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 550, 146, 192, 124)
$Button1 = GUICtrlCreateButton("Опции >>", 440, 112, 105, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button1
ChangeGUIView() ; тут должен быть код, изменяющий GUI
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func ChangeGUIView()
EndFunc
По нажатию кнопки можно убить форму и создать новую с нужным наполнением, но не хочется, чтобы все лишний раз мигало (некрасиво). Хочу сделать так, чтобы к существующей неизменной форме добавился еще 1 кусок снизу (в дальнейшем понатыкаю туда controls) :)
P.S. Сори, если объяснение того, что нужно, очень пространное, но я не знаю, как это называется. В каких-то окнах я видел реализацию такой возможности, но напрочь не помню, где именно. Поэтому примеров готовых решений предоставить не могу.
#include <GUIConstantsEx.au3>
Global $Guiwidth=550
Global $Guiheight =300
$hGUI = GUICreate("Test", $Guiwidth, $Guiheight)
$ResizeGUI_Button = GUICtrlCreateButton("Опции >>", 440, 250, 105, 25)
$ResizeGUI_Button2 = GUICtrlCreateButton("Опции <<", 440, 95, 105, 25)
GUICtrlSetState($ResizeGUI_Button2,$GUI_HIDE)
;Create test controls
$TestControl= GUICtrlCreateButton("Кнопка", 10, 150, 105, 25)
GUICtrlSetState($TestControl,$GUI_HIDE)
$TestControl2= GUICtrlCreateInput("Инпут", 10, 200, 120, 25)
GUICtrlSetState($TestControl2,$GUI_HIDE)
$TestControl3= GUICtrlCreateCombo("Комбо", 10, 250, 135, 25)
GUICtrlSetState($TestControl3,$GUI_HIDE)
WinMove($hGUI, "", Default, Default, $Guiwidth, $Guiheight-150)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $ResizeGUI_Button
WinMove($hGUI, "", Default, Default,$Guiwidth, $Guiheight)
ControlHide($hGui ,"",$ResizeGUI_Button)
ControlShow($hGui ,"",$ResizeGUI_Button2)
GUICtrlSetState($TestControl,$GUI_Show)
GUICtrlSetState($TestControl2,$GUI_Show)
GUICtrlSetState($TestControl3,$GUI_Show)
Case $ResizeGUI_Button2
ControlHide($hGui ,"",$ResizeGUI_Button2)
GUICtrlSetState($TestControl,$GUI_HIDE)
GUICtrlSetState($TestControl2,$GUI_HIDE)
GUICtrlSetState($TestControl3,$GUI_HIDE)
ControlShow($hGui ,"",$ResizeGUI_Button)
WinMove($hGUI, "", Default, Default,$Guiwidth, $Guiheight-150)
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Единственное затруднение, которое может возникнуть, это угадать точное взаиморасположение кнопок опции, чтобы их местоположение визуально совпадало.
Во-первых нужно не просто расширить окно, но ещё и поместить в него элементы, а для этого их сперва нужно создать (на этапе создания GUI).
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GUIImageList.au3>
;
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $hImageList, $sOld_Opt_GRM = Opt (http://www.autoitscript.com/autoit3/docs/functions/Opt.htm)("GUIResizeMode", $GUI_DOCKALL)
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $iGUI_Height = 150
$Form1 = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("Form1", 550, $iGUI_Height, 192, 124)
$Button1 = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Опции >>", 440, 112, 105, 25, $WS_GROUP)
_GUICtrlButton_SetImageEx($hImageList, $Button1, @SystemDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@SystemDir) & "\rasdlg.dll", 14)
#Region Expanded controls
GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Some Button", 20, 240, 80)
GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Other Button", 120, 240, 80)
GUICtrlCreateInput (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateInput.htm)("Some Input", 20, 200, 200, 20)
Opt (http://www.autoitscript.com/autoit3/docs/functions/Opt.htm)("GUIResizeMode", $sOld_Opt_GRM)
#EndRegion Expanded controls
;
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@SW_SHOW))
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$nMsg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $nMsg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $Button1
_Toggle_ExpandControls_Proc($Form1, $iGUI_Height, $iGUI_Height+150, $Button1, "Опции >>", "Опции <<")
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _Toggle_ExpandControls_Proc($hWnd,$iInitWndHeight,$iExpndHeight,$iExpndCtrlID,$sExpndText="Expand",$sCntrctText="Contract")
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iHeight, $sButtonText, $aSysCaptMetrics, $aSysBordMetrics
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) Const (http://www.autoitscript.com/autoit3/docs/keywords.htm#Const) $SM_CYCAPTION = 4 ;Caption (Title) heigth
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) Const (http://www.autoitscript.com/autoit3/docs/keywords.htm#Const) $SM_CXFIXEDFRAME = 7 ;Window border size
$aSysCaptMetrics = DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)('user32.dll', 'int', 'GetSystemMetrics', 'int', $SM_CYCAPTION)
$aSysBordMetrics = DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)('user32.dll', 'int', 'GetSystemMetrics', 'int', $SM_CXFIXEDFRAME)
$aGuiPos = WinGetPos (http://www.autoitscript.com/autoit3/docs/functions/WinGetPos.htm)($hWnd)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $aGuiPos[3] > $iExpndHeight + $aSysCaptMetrics[0] Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
_GUICtrlButton_SetImageEx($hImageList, $iExpndCtrlID, @SystemDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@SystemDir) & "\rasdlg.dll", 14)
$iHeight = $iInitWndHeight + $aSysCaptMetrics[0] + ($aSysBordMetrics[0] * 2)
$sButtonText = $sExpndText
Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else)
_GUICtrlButton_SetImageEx($hImageList, $iExpndCtrlID, @SystemDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@SystemDir) & "\rasdlg.dll", 16)
$iHeight = $iExpndHeight + $aSysCaptMetrics[0] + ($aSysBordMetrics[0] * 2)
$sButtonText = $sCntrctText
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($iExpndCtrlID, $sButtonText)
WinMove (http://www.autoitscript.com/autoit3/docs/functions/WinMove.htm)($hWnd, "", $aGuiPos[0], $aGuiPos[1], $aGuiPos[2], $iHeight)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _GUICtrlButton_SetImageEx(ByRef (http://www.autoitscript.com/autoit3/docs/keywords.htm#ByRef) $hImageList, $nCtrl, $sIconFile, $nIconID=0, $nAlign=-1)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $hImageList Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) _GUIImageList_Destroy($hImageList)
$hImageList = _GUIImageList_Create(16, 16, 5, 1)
_GUIImageList_AddIcon($hImageList, $sIconFile, $nIconID)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $stBIL = DllStructCreate (http://www.autoitscript.com/autoit3/docs/functions/DllStructCreate.htm)("dword;int[4];uint")
DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($stBIL, 1, $hImageList)
DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($stBIL, 2, 1, 1)
DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($stBIL, 2, 1, 2)
DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($stBIL, 2, 1, 3)
DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($stBIL, 2, 1, 4)
DllStructSetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructSetData.htm)($stBIL, 3, $nAlign)
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) GUICtrlSendMsg (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSendMsg.htm)($nCtrl, $BCM_SETIMAGELIST, 0, DllStructGetPtr (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetPtr.htm)($stBIL))
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
FlatX007
26-10-2009, 22:34
Во-первых нужно не просто расширить окно, но ещё и поместить в него элементы » ... клёво спасибо давно искал но боялся спросить =)
Да, действительно круто, спасибо!
FlatX007
10-03-2010, 09:54
Во-первых нужно не просто расширить окно, но ещё и поместить в него элементы, а для этого их сперва нужно создать (на этапе создания GUI). »
А как с помощью этой функции поменять ширину окна ? :search:
А как с помощью этой функции поменять ширину окна ? »
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GUIImageList.au3>
;
Global $hImageList, $sOld_Opt_GRM = Opt("GUIResizeMode", $GUI_DOCKALL)
Global $iGUI_Width = 385
Global $iGUI_Height = 162
$Form1 = GUICreate("Form", $iGUI_Width, $iGUI_Height, 192, 186)
$Button1 = GUICtrlCreateButton(">", 370, 0, 15, 160, $WS_GROUP)
#Region Expanded controls
$ExitButton = GUICtrlCreateButton("Exit", 470, 130, 75, 25, $WS_GROUP)
GUICtrlCreateInput("Some Input", 405, 20, 121, 21)
Opt("GUIResizeMode", $sOld_Opt_GRM)
#EndRegion Expanded controls
;
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button1
_Toggle_ExpandControls_Proc($Form1, $iGUI_Width, $iGUI_Width+165, $Button1, ">", "<")
Case $GUI_EVENT_CLOSE, $ExitButton
Exit
EndSwitch
WEnd
Func _Toggle_ExpandControls_Proc($hWnd,$iInitWndWidth,$iExpndWidth,$iExpndCtrlID,$sExpndText="<",$sCntrctText=">")
Local $iWidth, $sButtonText, $aSysCaptMetrics, $aSysBordMetrics
Local Const $SM_CXFIXEDFRAME = 7 ;Window border size
$aSysBordMetrics = DllCall('user32.dll', 'int', 'GetSystemMetrics', 'int', $SM_CXFIXEDFRAME)
$aGuiPos = WinGetPos($hWnd)
If $aGuiPos[2] > $iExpndWidth Then
$iWidth = $iInitWndWidth + ($aSysBordMetrics[0] * 2)
$sButtonText = $sExpndText
Else
$iWidth= $iExpndWidth + ($aSysBordMetrics[0] * 2)
$sButtonText = $sCntrctText
EndIf
GUICtrlSetData($iExpndCtrlID, $sButtonText)
WinMove($hWnd, "", $aGuiPos[0], $aGuiPos[1], $iWidth, $aGuiPos[3])
EndFunc
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.
Available in ZeroNet 1osznRoVratMCN3bFoFpR2pSV5c9z6sTC