Jump to content

Slide to Expand GUI


Recommended Posts

Hi,

I am trying to create a GUI with an initially hidden set of controls that will slide out and and give access to the controls on it.

I have a simple GUI and when you click a button I want the bottom to slide out and reveal some other controlls.

I have used Winmove to accomplish this but I do not like the "feel" of it.--The transition is too fast

I have looked at user32.dll functions but have not been able to get it to work

Func Slide_out()

$hide_state = 1

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $finder, "int", 500, "long", 0x00050004);slide out

GUISetState(@SW_SHOW, $finder)

WinActivate($finder)

WinWaitActive($finder)

EndFunc ;==>Slide_out

In this example I have a second Form "$finder" that has the controls that are needed in the expanded area. All that this did was reveal the previously hidden $finder form. There was no slide action.

As you can tell the only button that has a function is button4.

CODE
#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <StaticConstants.au3>

#include <EditConstants.au3>

#include <ButtonConstants.au3>

#include <GuiToolbar.au3>

#include <ToolbarConstants.au3>

Opt("GuiResizeMode", 802)

Global $hide_state = 0, $btn_state = 0, $pass = 0

Global $Sep = IniRead("OM.ini","Variable","Sep","")

$sIniFile = @WorkingDir & "\OM.ini"

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Form1", 645, 366, 193, 125)

;$Hide = GUICtrlCreateButton("^", 301, 693, 51, 25, BitOR($BS_CENTER, $BS_FLAT, $BS_MULTILINE))

$Apps = GUICtrlCreateButton("Button1", 8, 246, 152, 69, $BS_BITMAP)

$DeleteCl = GUICtrlCreateButton("Button2", 167, 246, 152, 69, $BS_BITMAP)

$Deleteprod = GUICtrlCreateButton("Button3", 326, 246, 152, 69, $BS_BITMAP)

$Rebuild = GUICtrlCreateButton("Button4", 485, 246, 152, 69, $BS_BITMAP)

GUISetState(@SW_SHOW)

$finder = GUICreate("Finder", 633, 447, 192, 506)

$Edit1 = GUICtrlCreateEdit("", 5, 17, 619, 187)

GUICtrlSetData(-1, "")

$Reset = GUICtrlCreateButton("Reset", 377, 346, 75, 25, 0)

$Close = GUICtrlCreateButton("Close", 474, 346, 75, 25, 0)

$Group1 = GUICtrlCreateGroup("Edit", 10, 218, 545, 121)

GUICtrlCreateGroup("", -99, -99, 1, 1)

$Input1 = GUICtrlCreateInput("", 127, 244, 121, 21)

$Label1 = GUICtrlCreateLabel("ini Section", 56, 250, 50, 17)

$Input2 = GUICtrlCreateInput("", 119, 277, 313, 21)

$Input3 = GUICtrlCreateInput("", 119, 311, 313, 21)

$Label2 = GUICtrlCreateLabel("Title", 57, 283, 40, 17)

$Label3 = GUICtrlCreateLabel("Solution", 60, 314, 40, 17)

$update = GUICtrlCreateButton("Update", 462, 235, 75, 25, $WS_GROUP)

$hide = GUICtrlCreateButton("(Not allowed)", 274, 421, 51, 25, $BS_BITMAP)

GUISetState(@SW_HIDE)

#EndRegion ### END Koda GUI section ###

$output = ""

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Rebuild

;Winmove($Form1, "",Default,Default,665, 771)

Slide_out()

$output = $output & @CRLF & IniRead("OM.ini","Rebuild","Title","")

$output = $output & @CRLF & $Sep

$output = $output & @CRLF & " "& IniRead("OM.ini","Rebuild","Solution","")

GuiCtrlSetData($Edit1,$output)

GuiCtrlSetData($input1,"Rebuild")

GuiCtrlSetData($input2,IniRead("OM.ini","Rebuild","Title",""))

GuiCtrlSetData($input3,IniRead("OM.ini","Rebuild","Solution",""))

$output = ""

If $nMsg = $Hide Then

If $pass = 1 Then

;WinSetTitle($hwnd2, "", "Sliding Launcher")

$pass = 0

EndIf

EndIf

Case $Reset

If $nMsg = $Reset Then ResetClick()

Case $Close

If $nMsg = $Close Then Exit

;Case $Closehelp

;If $nmsg = $Closehelp Then Closehlp()

Case $Update

IniWrite("OM.ini", GUICtrlRead($input1) , "Title", GuiCtrlRead($Input2))

IniWrite("OM.ini", GUICtrlRead($input1) , "Solution", GuiCtrlRead($Input3))

EndSwitch

WEnd

Func ResetClick()

GuiCtrlSetData($Edit1,"")

Winmove($Form1, "",Default,Default,650, 366,100)

EndFunc

Func Slide_in()

$hide_state = 0

GUISetState(@SW_HIDE, $finder)

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Form1, "int", 500, "long", 0x00040001);slide in

WinActivate($Form1)

WinWaitActive($Form1)

EndFunc ;==>Slide_in

Func Slide_out()

$hide_state = 1

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $finder, "int", 500, "long", 0x00050004);slide out

GUISetState(@SW_SHOW, $finder)

WinActivate($finder)

WinWaitActive($finder)

EndFunc ;==>Slide_out

;Func Closehlp ()

;$hide_state = 0

; GUISetState(@SW_HIDE, $Form1)

; DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Form1, "int", 500, "long", 0x00040008)

; WinActivate($Form1)

; WinWaitActive($Form1)

;EndFunc ;==>Slide_inDllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Form1, "int", 500, "long", 0x00040008)

;Winmove($Form1, "",Default,Default,650, 366,100)

