GUI window enable/disable Resize Option and Top Bar

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
GEOVAN
Posts: 192
Joined: 03 Mar 2022, 11:12

GUI window enable/disable Resize Option and Top Bar

19 Oct 2023, 09:35

There is the following simple GUI

Code: Select all

#NoEnv
#SingleInstance Force
SetBatchLines -1

MyText =
(
F2 -> Removes the Menu bar of the GUI

F3 -> Bring back the Menu bar of the GUI

F4 -> Makes the GUI window not resizable

F5 -> Makes the GUI window resizable
)



Gui +Resize +Maxsize%A_ScreenWidth%x%A_ScreenHeight% +Minsize280x200
Gui, Add, Text , x10 y10 ,  Info:
Gui, Add, Edit, x10 y25 h150 w250 ReadOnly, %MyText% 
Gui show
Return



F2::   ;Removes the Menu bar of the GUI
Gui, -caption
Return


F3::   ;Bring back the Menu bar of the GUI
Gui, +caption
Return


F4::    ;Makes the GUI window not resizable
winset, style, -0x40000, A
Return


F5::     ;Makes the GUI window resizable
winset, style, +0x40000, A
Return


GuiClose:
ExitApp
Note:
F2 -> Removes the Menu bar of the GUI
F3 -> Bring back the Menu bar of the GUI
F4 -> Makes the GUI window not resizable
F5 -> Makes the GUI window resizable

Please let me ask:

(1) By pressing F2 -----> it removes the Menu bar of the GUI, but it leaves a small thin area below the row of buttons as shown in below screenshot. Is there a way to avoid this, please?
image.png
image.png (10.62 KiB) Viewed 1846 times


(2) By pressing F4 -----> Makes the GUI window not resizable
BUT it INCREASES the GUI size a little.
Is there a way to avoid this, please?
image.png
image.png (84.71 KiB) Viewed 1841 times
GEOVAN
Posts: 192
Joined: 03 Mar 2022, 11:12

Re: GUI window enable/disable Resize Option and Top Bar

20 Oct 2023, 09:18

I found the following info -- https://www.autohotkey.com/board/topic/84673-gui-resize-and-aero-theme/

And if i use the following dllcall BEFORE gui show line, the problem is solved:

Code: Select all

      Gui, +LastFound
      ThisGuiHwnd := WinExist()
      DllCall("uxtheme\SetWindowTheme", "Uint", ThisGuiHwnd, "Uint", 0, "UintP", 0)
