Modify

Opened 7 years ago

Closed 7 years ago

#2549 closed Bug (No Bug)

Window controls do not always relocate with GUICtrlSetPos

Reported by: john@… Owned by:
Milestone: Component: AutoIt
Version: 3.3.8.1 Severity: None
Keywords: GUICtrlCreate GUICtrlSetPos Cc:

Description

The program below creates a resizable window. When the window is resized all of the controls move to new positions (not a good thing) so I have a function _Display() which uses GUICtrlSetPos to set the controls back to their original positions. This works for all controls I have tested - except for buttons. With buttons the left and top positions have to be different from those specified in the original GUICtrlCreate for the GUICtrlSetPos to work. You can see this where the Yes and No buttons have the same values as the original but the Exit button has slightly different values. Note also that if the commented out _Display() function in line 22 is called none of the buttons is relocated.

; John - 2 Dec 2013 First test program
; A simple custom messagebox that uses the MessageLoop mode


#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Global $YesID, $NoID, $ExitID, $msg, $winWidth, $winHeight, $hwnd, $LabID, $WidthID, $HeightID, $CBID
$winWidth = 400
$winHeight = 300

$hwnd = GUICreate("John - Custom Msgbox", $winWidth, $winHeight, -1, -1, $WS_SIZEBOX) ; can be resized
$LabID = GUICtrlCreateLabel("Please click a button!", 10, 10)
$YesID = GUICtrlCreateButton("Yes", 10, 50, 50, 20)
$NoID = GUICtrlCreateButton("No", 80, 50, 50, 20)
$ExitID = GUICtrlCreateButton("Exit", 151, 51, 50, 20)
$WidthID = GUICtrlCreateLabel("Width = " & $winWidth, 10, 100)
$HeightID = GUICtrlCreateLabel("Height = " & $winHeight, 100, 100)
$CBID = GUICtrlCreateCheckbox("test", 10, 150)
GUISetState(@SW_SHOWNORMAL, $hwnd) ; display the GUI

;_Display()
Do
	$msg = GUIGetMsg($hwnd)
	If $msg = $GUI_EVENT_RESIZED Then _Display()
Until $msg = $GUI_EVENT_CLOSE Or $msg = $ExitID

Func _Display()
	$winWidth = _WinAPI_GetClientWidth($hwnd)
	$winHeight = _WinAPI_GetClientHeight($hwnd)
	GUICtrlSetPos($LabID, 10, 10)
	GUICtrlSetPos($YesID, 10, 50, 50, 20)
	GUICtrlSetPos($NoID, 80, 50, 50, 20)
	GUICtrlSetPos($ExitID, 150, 50, 50, 20)
	GUICtrlSetData($WidthID, "Width = " & $winWidth)
	GUICtrlSetData($HeightID, "Height = " & $winHeight)
	GUICtrlSetPos($WidthID, 10, 100)
	GUICtrlSetPos($HeightID, 100, 100)
	GUICtrlSetPos($CBID, 10, 150)
EndFunc

Attachments (0)

Change History (4)

comment:1 Changed 7 years ago by Melba23

If you do not want the controls to move when the GUI is resized (which is what you seem to be saying) why not use the correct Resizing code to let Windows know?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
  
; Prevent controls resizing and moving
Opt("GUIResizeMode", $GUI_DOCKSIZE + $GUI_DOCKLEFT + $GUI_DOCKTOP) ; <<<<<<<<<<<<<<<<<

$winWidth = 400
$winHeight = 300 

$hwnd = GUICreate("John - Custom Msgbox", $winWidth, $winHeight, Default, Default,  $WS_SIZEBOX)

$LabID = GUICtrlCreateLabel("Please click a button!", 10, 10)
$YesID = GUICtrlCreateButton("Yes", 10, 50, 50, 20)
$NoID = GUICtrlCreateButton("No", 80, 50, 50, 20)
$ExitID = GUICtrlCreateButton("Exit", 151, 50, 50, 20)
$WidthID = GUICtrlCreateLabel("Width = " & $winWidth, 10, 100)
$HeightID = GUICtrlCreateLabel("Height = " & $winHeight, 100, 100)
$CBID = GUICtrlCreateCheckbox("test", 10, 150)
GUISetState()

Do
	$msg = GUIGetMsg($hwnd)
Until $msg = $GUI_EVENT_CLOSE Or $msg = $ExitID

Now you can leave it all to Windows.

M23

comment:2 Changed 7 years ago by Jpm

Just slight precision the resizing is done by AutoIt not really Windows

comment:3 Changed 7 years ago by john@…

Thanks for that. This is exactly what I wanted. I figured there should be a way of controlling the way the window contents behaved when resized but could not find it in Help. All is clear now.

comment:4 Changed 7 years ago by Jpm

  • Resolution set to No Bug
  • Status changed from new to closed

next time use the forum instead of the bug reporting

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.