;EndFunc

;Func expanded($expanded)

; If $expanded = True Then WinMove($Form, "", Default, Default, 262, 246)

;If $expanded = False Then WinMove($Form, "", Default, Default, 137, 246)

;EndFunc ;==>expanded

Link to comment
Share on other sites

Hey thanks I was able to modify the example and it looks good.

Here is the modded code that I used

CODE
#include <WindowsConstants.au3>

#Include <WinAPI.au3>

Global Const $WM_ENTERSIZEMOVE = 0x0231

Global Const $WM_EXITSIZEMOVE = 0x0232

Global $Sep = IniRead("OM.ini","Variable","Sep","")

$main_height = 300 ;height of the pop-up window

$slide_speed = 600 ;window pop-up/down speed, bigger number = slower, smaller number = faster

$sIniFile = @WorkingDir & "\OM.ini"

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Form1", 645, 366, 193, 125)

$Button1 = GUICtrlCreateButton("Button1", 8, 246, 152, 69)

$Button2 = GUICtrlCreateButton("Button2", 167, 246, 152, 69)

$Button3 = GUICtrlCreateButton("Button3", 326, 246, 152, 69)

$Button4 = GUICtrlCreateButton("Button4", 485, 246, 152, 69)

GUISetState(@SW_SHOW)

$ParentPosArr = WinGetPos($Form1)

$finder = GUICreate("", 640, 383, 0, 392,$WS_POPUP +$WS_BORDER, $WS_EX_MDICHILD, $Form1)

$childpos = WinGetPos($finder)

$Edit1 = GUICtrlCreateEdit("", 5, 17, 619, 187)

GUICtrlSetData(-1, "")

$Reset = GUICtrlCreateButton("Reset", 377, 346, 75, 25, 0)

$Close = GUICtrlCreateButton("Close", 474, 346, 75, 25, 0)

$hide = GUICtrlCreateButton("Hide", 274, 358, 51, 25)

GUISetState(@SW_HIDE)

$Form2 = GUICreate("", 579, 381, 646,2,$WS_POPUP +$WS_BORDER, $WS_EX_MDICHILD, $Form1)

$hide2 = GUICtrlCreateButton("<-", 554, 185, 25, 25)

GUISetState(@SW_HIDE)

WinSetTrans($Form1, "", 255) ;if it's not set to 255, then sliding out has visual bugs

GUISetState(@SW_SHOW, $Form1)

$ParentPosArr = WinGetPos($Form1)

GUIRegisterMsg($WM_ENTERSIZEMOVE,"WM_ENTERSIZEMOVE")

GUIRegisterMsg($WM_EXITSIZEMOVE, "WM_EXITSIZEMOVE")

#EndRegion ### END Koda GUI section ###

Func WM_ENTERSIZEMOVE($hWndGUI, $MsgID, $WParam, $LParam)

WinSetTrans($finder,"",254)

EndFunc

Func WM_EXITSIZEMOVE($hWndGUI, $MsgID, $WParam, $LParam)

WinSetTrans($finder,"",255)

EndFunc

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

_show_child_window($Button1, $slide_speed)

Case $Button2

_show_child_window($Button2, $slide_speed)

Case $Button3

_show_child_RT($Button3, $slide_speed)

Case $Button4

_show_child_RT($Button1, $slide_speed)

Case $Close

If $nMsg = $Close Then Exit

Case $hide

_slide_out($finder, $slide_speed)

Case $hide2

_slide_lft($Form2, $slide_speed)

EndSwitch

WEnd

Func _show_child_window($button_handle, $Speed)

if WinExists($finder) then

endif

_slide_in($finder, $Speed, $button_handle)

EndFunc

func _slide_in($hwGui, $Speed, $hwCtrl)

Local $position = ControlGetPos($Form1, "", $hwCtrl)

Local $position2 = WinGetPos($Form1)

Local $position2b = WinGetClientSize($Form1)

Local $position3 = WinGetPos($hwGui)

Local $light_border = ($position2[2]-$position2b[0])/2

Local $thick_border = ($position2[3]-$position2b[1])-$light_border

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwGui, "int", $Speed, "long", 0x00040004)

_WinAPI_RedrawWindow($hwGui)

GUISetState(@SW_SHOW, $hwGui)

EndFunc

func _slide_out($hwGui, $Speed)

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwGui, "int", $Speed, "long", 0x00050008)

GUISetState(@SW_HIDE, $hwGui)

EndFunc

Func _show_child_Rt($button_handle, $Speed)

if WinExists($Form2) then

endif

_slide_RT($Form2, $Speed, $button_handle)

EndFunc

func _slide_Rt($hwGui, $Speed, $hwCtrl)

Local $position = ControlGetPos($Form1, "", $hwCtrl)

Local $position2 = WinGetPos($Form1)

Local $position2b = WinGetClientSize($Form1)

Local $position3 = WinGetPos($hwGui)

Local $light_border = ($position2[2]-$position2b[0])/2

Local $thick_border = ($position2[3]-$position2b[1])-$light_border

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwGui, "int", $Speed, "long", 0x00040001)

_WinAPI_RedrawWindow($hwGui)

GUISetState(@SW_SHOW, $hwGui)

EndFunc

func _slide_lft($hwGui, $Speed)

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwGui, "int", $Speed, "long", 0x00050002)

GUISetState(@SW_HIDE, $hwGui)

EndFunc

Once I understood that slide in meant slide into view it helped. For some reason I had that backwards.

Someone with more experience than I have could clean this up, but this is what worked for Me. Maybe this will help someone else.

Thank You mdiesel for pointing me in the right direction and thanks to sandin for the original post.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...