But the gui window now is shown as:
image.png
image.png (15.06 KiB) Viewed 1753 times
Please, is there any better workaround solution?
Is this error is a bug of AHK ( AHK is setting a wrong style for the window somewhere when Aero theme is enabled? or the default style that it is using it not compatible with Aero? or something else?

Please i will appreciate your help
GEOVAN
Posts: 192
Joined: 03 Mar 2022, 11:12

Re: GUI window enable/disable Resize Option and Top Bar

23 Oct 2023, 14:47

Please, i will appreciate any help on this topic, please?
just me
Posts: 9573
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: GUI window enable/disable Resize Option and Top Bar

24 Oct 2023, 04:36

GEOVAN wrote: Is this error is a bug of AHK ( AHK is setting a wrong style for the window somewhere when Aero theme is enabled? or the default style that it is using it not compatible with Aero?
Definitely not!
User avatar
Hellbent
Posts: 2114
Joined: 23 Sep 2017, 13:34

Re: GUI window enable/disable Resize Option and Top Bar

24 Oct 2023, 09:59

GEOVAN wrote:
23 Oct 2023, 14:47
Please, i will appreciate any help on this topic, please?
Use your own resize routine and logic instead of using the +Resize option.

i.e. Pick a spot on your gui that triggers resizing. You can use a rectangle ( point in rect. ) or a circle ( distance from point ).
You can also set it up for edge detection.
GEOVAN
Posts: 192
Joined: 03 Mar 2022, 11:12

Re: GUI window enable/disable Resize Option and Top Bar

24 Oct 2023, 13:15

Use your own resize routine and logic instead of using the +Resize option.
i.e. Pick a spot on your gui that triggers resizing. You can use a rectangle ( point in rect. ) or a circle ( distance from point ).
You can also set it up for edge detection.


Very very interesting.Thank you very much!
Unfortunately I can not find a way to do it. Can you please demonstrate in our example code how can we successfully do it, please?

EXAMPLE CODE:

Code: Select all

#NoEnv
#SingleInstance Force
SetBatchLines -1

MyText =
(
F2 -> Removes the Menu bar of the GUI

F3 -> Bring back the Menu bar of the GUI

F4 -> Makes the GUI window not resizable

F5 -> Makes the GUI window resizable
)



Gui +Resize +Maxsize%A_ScreenWidth%x%A_ScreenHeight% +Minsize280x200
Gui, Add, Text , x10 y10 ,  Info:
Gui, Add, Edit, x10 y25 h150 w250 ReadOnly, %MyText% 
Gui show
Return



F2::   ;Removes the Menu bar of the GUI
Gui, -caption
Return


F3::   ;Bring back the Menu bar of the GUI
Gui, +caption
Return


F4::    ;Makes the GUI window not resizable
winset, style, -0x40000, A
Return


F5::     ;Makes the GUI window resizable
winset, style, +0x40000, A
Return


GuiClose:
ExitApp
User avatar
Hellbent
Posts: 2114
Joined: 23 Sep 2017, 13:34

Re: GUI window enable/disable Resize Option and Top Bar

24 Oct 2023, 23:45

Here is an example.

.
custom resize 1.gif
custom resize 1.gif (204.13 KiB) Viewed 1473 times
.

Code: Select all

#SingleInstance, Force
SetBatchLines, -1
;--------------
Gui1 := {}
;--------------
Gui, New , +AlwaysOnTop +hwndhwnd
Gui1.Hwnd := hwnd
;--------------
Gui, Margin, 10 , 10
;--------------
Gui, Add, Button, w120 r1 , Demo control 1
Gui, Add, Edit, x+10 , Demo Control 2
Gui, Add, ListBox, xm , Demo Control 3||
;--------------
Gui, -Caption
Gui, Show, Hide
;--------------
Gui, +LastFound
WinGetPos,,, w , h
Gui1.W := w 
Gui1.H := h
Gui1.MinWidth := w 
Gui1.MinHeight := h
Gui1.ResizeVector := New Vector( w , h )
Gui1.ResizeVector.Radius := 10
;--------------
Gui, Show, AutoSize
;--------------
Gui1.CaptionMode := 0
Gui1.ReSizeMode := 1
;--------------
OnMessage( 0x201 , func( "WM_LButtonDown" ).Bind( Gui1 ) )
;--------------
return
;--------------
GuiClose:
GuiContextMenu:
*ESC::ExitApp
;--------------
F1::	;{
	if( Gui1.CaptionMode := !Gui1.CaptionMode )
		Gui, % Gui1.Hwnd ":+Caption"
	else
		Gui, % Gui1.Hwnd ":-Caption"
	Gui, % Gui1.Hwnd ":Show", % " w" Gui1.W " h" Gui1.H 
	return
;}
;--------------
F2::	;{
	Gui1.ReSizeMode := !Gui1.ReSizeMode
	return 
;}
;--------------
WM_LButtonDown( Gui1 ){
	CoordMode, Mouse, Client
	MouseGetPos, x , y , win 
	if( win != Gui1.Hwnd )
		return
	;x /= ( A_ScreenDPI / 96 )
	;y /= ( A_ScreenDPI / 96 )
	MouseVector := New Vector( x , y )
	if( Gui1.ReSizeMode && MouseVector.Dist( Gui1.ResizeVector ) <= Gui1.ResizeVector.Radius ){
		Gui, % Gui1.Hwnd ":-Caption"
		WinGetPos, winX , winY 
		CoordMode, Mouse, Screen
		While( GetKeyState( "LButton" , "P" ) ){
			MouseGetPos, x , y
			Gui1.ResizeVector.X := Gui1.W := ( x < winX + Gui1.MinWidth ) ? ( Gui1.MinWidth ) : ( x - winX )
			Gui1.ResizeVector.Y := Gui1.H := ( y < winY + Gui1.MinHeight ) ? ( Gui1.MinHeight ) : ( y - winY )
			Gui, % Gui1.Hwnd ":Show", % " w" Gui1.W " h" Gui1.H 
		}
		if( Gui1.CaptionMode ){
			Gui, % Gui1.Hwnd ":+Caption"
			Gui, % Gui1.Hwnd ":Show", % " w" Gui1.W " h" Gui1.H
		}
		return 1
	}
	
}

;************
;Vector Class
;**************************************************************************************************************************************************************************
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;**************************************************************************************************************************************************************************
Class Vector	{
	;Written By: HB
	;Date: Sept 23rd, 2022
	;Last Edit: Sept 24th, 2022
	;Purpose: Vector math class 
	;Credit: Rohwedder 
	;Resources: 
		;Line intercept concepts and code: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=37175
		;Create an Arrow: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=92039&p=479129#p478944
		;Getting an angle: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=108760&p=483661#p483678
		;Setting an Angle: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=108760&p=483786#p483811
		;
		
	static RadToDeg := 45 / ATan( 1 ) 
		, DegToRad := ATan( 1 ) / 45 
		
	__New( x := 0 , y := 0 , rotate := 0 ){ 
		if( IsObject( x ) ){
			if( rotate = 3 ){
				This.X := x.X * -1
				,This.Y := x.Y * -1
			}else if( rotate = 2 ){
				This.X := x.Y 
				,This.Y := x.X * -1
			}else if( rotate = 1 ){
				This.X := x.Y * -1
				,This.Y := x.X 
			}else{
				This.X := x.X
				,This.Y := x.Y
			}
		}else{
			if( rotate = 3 ){
				This.X := X * -1
				,This.Y := Y * -1
			}else if( rotate = 2 ){
				This.X := Y 
				,This.Y := X * -1
			}else if( rotate = 1 ){
				This.X := Y * -1
				,This.Y := X 
			}else{
				This.X := X
				,This.Y := Y
			}
		}
	}
	Add( x , y := "" ){
		if( IsObject( x ) ){
			This.X += x.X
			,This.Y += x.Y
		}else if( y = "" ){
			This.X += x 
			,This.Y += x
		}else{
			This.X += x 
			,This.Y += y 
		}
	}
	Sub( x , y := "" ){
		if( IsObject( x ) ){
			This.X -= x.X
			,This.Y -= x.Y
		}else if( y = "" ){
			This.X -= X
			,This.Y -= X
		}else{
			This.X -= X
			,This.Y -= Y
		}
	}
	Div( x , y := "" ){
		if( IsObject( x ) ){
			This.X /= x.X
			,This.Y /= x.Y
		}else if( x && y = "" ){
			This.X /= x 
			,This.Y /= x 
		}else{
			This.X /= X
			,This.Y /= Y
		}
	}
	Mult( x , y := "" ){
		if( IsObject( x ) ){
			This.X *= x.X
			,This.Y *= x.Y
		}else if( x && y = "" ){
			This.X *= x 
			,This.Y *= x 
		}else{
			This.X *= X
			,This.Y *= Y
		}
	}
	Dist( x , y := "" ){
		if( IsObject( x ) )
			return Sqrt( ( ( This.X - x.X ) **2 ) + ( ( This.Y - x.Y ) **2 ) )
		else 
			return Sqrt( ( ( This.X - X ) **2 ) + ( ( This.Y - Y ) **2 ) )
	}
	GetMag(){
		return Sqrt( This.X * This.X + This.Y * This.Y )
	}
	SetMag( magnitude ){
		local m := This.GetMag()
		This.X := This.X * magnitude / m
		,This.Y := This.Y * magnitude / m
	}
	MagSq(){
		return This.GetMag()**2
	}	
	Dot( x , y := "" ){
		if( IsObject( x ) )
			return ( This.X * x.X ) + ( This.Y * x.Y )
		else
			return ( This.X * X ) + ( This.Y * Y )
	}
	Cross( x , y := "" ){
		if( IsObject( x ) )
			return This.X * x.Y - This.Y * x.X
		else
			return This.X * Y - This.Y * X
		
	}
	Norm(){
		local m := This.GetMag()
		This.X /= m
		This.Y /= m
	}
	GetAngle(){ 
		local angle 
		( (  angle := Vector.RadToDeg * DllCall( "msvcrt\atan2" , "Double" , This.Y , "Double" , This.X , "CDECL Double" ) ) < 0 ) ? ( angle += 360 )
		return angle
	}
	SetAngle( newAngle := 0 , NewVector := 0 ){
		local Angle := This.GetAngle()
		, ChangeAngle := newAngle - Angle 
		, Co := Cos( Vector.DegToRad * ChangeAngle )
		, Si := Sin( Vector.DegToRad * ChangeAngle )
		, X := This.X 
		, Y := This.Y
		, X2 := X * Co - Y * Si 
		, Y2 := X * Si + Y * Co 
		
		if( !NewVector )
			This.X := X2 , This.Y := Y2
		else 
			return New Vector( X2 , Y2 )
	}
	RotateAngle( rotationAmount := 90 , NewVector := 0 ){
		local Co := Cos( Vector.DegToRad * rotationAmount )
		, Si := Sin( Vector.DegToRad * rotationAmount )
		, X := This.X 
		, Y := This.Y
		, X2 := X * Co - Y * Si 
		, Y2 := X * Si + Y * Co 
		
		if( !NewVector )
			This.X := X2 , This.Y := Y2
		else 
			return New Vector( X2 , Y2 )
	}
	;********************************************
	;class methods
	TestLineInterceptPoint( interceptPoint , Line1 , Line2 ){ ; Line = { Start: { X: , Y: } , End: { X: , Y: } } , interceptPoint = { X: , Y: }
		local
		for k , v in [ "X" , "Y" ]	
			M%v%_Min := min( Line1.Start[ v ] , Line1.End[ v ] )
			,M%v%_Max := max( Line1.Start[ v ] , Line1.End[ v ] )
			,L%v%_Min := min( Line2.Start[ v ] , Line2.End[ v ] )
			,L%v%_Max := max( Line2.Start[ v ] , Line2.End[ v ] )
		if( !( interceptPoint.X < Mx_Min || interceptPoint.X > Mx_Max || interceptPoint.X < Lx_Min || interceptPoint.X > Lx_Max ) && !( interceptPoint.Y < My_Min || interceptPoint.Y > My_Max || interceptPoint.Y < Ly_Min || interceptPoint.Y > Ly_Max ) )
			return 1
		return 0
	}
	GetLineInterceptPoint( Line1 , Line2 ){ ; Line = { Start: { X: , Y: } , End: { X: , Y: } }
		local A1 := Line1.End.Y - Line1.Start.Y
		,B1 := Line1.Start.X - Line1.End.X
		,C1 := A1 * Line1.Start.X + B1 * Line1.Start.Y
		,A2 := Line2.End.Y - Line2.Start.Y
		,B2 := Line2.Start.X - Line2.End.X
		,C2 := A2 * Line2.Start.X + B2 * Line2.Start.Y
		,Denominator := A1 * B2 - A2 * B1 
		return New Vector( { X: ( ( B2 * C1 - B1 * C2 ) / Denominator )  , Y: ( ( A1 * C2 - A2 * C1 ) / Denominator ) } )
	}
	;********************************************
}
;**************************************************************************************************************************************************************************
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;**************************************************************************************************************************************************************************
User avatar
Hellbent
Posts: 2114
Joined: 23 Sep 2017, 13:34

Re: GUI window enable/disable Resize Option and Top Bar

25 Oct 2023, 01:21

Here is another example that uses a custom gui class for scaling.

viewtopic.php?f=76&t=122044&p=543571#p543571

.
custom resize 2.gif
custom resize 2.gif (617.43 KiB) Viewed 1462 times
.

Code: Select all

#SingleInstance, Force
SetBatchLines, -1
MyText =
(
F2 -> Removes the Menu bar of the GUI

F3 -> Bring back the Menu bar of the GUI

F4 -> Makes the GUI window not resizable

F5 -> Makes the GUI window resizable
)
Gui1 := New Gui( "+AlwaysOnTop +E0x02000000 +E0x00080000" )
Gui1.Margin( 10 , 10 )
Gui1.SetFont( Size := 9 , color := "Black" , Options := "" , Type := "Arial" )
Gui1.Add( "Text" , "xm ym" , "Info:" , "InfoTextControl" )
Gui1.Add( "Edit" , "xm y+m w250 h150" , MyText )
Gui1.Set( Gui1.Controls.InfoTextControl.Hwnd ,, "Focus" )
Gui1.Options( "-Caption" )
DetectHiddenWindows, On
Gui1.Show( "Hide AutoSize" )
Gui1.CaptionLessSize := Gui1.WindowPosition()
Gui1.Options( "-E0x02000000 -E0x00080000 +Caption" )
Gui1.Show( "AutoSize" )
Gui1.Options( "+E0x02000000 +E0x00080000" )
Gui1.CaptionedSize := Gui1.WindowPosition()
Gui1.OriginalSize := { W: Gui1.CaptionLessSize.W , H: Gui1.CaptionLessSize.H }
Gui1.TriggerRadius := 10
Gui1.ResizeMode := 1
Gui1.CaptionMode := 1
OnMessage( 0x201 , func( "ClickEvent" ).bind( Gui1 ) )
return
;|<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>|
GuiClose:
GuiContextMenu:
*ESC::ExitApp
;|<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>|
F2::	;{
	Gui1.Options( "-Caption" )
	Gui1.Show( "AutoSize" )
	return
;}
;|<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>|
F3::	;{
	Gui1.Options( "-E0x02000000 -E0x00080000 +Caption" )
	Gui1.Options( "+E0x02000000 +E0x00080000" )
	Gui1.Show( "AutoSize" )
	return
;}
;|<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>|
F4::	;{
	Gui1.ResizeMode := false
	return
;}
;|<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>|
F5::	;{
	Gui1.ResizeMode := True
	return
;}
;|<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>|	
ClickEvent( Gui1 ){
	SetControlDelay, -1
	CoordMode, Mouse, Window
	MouseGetPos, x , y , win 
	if( win != Gui1.Hwnd )
		return 
	MouseVector := New Vector( x , y )
	pos := Gui1.WindowPosition()
	triggerVector  := New Vector( pos.W , pos.H )
	if( Gui1.ResizeMode && MouseVector.Dist( triggerVector ) <= Gui1.TriggerRadius ){
		While( GetKeyState( "LButton" , "P" ) ){
			CoordMode, Mouse, Screen
			MouseGetPos, x , y
			pos := Gui1.WindowPosition()
			scale := ( x - pos.X ) / Gui1.OriginalSize.W 
			if( scale < 1 )
				scale := 1
			Gui1.ScaleAllControls( scale )
			Gui1.Margin( 10 * scale , 10 * scale )
			Gui1.Show( "AutoSize" )
			Gui1.Options( "+LastFound" )
			WinSet, Redraw 
			sleep, 60
		}
		Gui1.Show( "Hide" )
		Gui1.Show( "AutoSize" )
	}
}
;|<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>|
;|<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>|
class Gui	{
	static Index := 0 , Windows := [] , Handles := []
	;Written By: Hellbent
	;Date: Sept 9th, 2021
	;Last Edit: Oct 16th 2023
	;Class to create Easy Scale windows
	__New( Options := "+AlwaysOnTop" , Title := "" ){
		local hwnd
		
		;********************
		Gui, New, % Options " +Hwndhwnd" , % Title
		
		This.Hwnd := hwnd
		;********************
		This.Controls := {}
		This.ControlArray := []
		This.Handles := []
		;********************
		This.FontType := "Arial"
		This.FontSize := 10
		This.FontColor := "Black"
		This.FontOptions := ""
		This.Font()
		;********************
		This.Color := "F0F0F0"
		This.ControlColor := "FFFFFF"
		
		This.SetColors()
		;********************
		
		Gui.Handles[ This.Hwnd ] := Gui.Windows[ ++Gui.Index ] := This
		This.Show( "Hide w1 h1 " )
		
	}
	Show( Options := "" , Title := "" ){
		Gui, % This.Hwnd ":Show" , % Options , % Title
	}
	Hide( Name := 1 ){
		Gui, % Name ":Hide"
	}
	Enable(){
		Gui, % This.Hwnd ":-Disabled"
	}
	Disable(){
		Gui, % This.Hwnd ":+Disabled"
	}
	Destroy( Name := 1 ){
		Try
			Gui, % This.Hwnd ":Destroy"
	}
	__Delete(){
		Try
			Gui, % This.Hwnd ":Destroy"
	}
	Get( Control , SubCommand := "" ){
		local output
		GuiControlGet, output, % This.Hwnd ":" SubCommand , % Control
		return output
	}
	Set( Control , Value := "" , SubCommand := "" ){
		GuiControl, % This.Hwnd ":" SubCommand , % Control , % Value
	}
	Margin( x := 10 , y := 10 ){
		Gui, % This.Hwnd ":Margin", % x , % y
	}
	SetColors( Color1 := "" , Color2 := "" ){
		if( Color1 != "" )
			This.Color := Color1
		if( Color2 != "" )
			This.ControlColor := Color2
		Gui, % This.Hwnd ":Color", % This.Color , % This.ControlColor
	}
	WindowPosition(){
		local x , y , w , h
		WinGetPos, x , y , w , h , % "ahk_id " This.Hwnd
		return { X: x , Y: y , W: w , H: h }
	}
	ControlPosition( Hwnd ){
		local pos , posX , posY , PosW , PosH
		GuiControlGet, pos , % This.Hwnd ":pos", % Hwnd
		if( This.Handles[ hwnd ].Index ){
			This.Handles[ hwnd ].Position := { X: posX , Y: posY , W: posW , H: posH }
			return
		}else{
			return { X: posX , Y: posY , W: posW , H: posH }
		}
	}
	Add( Type := "Button" , Options := "" , Display := "" , ControlName := "" , ScaleMode := "" , rows := "" ){ ;scaleMode 1: scale via font size. 2= scale via controls size
		static ScaleModeList := { "Text": 1 , "Edit": 1 , "Button": 1 , "DDL": 2 , "DropDownList": 2 , "ListBox": 1 , "CheckBox": 1 }
		local hwnd 
		Gui, % This.Hwnd ":Add", % Type, % Options " hwndhwnd " , % Display
		if( ControlName != "" ){
			This.Controls[ ControlName ] := {}
			This.Controls[ ControlName ].Name := ControlName
			This.Controls[ ControlName ].Hwnd := hwnd
			This.Controls[ ControlName ].Type := type
			This.Handles[ hwnd ] := This.Controls[ ControlName ]
			This.ControlArray.Push( This.Controls[ ControlName ] )
		}else{
			This.Controls[ hwnd ] := {}
			This.Controls[ hwnd ].Name := hwnd
			This.Controls[ hwnd ].Type := Type
			This.Controls[ hwnd ].Hwnd := hwnd
			This.Handles[ hwnd ] := This.Controls[ hwnd ]
			This.ControlArray.Push( This.Controls[ hwnd ] )
		}
		if( ScaleMode != "" )
			This.Handles[ hwnd ].ScaleMode := ScaleMode
		else
			This.Handles[ hwnd ].ScaleMode := ScaleModeList[ type ]
		if( This.Handles[ hwnd ].ScaleMode = "" )
			This.Handles[ hwnd ].ScaleMode := 1
		
		This.Handles[ hwnd ].Index := This.ControlArray.Length()
		
		This.ControlPosition( Hwnd )
		This.Handles[ hwnd ].Font := { Type: This.FontType , Size: This.FontSize , Color: This.FontColor , Options: This.FontOptions }
		
		if( rows != "" )
			This.Handles[ hwnd ].Rows := rows
			
	}
	SetFont( Size := "" , color := "" , Options := "" , Type := "" ){
		
		if( Size != "" )
			This.FontSize := Size
		if( color != "" )
			This.FontColor := Color
		if( Options != "" )
			This.FontOptions := Options
		if( Type != "" )
			This.FontType := Type
		Gui, % This.Hwnd ":Font", % "norm s" ( This.FontSize * A_ScreenDPI / 96 ) " c" This.FontColor " " This.FontOptions , % This.FontType
	}
	Options( Options ){
		Gui, % This.Hwnd ":" Options
	}
	Bind( Control , Method , BoundObject := "" ){
		local fn 
		if( BoundObject = "Label" )
			fn := Method
		else if( BoundObject != "" )
			fn := Func( Method ).Bind( This , Control , BoundObject )
		else
			fn := Func( Method ).Bind( This , Control )
		GuiControl, % This.Hwnd ":+g", % Control, % fn
	}
	ScaleControl( ControlHwnd , scalefactor , mode := 1 ){
		if( mode = 1 ){
			cc := This.Handles[ ControlHwnd ].Position
			x := cc.X * scaleFactor
			y := cc.Y * scaleFactor
			w := cc.W * scaleFactor
			h := cc.H * scaleFactor
			This.SetControlFont( controlhwnd , , , , , scalefactor )
			
			This.Set( ControlHwnd , "X" x " y" y " w " w " h" h , "MoveDraw" )
			
		}else if( mode = 2 ){
			
			cc := This.Handles[ ControlHwnd ].Position
			x := cc.X * scaleFactor
			y := cc.Y * scaleFactor
			w := cc.W * scaleFactor
			h := ( 16 * This.Handles[ ControlHwnd ].Rows ) * scaleFactor
			This.SetControlFont( controlhwnd , , , , , scalefactor )
			This.Set( ControlHwnd , "X" x " y" y " w " w " h" h , "MoveDraw" )
		}
	}
	SetControlFont( controlhwnd , Size := "" , color := "" , Options := "" , Type := "" , Scale := 1 ){
		cc := This.Handles[ controlhwnd ].Font
		if( Size != "" ){
			cc.Size := Size
			Size /= A_ScreenDPI / 96
			Size *= Scale
		}else{
			Size := ( cc.Size / ( A_ScreenDPI / 96 ) ) * Scale
		}
		if( color != "" )
			cc.Color := Color
		else
			Color := cc.Color
		if( Options != "" )
			cc.Options := Options
		else
			Options := cc.Options
		if( Type != "" )
			cc.Type := Type
		else
			Type := cc.Type 
		Gui, % This.Hwnd ":Font" , % " norm s" size " c" color " " options , % Type
		This.Set( controlhwnd ,, "Font" )
	}
	ScaleAllControls( scale := 1 ){
		for k, v in This.ControlArray	{
			cc := This.ControlArray[ k ]
			This.ScaleControl( cc.Hwnd , Scale , mode := cc.ScaleMode )
		}
	}
}
;************
;Vector Class
;**************************************************************************************************************************************************************************
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;**************************************************************************************************************************************************************************
Class Vector	{
	;Written By: HB
	;Date: Sept 23rd, 2022
	;Last Edit: Sept 24th, 2022
	;Purpose: Vector math class 
	;Credit: Rohwedder 
	;Resources: 
		;Line intercept concepts and code: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=37175
		;Create an Arrow: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=92039&p=479129#p478944
		;Getting an angle: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=108760&p=483661#p483678
		;Setting an Angle: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=108760&p=483786#p483811
		;
		
	static RadToDeg := 45 / ATan( 1 ) 
		, DegToRad := ATan( 1 ) / 45 
		
	__New( x := 0 , y := 0 , rotate := 0 ){ 
		if( IsObject( x ) ){
			if( rotate = 3 ){
				This.X := x.X * -1
				,This.Y := x.Y * -1
			}else if( rotate = 2 ){
				This.X := x.Y 
				,This.Y := x.X * -1
			}else if( rotate = 1 ){
				This.X := x.Y * -1
				,This.Y := x.X 
			}else{
				This.X := x.X
				,This.Y := x.Y
			}
		}else{
			if( rotate = 3 ){
				This.X := X * -1
				,This.Y := Y * -1
			}else if( rotate = 2 ){
				This.X := Y 
				,This.Y := X * -1
			}else if( rotate = 1 ){
				This.X := Y * -1
				,This.Y := X 
			}else{
				This.X := X
				,This.Y := Y
			}
		}
	}
	Add( x , y := "" ){
		if( IsObject( x ) ){
			This.X += x.X
			,This.Y += x.Y
		}else if( y = "" ){
			This.X += x 
			,This.Y += x
		}else{
			This.X += x 
			,This.Y += y 
		}
	}
	Sub( x , y := "" ){
		if( IsObject( x ) ){
			This.X -= x.X
			,This.Y -= x.Y
		}else if( y = "" ){
			This.X -= X
			,This.Y -= X
		}else{
			This.X -= X
			,This.Y -= Y
		}
	}
	Div( x , y := "" ){
		if( IsObject( x ) ){
			This.X /= x.X
			,This.Y /= x.Y
		}else if( x && y = "" ){
			This.X /= x 
			,This.Y /= x 
		}else{
			This.X /= X
			,This.Y /= Y
		}
	}
	Mult( x , y := "" ){
		if( IsObject( x ) ){
			This.X *= x.X
			,This.Y *= x.Y
		}else if( x && y = "" ){
			This.X *= x 
			,This.Y *= x 
		}else{
			This.X *= X
			,This.Y *= Y
		}
	}
	Dist( x , y := "" ){
		if( IsObject( x ) )
			return Sqrt( ( ( This.X - x.X ) **2 ) + ( ( This.Y - x.Y ) **2 ) )
		else 
			return Sqrt( ( ( This.X - X ) **2 ) + ( ( This.Y - Y ) **2 ) )
	}
	GetMag(){
		return Sqrt( This.X * This.X + This.Y * This.Y )
	}
	SetMag( magnitude ){
		local m := This.GetMag()
		This.X := This.X * magnitude / m
		,This.Y := This.Y * magnitude / m
	}
	MagSq(){
		return This.GetMag()**2
	}	
	Dot( x , y := "" ){
		if( IsObject( x ) )
			return ( This.X * x.X ) + ( This.Y * x.Y )
		else
			return ( This.X * X ) + ( This.Y * Y )
	}
	Cross( x , y := "" ){
		if( IsObject( x ) )
			return This.X * x.Y - This.Y * x.X
		else
			return This.X * Y - This.Y * X
		
	}
	Norm(){
		local m := This.GetMag()
		This.X /= m
		This.Y /= m
	}
	GetAngle(){ 
		local angle 
		( (  angle := Vector.RadToDeg * DllCall( "msvcrt\atan2" , "Double" , This.Y , "Double" , This.X , "CDECL Double" ) ) < 0 ) ? ( angle += 360 )
		return angle
	}
	SetAngle( newAngle := 0 , NewVector := 0 ){
		local Angle := This.GetAngle()
		, ChangeAngle := newAngle - Angle 
		, Co := Cos( Vector.DegToRad * ChangeAngle )
		, Si := Sin( Vector.DegToRad * ChangeAngle )
		, X := This.X 
		, Y := This.Y
		, X2 := X * Co - Y * Si 
		, Y2 := X * Si + Y * Co 
		
		if( !NewVector )
			This.X := X2 , This.Y := Y2
		else 
			return New Vector( X2 , Y2 )
	}
	RotateAngle( rotationAmount := 90 , NewVector := 0 ){
		local Co := Cos( Vector.DegToRad * rotationAmount )
		, Si := Sin( Vector.DegToRad * rotationAmount )
		, X := This.X 
		, Y := This.Y
		, X2 := X * Co - Y * Si 
		, Y2 := X * Si + Y * Co 
		
		if( !NewVector )
			This.X := X2 , This.Y := Y2
		else 
			return New Vector( X2 , Y2 )
	}
	;********************************************
	;class methods
	TestLineInterceptPoint( interceptPoint , Line1 , Line2 ){ ; Line = { Start: { X: , Y: } , End: { X: , Y: } } , interceptPoint = { X: , Y: }
		local
		for k , v in [ "X" , "Y" ]	
			M%v%_Min := min( Line1.Start[ v ] , Line1.End[ v ] )
			,M%v%_Max := max( Line1.Start[ v ] , Line1.End[ v ] )
			,L%v%_Min := min( Line2.Start[ v ] , Line2.End[ v ] )
			,L%v%_Max := max( Line2.Start[ v ] , Line2.End[ v ] )
		if( !( interceptPoint.X < Mx_Min || interceptPoint.X > Mx_Max || interceptPoint.X < Lx_Min || interceptPoint.X > Lx_Max ) && !( interceptPoint.Y < My_Min || interceptPoint.Y > My_Max || interceptPoint.Y < Ly_Min || interceptPoint.Y > Ly_Max ) )
			return 1
		return 0
	}
	GetLineInterceptPoint( Line1 , Line2 ){ ; Line = { Start: { X: , Y: } , End: { X: , Y: } }
		local A1 := Line1.End.Y - Line1.Start.Y
		,B1 := Line1.Start.X - Line1.End.X
		,C1 := A1 * Line1.Start.X + B1 * Line1.Start.Y
		,A2 := Line2.End.Y - Line2.Start.Y
		,B2 := Line2.Start.X - Line2.End.X
		,C2 := A2 * Line2.Start.X + B2 * Line2.Start.Y
		,Denominator := A1 * B2 - A2 * B1 
		return New Vector( { X: ( ( B2 * C1 - B1 * C2 ) / Denominator )  , Y: ( ( A1 * C2 - A2 * C1 ) / Denominator ) } )
	}
	;********************************************
}
;**************************************************************************************************************************************************************************
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;**************************************************************************************************************************************************************************
GEOVAN
Posts: 192
Joined: 03 Mar 2022, 11:12

Re: GUI window enable/disable Resize Option and Top Bar

25 Oct 2023, 07:41

Thank you very much for the great tutorials.

Please let me say, that this is not exactly what i need.
Please let me explain better what i need:

I want to TOGGLE between winset, style, -0x40000, A AND winset, style, +0x40000, A
Here is the toggle code using F4 and F5 to TOGGLE:

Code: Select all

#NoEnv
#SingleInstance Force
SetBatchLines -1

MyText =
(
F4 -> Makes the GUI window not resizable
F5 -> Makes the GUI window resizable
)



Gui +Resize +Maxsize%A_ScreenWidth%x%A_ScreenHeight% +Minsize280x200
Gui, Add, Text , x10 y10 ,  Info:
Gui, Add, Edit, x10 y25 h150 w250 ReadOnly, %MyText% 
Gui show
Return



F4::    
winset, style, -0x40000, A
Return


F5::     
winset, style, +0x40000, A
Return


GuiClose:
ExitApp
THE PROBLEM is the following:
When toggle F4 and F5 the GUI window increases its window size and decreases it (F4 --> increases GUI window size, and F5 -->decreases GUI window size)
BUT i do not want this INCREASE and DECREASE of GUI window size.
Is there a way to avoid this, please?
User avatar
Hellbent
Posts: 2114
Joined: 23 Sep 2017, 13:34

Re: GUI window enable/disable Resize Option and Top Bar

25 Oct 2023, 10:37

GEOVAN wrote:
25 Oct 2023, 07:41
THE PROBLEM is the following:
When toggle F4 and F5 the GUI window increases its window size and decreases it (F4 --> increases GUI window size, and F5 -->decreases GUI window size)
BUT i do not want this INCREASE and DECREASE of GUI window size.
Is there a way to avoid this, please?
Yes.
Hellbent wrote:
24 Oct 2023, 09:59
Use your own resize routine and logic instead of using the +Resize option.
You may have missed the first example.

viewtopic.php?f=76&t=122461&p=544455#p544419
User avatar
Hellbent
Posts: 2114
Joined: 23 Sep 2017, 13:34

Re: GUI window enable/disable Resize Option and Top Bar

25 Oct 2023, 22:11

GEOVAN wrote:
25 Oct 2023, 16:39
Thank you very much.
Here is the first example written with the gui class.


.
custom resize 3.gif
custom resize 3.gif (256.96 KiB) Viewed 1260 times
.

Code: Select all

#SingleInstance, Force
SetBatchLines, -1

MyText =
(
F2 -> Removes the Menu bar of the GUI

F3 -> Bring back the Menu bar of the GUI

F4 -> Makes the GUI window not resizable

F5 -> Makes the GUI window resizable
)

;create a new gui / object
Gui1 := New Gui()

;set the margin and the font
Gui1.Margin( 10 , 10 )
Gui1.SetFont( Size := 9 , color := "Black" , Options := "" , Type := "Arial" )

;add the controls
Gui1.Add( "Text" , "xm ym" , "Info:" , "InfoTextControl" )
Gui1.Add( "Edit" , "xm y+m w250 h150" , MyText )

;set the focus to the text control (take focus away from the edit control)
Gui1.Set( Gui1.Controls.InfoTextControl.Hwnd ,, "Focus" )

;Get the size of the window without the title and border
Gui1.Options( "-Caption" )
DetectHiddenWindows, On
Gui1.Show( "Hide AutoSize" )
Gui1.CaptionLessSize := Gui1.WindowPosition()

;Add the title and border back again and get the new size.
Gui1.Options( "+Caption" )
Gui1.Show( "AutoSize" )
Gui1.CaptionedSize := Gui1.WindowPosition()

;get the width of the border on the sides of the window
Gui1.CapWidth := ( Gui1.CaptionedSize.W - Gui1.CaptionLessSize.W ) / 2

;get the height of the title bar (the bottom border is the same as side borders )
Gui1.CapHeight := Gui1.CaptionedSize.H - Gui1.CaptionLessSize.H ;- Gui1.CapWidth

;set the minimum width and height of the window
Gui1.MinWidth := Gui1.CaptionLessSize.W
Gui1.MinHeight := Gui1.CaptionLessSize.H 

;set the radius for the resize trigger (click the bottom right corner of the window)
Gui1.TriggerRadius := 10

;set the current resize mode ( 0 = resize is off | 1 = resize is on )
Gui1.ResizeMode := True

;set the current caption mode ( 0 = the title is removed | 1 = the window has the title )
Gui1.CaptionMode := True

;set up to monitor clicks on the window
OnMessage( 0x201 , func( "ClickEvent" ).bind( Gui1 ) )

return
;|<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>|
GuiClose:
GuiContextMenu:
*ESC::ExitApp
;|<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>|
F2::	;{	Remove Caption
	if( Gui1.CaptionMode ){
		Gui1.Options( "-Caption" )
		Gui1.CaptionMode := False
	}
	return
;}
;|<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>|
F3::	;{	Add Caption
	if( !Gui1.CaptionMode ){
		change := 0
		Gui1.Options( "+Caption" )
		Gui1.CaptionMode := True
		pos := Gui1.WindowPosition()
		w := pos.w - Gui1.CapWidth * 2
		if( w < Gui1.MinWidth ){
			w := Gui1.MinWidth
			change := 1
		}
		h := ( pos.h - Gui1.CapHeight )
		if( h < Gui1.MinHeight ){
			h := Gui1.MinHeight 
			change := 1
		}
		if( change )
			Gui1.Show( "w" w " h" h )
	}
	return
;}
;|<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>|
F4::	;{	Turn off resize
	Gui1.ResizeMode := false
	return
;}
;|<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>|
F5::	;{	Turn on resize
	Gui1.ResizeMode := True
	return
;}
;|<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>|	
ClickEvent( Gui1 ){	;Gets called when you click on the window
	
	;set the coord mode to "window"
	CoordMode, Mouse, Window
	
	;get the position and the hwnd of the window under the cursor
	MouseGetPos, x , y , win 
	
	;do nothing if it's the wrong window or if resize mode is turned off
	if( win != Gui1.Hwnd || !Gui1.ResizeMode )
		return 
	
	;create a vector object for the cursor position
	MouseVector := New Vector( x , y )
	
	;get the current position of the window
	pos := Gui1.WindowPosition()
	
	;create a vector object for the resize trigger position
	triggerVector  := New Vector( pos.W , pos.H )
	
	;check if the distance between the click position and the trigger position is less than the trigger radius
	if( MouseVector.Dist( triggerVector ) <= Gui1.TriggerRadius ){
		
		;loop while the mouse button is being held
		While( GetKeyState( "LButton" , "P" ) ){
			
			;set the coord mode to the "Screen"
			CoordMode, Mouse, Screen
			
			;get the cursor position
			MouseGetPos, x , y
			
			
			if( Gui1.CaptionMode ){	;if the window has its caption on
				
				;set the new window width
				( ( w := ( x - Pos.X - Gui1.CapWidth ) ) < Gui1.MinWidth ) ? ( w := Gui1.MinWidth )
				
				;set the new window height
				( ( h := ( y - Pos.Y - Gui1.CapHeight ) ) < Gui1.MinHeight ) ? ( h := Gui1.MinHeight )
			
			}else{	;if the caption is removed
				
				;set the new window width 
				( ( w := ( x - Pos.X ) ) < Gui1.MinWidth ) ? ( w := Gui1.MinWidth )
				
				;set the new window height
				( ( h := ( y - Pos.Y ) ) < Gui1.MinHeight ) ? ( h := Gui1.MinHeight )
				
			}
			
			;show the window with its new size
			Gui1.Show( "w" w " h" h )
			
		}
	}
}
;|<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>|
;|<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>||<<<---(0)_(0)--->>>|
class Gui	{
	static Index := 0 , Windows := [] , Handles := []
	;Written By: Hellbent
	;Date: Sept 9th, 2021
	;Last Edit: Oct 16th 2023
	;Class to create Easy Scale windows
	__New( Options := "+AlwaysOnTop" , Title := "" ){
		local hwnd
		
		;********************
		Gui, New, % Options " +Hwndhwnd" , % Title
		
		This.Hwnd := hwnd
		;********************
		This.Controls := {}
		This.ControlArray := []
		This.Handles := []
		;********************
		This.FontType := "Arial"
		This.FontSize := 10
		This.FontColor := "Black"
		This.FontOptions := ""
		This.Font()
		;********************
		This.Color := "F0F0F0"
		This.ControlColor := "FFFFFF"
		
		This.SetColors()
		;********************
		
		Gui.Handles[ This.Hwnd ] := Gui.Windows[ ++Gui.Index ] := This
		This.Show( "Hide w1 h1 " )
		
	}
	Show( Options := "" , Title := "" ){
		Gui, % This.Hwnd ":Show" , % Options , % Title
	}
	Hide( Name := 1 ){
		Gui, % Name ":Hide"
	}
	Enable(){
		Gui, % This.Hwnd ":-Disabled"
	}
	Disable(){
		Gui, % This.Hwnd ":+Disabled"
	}
	Destroy( Name := 1 ){
		Try
			Gui, % This.Hwnd ":Destroy"
	}
	__Delete(){
		Try
			Gui, % This.Hwnd ":Destroy"
	}
	Get( Control , SubCommand := "" ){
		local output
		GuiControlGet, output, % This.Hwnd ":" SubCommand , % Control
		return output
	}
	Set( Control , Value := "" , SubCommand := "" ){
		GuiControl, % This.Hwnd ":" SubCommand , % Control , % Value
	}
	Margin( x := 10 , y := 10 ){
		Gui, % This.Hwnd ":Margin", % x , % y
	}
	SetColors( Color1 := "" , Color2 := "" ){
		if( Color1 != "" )
			This.Color := Color1
		if( Color2 != "" )
			This.ControlColor := Color2
		Gui, % This.Hwnd ":Color", % This.Color , % This.ControlColor
	}
	WindowPosition(){
		local x , y , w , h
		WinGetPos, x , y , w , h , % "ahk_id " This.Hwnd
		return { X: x , Y: y , W: w , H: h }
	}
	ControlPosition( Hwnd ){
		local pos , posX , posY , PosW , PosH
		GuiControlGet, pos , % This.Hwnd ":pos", % Hwnd
		if( This.Handles[ hwnd ].Index ){
			This.Handles[ hwnd ].Position := { X: posX , Y: posY , W: posW , H: posH }
			return
		}else{
			return { X: posX , Y: posY , W: posW , H: posH }
		}
	}
	Add( Type := "Button" , Options := "" , Display := "" , ControlName := "" , ScaleMode := "" , rows := "" ){ ;scaleMode 1: scale via font size. 2= scale via controls size
		static ScaleModeList := { "Text": 1 , "Edit": 1 , "Button": 1 , "DDL": 2 , "DropDownList": 2 , "ListBox": 1 , "CheckBox": 1 }
		local hwnd 
		Gui, % This.Hwnd ":Add", % Type, % Options " hwndhwnd " , % Display
		if( ControlName != "" ){
			This.Controls[ ControlName ] := {}
			This.Controls[ ControlName ].Name := ControlName
			This.Controls[ ControlName ].Hwnd := hwnd
			This.Controls[ ControlName ].Type := type
			This.Handles[ hwnd ] := This.Controls[ ControlName ]
			This.ControlArray.Push( This.Controls[ ControlName ] )
		}else{
			This.Controls[ hwnd ] := {}
			This.Controls[ hwnd ].Name := hwnd
			This.Controls[ hwnd ].Type := Type
			This.Controls[ hwnd ].Hwnd := hwnd
			This.Handles[ hwnd ] := This.Controls[ hwnd ]
			This.ControlArray.Push( This.Controls[ hwnd ] )
		}
		if( ScaleMode != "" )
			This.Handles[ hwnd ].ScaleMode := ScaleMode
		else
			This.Handles[ hwnd ].ScaleMode := ScaleModeList[ type ]
		if( This.Handles[ hwnd ].ScaleMode = "" )
			This.Handles[ hwnd ].ScaleMode := 1
		
		This.Handles[ hwnd ].Index := This.ControlArray.Length()
		
		This.ControlPosition( Hwnd )
		This.Handles[ hwnd ].Font := { Type: This.FontType , Size: This.FontSize , Color: This.FontColor , Options: This.FontOptions }
		
		if( rows != "" )
			This.Handles[ hwnd ].Rows := rows
			
	}
	SetFont( Size := "" , color := "" , Options := "" , Type := "" ){
		
		if( Size != "" )
			This.FontSize := Size
		if( color != "" )
			This.FontColor := Color
		if( Options != "" )
			This.FontOptions := Options
		if( Type != "" )
			This.FontType := Type
		Gui, % This.Hwnd ":Font", % "norm s" ( This.FontSize * A_ScreenDPI / 96 ) " c" This.FontColor " " This.FontOptions , % This.FontType
	}
	Options( Options ){
		Gui, % This.Hwnd ":" Options
	}
	Bind( Control , Method , BoundObject := "" ){
		local fn 
		if( BoundObject = "Label" )
			fn := Method
		else if( BoundObject != "" )
			fn := Func( Method ).Bind( This , Control , BoundObject )
		else
			fn := Func( Method ).Bind( This , Control )
		GuiControl, % This.Hwnd ":+g", % Control, % fn
	}
	ScaleControl( ControlHwnd , scalefactor , mode := 1 ){
		if( mode = 1 ){
			cc := This.Handles[ ControlHwnd ].Position
			x := cc.X * scaleFactor
			y := cc.Y * scaleFactor
			w := cc.W * scaleFactor
			h := cc.H * scaleFactor
			This.SetControlFont( controlhwnd , , , , , scalefactor )
			
			This.Set( ControlHwnd , "X" x " y" y " w " w " h" h , "MoveDraw" )
			
		}else if( mode = 2 ){
			
			cc := This.Handles[ ControlHwnd ].Position
			x := cc.X * scaleFactor
			y := cc.Y * scaleFactor
			w := cc.W * scaleFactor
			h := ( 16 * This.Handles[ ControlHwnd ].Rows ) * scaleFactor
			This.SetControlFont( controlhwnd , , , , , scalefactor )
			This.Set( ControlHwnd , "X" x " y" y " w " w " h" h , "MoveDraw" )
		}
	}
	SetControlFont( controlhwnd , Size := "" , color := "" , Options := "" , Type := "" , Scale := 1 ){
		cc := This.Handles[ controlhwnd ].Font
		if( Size != "" ){
			cc.Size := Size
			Size /= A_ScreenDPI / 96
			Size *= Scale
		}else{
			Size := ( cc.Size / ( A_ScreenDPI / 96 ) ) * Scale
		}
		if( color != "" )
			cc.Color := Color
		else
			Color := cc.Color
		if( Options != "" )
			cc.Options := Options
		else
			Options := cc.Options
		if( Type != "" )
			cc.Type := Type
		else
			Type := cc.Type 
		Gui, % This.Hwnd ":Font" , % " norm s" size " c" color " " options , % Type
		This.Set( controlhwnd ,, "Font" )
	}
	ScaleAllControls( scale := 1 ){
		for k, v in This.ControlArray	{
			cc := This.ControlArray[ k ]
			This.ScaleControl( cc.Hwnd , Scale , mode := cc.ScaleMode )
		}
	}
}
;************
;Vector Class
;**************************************************************************************************************************************************************************
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;**************************************************************************************************************************************************************************
Class Vector	{
	;Written By: HB
	;Date: Sept 23rd, 2022
	;Last Edit: Sept 24th, 2022
	;Purpose: Vector math class 
	;Credit: Rohwedder 
	;Resources: 
		;Line intercept concepts and code: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=37175
		;Create an Arrow: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=92039&p=479129#p478944
		;Getting an angle: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=108760&p=483661#p483678
		;Setting an Angle: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=108760&p=483786#p483811
		;
		
	static RadToDeg := 45 / ATan( 1 ) 
		, DegToRad := ATan( 1 ) / 45 
		
	__New( x := 0 , y := 0 , rotate := 0 ){ 
		if( IsObject( x ) ){
			if( rotate = 3 ){
				This.X := x.X * -1
				,This.Y := x.Y * -1
			}else if( rotate = 2 ){
				This.X := x.Y 
				,This.Y := x.X * -1
			}else if( rotate = 1 ){
				This.X := x.Y * -1
				,This.Y := x.X 
			}else{
				This.X := x.X
				,This.Y := x.Y
			}
		}else{
			if( rotate = 3 ){
				This.X := X * -1
				,This.Y := Y * -1
			}else if( rotate = 2 ){
				This.X := Y 
				,This.Y := X * -1
			}else if( rotate = 1 ){
				This.X := Y * -1
				,This.Y := X 
			}else{
				This.X := X
				,This.Y := Y
			}
		}
	}
	Add( x , y := "" ){
		if( IsObject( x ) ){
			This.X += x.X
			,This.Y += x.Y
		}else if( y = "" ){
			This.X += x 
			,This.Y += x
		}else{
			This.X += x 
			,This.Y += y 
		}
	}
	Sub( x , y := "" ){
		if( IsObject( x ) ){
			This.X -= x.X
			,This.Y -= x.Y
		}else if( y = "" ){
			This.X -= X
			,This.Y -= X
		}else{
			This.X -= X
			,This.Y -= Y
		}
	}
	Div( x , y := "" ){
		if( IsObject( x ) ){
			This.X /= x.X
			,This.Y /= x.Y
		}else if( x && y = "" ){
			This.X /= x 
			,This.Y /= x 
		}else{
			This.X /= X
			,This.Y /= Y
		}
	}
	Mult( x , y := "" ){
		if( IsObject( x ) ){
			This.X *= x.X
			,This.Y *= x.Y
		}else if( x && y = "" ){
			This.X *= x 
			,This.Y *= x 
		}else{
			This.X *= X
			,This.Y *= Y
		}
	}
	Dist( x , y := "" ){
		if( IsObject( x ) )
			return Sqrt( ( ( This.X - x.X ) **2 ) + ( ( This.Y - x.Y ) **2 ) )
		else 
			return Sqrt( ( ( This.X - X ) **2 ) + ( ( This.Y - Y ) **2 ) )
	}
	GetMag(){
		return Sqrt( This.X * This.X + This.Y * This.Y )
	}
	SetMag( magnitude ){
		local m := This.GetMag()
		This.X := This.X * magnitude / m
		,This.Y := This.Y * magnitude / m
	}
	MagSq(){
		return This.GetMag()**2
	}	
	Dot( x , y := "" ){
		if( IsObject( x ) )
			return ( This.X * x.X ) + ( This.Y * x.Y )
		else
			return ( This.X * X ) + ( This.Y * Y )
	}
	Cross( x , y := "" ){
		if( IsObject( x ) )
			return This.X * x.Y - This.Y * x.X
		else
			return This.X * Y - This.Y * X
		
	}
	Norm(){
		local m := This.GetMag()
		This.X /= m
		This.Y /= m
	}
	GetAngle(){ 
		local angle 
		( (  angle := Vector.RadToDeg * DllCall( "msvcrt\atan2" , "Double" , This.Y , "Double" , This.X , "CDECL Double" ) ) < 0 ) ? ( angle += 360 )
		return angle
	}
	SetAngle( newAngle := 0 , NewVector := 0 ){
		local Angle := This.GetAngle()
		, ChangeAngle := newAngle - Angle 
		, Co := Cos( Vector.DegToRad * ChangeAngle )
		, Si := Sin( Vector.DegToRad * ChangeAngle )
		, X := This.X 
		, Y := This.Y
		, X2 := X * Co - Y * Si 
		, Y2 := X * Si + Y * Co 
		
		if( !NewVector )
			This.X := X2 , This.Y := Y2
		else 
			return New Vector( X2 , Y2 )
	}
	RotateAngle( rotationAmount := 90 , NewVector := 0 ){
		local Co := Cos( Vector.DegToRad * rotationAmount )
		, Si := Sin( Vector.DegToRad * rotationAmount )
		, X := This.X 
		, Y := This.Y
		, X2 := X * Co - Y * Si 
		, Y2 := X * Si + Y * Co 
		
		if( !NewVector )
			This.X := X2 , This.Y := Y2
		else 
			return New Vector( X2 , Y2 )
	}
	;********************************************
	;class methods
	TestLineInterceptPoint( interceptPoint , Line1 , Line2 ){ ; Line = { Start: { X: , Y: } , End: { X: , Y: } } , interceptPoint = { X: , Y: }
		local
		for k , v in [ "X" , "Y" ]	
			M%v%_Min := min( Line1.Start[ v ] , Line1.End[ v ] )
			,M%v%_Max := max( Line1.Start[ v ] , Line1.End[ v ] )
			,L%v%_Min := min( Line2.Start[ v ] , Line2.End[ v ] )
			,L%v%_Max := max( Line2.Start[ v ] , Line2.End[ v ] )
		if( !( interceptPoint.X < Mx_Min || interceptPoint.X > Mx_Max || interceptPoint.X < Lx_Min || interceptPoint.X > Lx_Max ) && !( interceptPoint.Y < My_Min || interceptPoint.Y > My_Max || interceptPoint.Y < Ly_Min || interceptPoint.Y > Ly_Max ) )
			return 1
		return 0
	}
	GetLineInterceptPoint( Line1 , Line2 ){ ; Line = { Start: { X: , Y: } , End: { X: , Y: } }
		local A1 := Line1.End.Y - Line1.Start.Y
		,B1 := Line1.Start.X - Line1.End.X
		,C1 := A1 * Line1.Start.X + B1 * Line1.Start.Y
		,A2 := Line2.End.Y - Line2.Start.Y
		,B2 := Line2.Start.X - Line2.End.X
		,C2 := A2 * Line2.Start.X + B2 * Line2.Start.Y
		,Denominator := A1 * B2 - A2 * B1 
		return New Vector( { X: ( ( B2 * C1 - B1 * C2 ) / Denominator )  , Y: ( ( A1 * C2 - A2 * C1 ) / Denominator ) } )
	}
	;********************************************
}
;**************************************************************************************************************************************************************************
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 00000 <<<>>> 00000 
;**************************************************************************************************************************************************************************
GEOVAN
Posts: 192
Joined: 03 Mar 2022, 11:12

Re: GUI window enable/disable Resize Option and Top Bar

26 Oct 2023, 14:30

Thank you very much.

But, please note that the EDITBOX is NOT resizable in your example.
BUT, in the initial question (see the initial code, please), the EDITBOX is resizable.

Any way please to retain EDITBOX is resizable?
User avatar
Hellbent
Posts: 2114
Joined: 23 Sep 2017, 13:34

Re: GUI window enable/disable Resize Option and Top Bar

27 Oct 2023, 15:04

GEOVAN wrote:
26 Oct 2023, 14:30
Thank you very much.

But, please note that the EDITBOX is NOT resizable in your example.
BUT, in the initial question (see the initial code, please), the EDITBOX is resizable.

Any way please to retain EDITBOX is resizable?
You never mentioned resizing the edit or any of the other controls.

Your question was about getting rid of the border when you use -Caption and +Resize together.
My suggestion was to create your own resize routine so that you don't have to use +Resize thus removing the border.

Here is an example of how you can remove the border and resize the edit control.
It uses the same basic method as used here:
viewtopic.php?f=76&t=119635&p=531550#p530844

.
custom resize 5.gif
custom resize 5.gif (313.86 KiB) Viewed 1150 times
.

Code: Select all

#SingleInstance Force
;<<<>>>
sampleText = 
( 
F2 -> Removes the Menu bar of the GUI

F3 -> Bring back the Menu bar of the GUI

F4 -> Makes the GUI window not resizable

F5 -> Makes the GUI window resizable
)
;<<<>>>
Gui1 					:= {}
;<<<>>>
Gui, New, +AlwaysOnTop +HwndHwnd

Gui1.Hwnd 				:= hwnd
;<<<>>>
Gui1.Margin 			:= 10
Gui, % Gui1.Hwnd ":Margin", % Gui1.Margin , % Gui1.Margin
;<<<>>>
Gui1.FontColor			:= "Black"
Gui1.FontSize			:= 8
Gui1.FontType			:= "Segoe UI"
Gui1.FontOptions		:= ""
SetFont( Gui1 )
;<<<>>>
Gui1.Controls 			:= {}
Gui1.Controls.InfoText 	:= CreateControl( Gui1.Hwnd , "Text" , "xm ym w200 r1" , "Info:" )
Gui1.Controls.MainEdit 	:= CreateControl( Gui1.Hwnd , "Edit" , "xm y+m w200 h200 " , sampleText )
;<<<>>> Set min width and height
DetectHiddenWindows, On
Gui, % Gui1.Hwnd ":-Caption"
Gui, % Gui1.Hwnd ":Show", AutoSize Hide 
WinGetPos,,, w , h , % "ahk_id " Gui1.Hwnd 
Gui1.MinWidth 			:= w
Gui1.MinHeight			:= h
Gui, % Gui1.Hwnd ":+Caption"
;<<<>>> set trigger radius
Gui1.TriggerRadius 		:= 20
;<<<>>> ;set modes
Gui1.ResizeMode 		:= true
Gui1.CaptionMode		:= true
;<<<>>> set focused control
GuiControl, % Gui1.Hwnd ":Focus" , static1
;<<<>>> show the window
Gui, % Gui1.Hwnd ":Show", AutoSize
;<<<>>> monitor left mouse clicks
OnMessage( 0x201 , func( "ClickEvent" ).Bind( Gui1 ) )
;<<<>>>
return ;<<<--- End Of Auto-Execute Section
;<<<>>> Exit Routine (temp)
GuiClose:
GuiContextMenu:
*ESC::ExitApp
;******************
F2::	;{	;remove caption
	Gui, % Gui1.Hwnd ":-Caption"
	Gui1.CaptionMode := false
	Gui, % Gui1.Hwnd ":Show", AutoSize
	return
;}
F3::	;{	;add caption
	Gui, % Gui1.Hwnd ":+Caption"
	Gui1.CaptionMode := true
	Gui, % Gui1.Hwnd ":Show", AutoSize
	return
;}
F4::	;{	;turn off resize
	Gui1.ResizeMode := false
	return
;}
F5::	;{	;turn on resize
	Gui1.ResizeMode := true
	return
;}
;******************
ClickEvent( Gui1 ){ ;When you left click on the window.
	
	;set the coordmode to be relative to the active window
	CoordMode, Mouse, Window
	
	;get the current position and the hwnd of the window under the cursor
	MouseGetPos, x , y , win 
	
	if( win != Gui1.Hwnd || !Gui1.ResizeMode ) ;do nothing if the window clicked isn't the right window or if resize mode is turned off
		return 
	
	;create a vector object for the cursor position ( accounting for dpi scaling *Don't recall if this needs to be done for the trigger vector or not* ) 
	MouseVector := New Vector( x / ( A_ScreenDPI / 96 ) , y / ( A_ScreenDPI / 96 ) )
	
	;get the size and position of the window
	WinGetPos, wX , wY , w , h , % "ahk_id " Gui1.Hwnd
	
	;create a vector object for the resize trigger
	TriggerVector := New Vector( w , h )
	
	if( MouseVector.Dist( TriggerVector ) <= Gui1.TriggerRadius ){ ;if the distance between the cursor and the edge of the window are less than the resize trigger radius.
		
		;set the coordmode to be relative to the screen
		CoordMode, Mouse, Screen
		
		While( GetKeyState( "LButton" , "P" ) ){ ;while the Left mouse button is pressed
			;get the current cursor position
			MouseGetPos, x , y
			if( x != lx || y != ly ){ ;only update if the cursor moves
				lx := x , ly := y
				
				;get the new width for the edit
				( ( w := x - wX - 2 * Gui1.Margin ) < Gui1.MinWidth - 2 * Gui1.Margin ) ? ( w := Gui1.MinWidth - 2 * Gui1.Margin )
				
				;get the new height for the edit
				( ( h := y - wY - 2 * Gui1.Margin - Gui1.Controls.MainEdit.Y ) < Gui1.MinHeight - 2 * Gui1.Margin - Gui1.Controls.MainEdit.Y ) ? ( h := Gui1.MinHeight - 2 * Gui1.Margin - Gui1.Controls.MainEdit.Y ) 
				
				;set the edit control object with the new width and height
				Gui1.Controls.MainEdit.W := w 
				Gui1.Controls.MainEdit.H := h 
				
				;resize the gui control 
				ReSizeControl( Gui1.Controls.MainEdit )
				
				;auto-size the window to account for the new control sizes
				Gui, % Gui1.Hwnd ":Show", AutoSize
			}
			
			;slow the process down a bit.
			sleep, 30
		}
	}
	
}
;******************
SetFont( winObj ){
	Gui, % winObj.Hwnd ":Font", % "s" winObj.FontSize " c" winObj.FontColor " " winObj.FontOptions , % winObj.FontType
}
;******************
CreateControl( WinHwnd , ControlType := "Text" , Options := "" , Value := "" ){
	Gui, % WinHwnd ":Add" , % ControlType , % Options " +HwndHwnd" , % Value
	GuiControlGet, pos , % WinHwnd ":pos" , % hwnd
	return { X: posX , Y: posY , W: posW , H: posH , Hwnd: hwnd , Type: ControlType , Parent: WinHwnd }
}
;******************
ReSizeControl( ControlObject ){
	cc := ControlObject
	GuiControl, % cc.Parent ":MoveDraw" , % cc.Hwnd , % "x" cc.X " y" cc.Y " w" cc.W " h" cc.H 
}
;******************
Class Vector	{
	__New( x := 0 , y := 0 ){ 
		This.X := X
		This.Y := Y
	}
	Dist( x , y := "" ){
		if( IsObject( x ) )
			return Sqrt( ( ( This.X - x.X ) **2 ) + ( ( This.Y - x.Y ) **2 ) )
		else 
			return Sqrt( ( ( This.X - X ) **2 ) + ( ( This.Y - Y ) **2 ) )
	}
}
;******************

GEOVAN
Posts: 192
Joined: 03 Mar 2022, 11:12

Re: GUI window enable/disable Resize Option and Top Bar

28 Oct 2023, 00:41

Not exactly what i need, because the resize with the mouse is difficult - actually it can not be resized.... i do not know why.
Also toggle between border and not border change window gui size which i do not want to change it - please see my initial comment.
But anyway, Thank you very much for trying to help me.
User avatar
Hellbent
Posts: 2114
Joined: 23 Sep 2017, 13:34

Re: GUI window enable/disable Resize Option and Top Bar

28 Oct 2023, 15:36

GEOVAN wrote:
28 Oct 2023, 00:41
Not exactly what i need, because the resize with the mouse is difficult
The way I showed is just one method of doing it, another method is to use a control or general rectangle to trigger resizing.

.
Image
.

.
resize.gif
resize.gif (166.68 KiB) Viewed 1098 times
.
- actually it can not be resized.... i do not know why.
Change the size of the trigger radius. Gui1.TriggerRadius := 20
Also toggle between border and not border change window gui size which i do not want to change it
The way I have that last version is that it auto sizes when switching between captioned and non-captioned to maintain the same client area (the non caption part of the window).
I don't know why you would want to keep the extra white space but you can skip fixing the margins by not using Gui, % Gui1.Hwnd ":Show", AutoSize

- please see my initial comment.
Your original question was about removing the extra border that you get when you use the +Resize gui option.

i.e.

.
20231028162805.png
20231028162805.png (37.17 KiB) Viewed 1098 times
.

If you don't use +Resize you won't get the extra border.

But anyway, Thank you very much for trying to help me.
No problem, good luck with your project.
GEOVAN
Posts: 192
Joined: 03 Mar 2022, 11:12

Re: GUI window enable/disable Resize Option and Top Bar

29 Oct 2023, 00:55

Thank you very much!!!

Please let me finally ask (just for my knowledge support):

WHAT IS THE REASON that when use +Resize an extra border occurs as shown in the screenshot below ?
image.png
image.png (37.17 KiB) Viewed 906 times

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 177 guests