Page 1 of 1

Gui +Resize - Caption

Posted: 17 Feb 2020, 20:46
by Kanji
Hi everyone, sorry if this question is stupid or this topic has been already debated, but i searched and i didn't find anything :(
I'd like to remove the 6px white border created by the option +resize in the GUI when there's no title bar.
In the spoiler i added an image to let you understand what I'm talking about.
Spoiler

Code: Select all

Gui, -caption +resize MinSize400x200
Gui, Color, 000
Gui, Show, w100 h50, Nome
return

Re: Gui +Resize - Caption

Posted: 17 Feb 2020, 23:50
by scriptor2016

Code: Select all

Gui, margin, -1, -1
Gui, -caption +resize MinSize400x200
Gui, Color, 000
Gui, Show, w100 h50, Nome
return

Re: Gui +Resize - Caption  Topic is solved

Posted: 18 Feb 2020, 00:47
by flyingDman
see here: https://autohotkey.com/board/topic/23969-resizable-window-border/

Code: Select all

OnMessage(0x84, "WM_NCHITTEST")
OnMessage(0x83, "WM_NCCALCSIZE")
gui, color, 000000
Gui, +resize MinSize200x200 maxsize400x400
Gui, Show, w300 h300
return

esc::
exitapp

WM_NCCALCSIZE()
{
    if A_Gui
        return 0    ; Sizes the client area to fill the entire window.
}

; Redefine where the sizing borders are.  This is necessary since
; returning 0 for WM_NCCALCSIZE effectively gives borders zero size.


WM_NCHITTEST(wParam, lParam)
{
    static border_size = 6
    
    if !A_Gui
        return
    
    WinGetPos, gX, gY, gW, gH
    
    x := lParam<<48>>48, y := lParam<<32>>48
    
    hit_left    := x <  gX+border_size
    hit_right   := x >= gX+gW-border_size
    hit_top     := y <  gY+border_size
    hit_bottom  := y >= gY+gH-border_size
    
    if hit_top
    {
        if hit_left
            return 0xD
        else if hit_right
            return 0xE
        else
            return 0xC
    }
    else if hit_bottom
    {
        if hit_left
            return 0x10
        else if hit_right
            return 0x11
        else
            return 0xF
    }
    else if hit_left
        return 0xA
    else if hit_right
        return 0xB
    
    ; else let default hit-testing be done
}

Re: Gui +Resize - Caption

Posted: 18 Feb 2020, 08:23
by Kanji
flyingDman wrote:
18 Feb 2020, 00:47
see here: https://autohotkey.com/board/topic/23969-resizable-window-border/

Code: Select all

OnMessage(0x84, "WM_NCHITTEST")
OnMessage(0x83, "WM_NCCALCSIZE")
gui, color, 000000
Gui, +resize MinSize200x200 maxsize400x400
Gui, Show, w300 h300
return

esc::
exitapp

WM_NCCALCSIZE()
{
    if A_Gui
        return 0    ; Sizes the client area to fill the entire window.
}

; Redefine where the sizing borders are.  This is necessary since
; returning 0 for WM_NCCALCSIZE effectively gives borders zero size.


WM_NCHITTEST(wParam, lParam)
{
    static border_size = 6
    
    if !A_Gui
        return
    
    WinGetPos, gX, gY, gW, gH
    
    x := lParam<<48>>48, y := lParam<<32>>48
    
    hit_left    := x <  gX+border_size
    hit_right   := x >= gX+gW-border_size
    hit_top     := y <  gY+border_size
    hit_bottom  := y >= gY+gH-border_size
    
    if hit_top
    {
        if hit_left
            return 0xD
        else if hit_right
            return 0xE
        else
            return 0xC
    }
    else if hit_bottom
    {
        if hit_left
            return 0x10
        else if hit_right
            return 0x11
        else
            return 0xF
    }
    else if hit_left
        return 0xA
    else if hit_right
        return 0xB
    
    ; else let default hit-testing be done
}
Thank you, this is exactly what i was looking for :)

Re: Gui +Resize - Caption

Posted: 08 Mar 2022, 01:55
by sanmaodo
@flyingDman Thanks a lot, solved my big trouble.

Re: Gui +Resize - Caption

Posted: 01 Jun 2024, 18:46
by GEOVAN
Thank you very much for this solution!!!

Please let me ask:
If i want to toggle between adding top bar, and removing top bar using F1 and F2 as shown in the following example, there is a problem:
Since F2 is applied once, then NEVER F1 functions.
Can you please advice how to solve this?

Code: Select all


F1::
Gui, destroy
gui, color, c33FFA8
Gui, +resize MinSize200x200 maxsize400x400
Gui, Show, w300 h300
Return




F2::
Gui, destroy
OnMessage(0x84, "WM_NCHITTEST")
OnMessage(0x83, "WM_NCCALCSIZE")

gui, color, c33FFA8
Gui, +resize MinSize200x200 maxsize400x400
Gui, Show, w300 h300
Return



esc::
exitapp






WM_NCCALCSIZE()
{
    if A_Gui
        return 0    ; Sizes the client area to fill the entire window.
}

; Redefine where the sizing borders are.  This is necessary since
; returning 0 for WM_NCCALCSIZE effectively gives borders zero size.


WM_NCHITTEST(wParam, lParam)
{
    static border_size = 6
    
    if !A_Gui
        return
    
    WinGetPos, gX, gY, gW, gH
    
    x := lParam<<48>>48, y := lParam<<32>>48
    
    hit_left    := x <  gX+border_size
    hit_right   := x >= gX+gW-border_size
    hit_top     := y <  gY+border_size
    hit_bottom  := y >= gY+gH-border_size
    
    if hit_top
    {
        if hit_left
            return 0xD
        else if hit_right
            return 0xE
        else
            return 0xC
    }
    else if hit_bottom
    {
        if hit_left
            return 0x10
        else if hit_right
            return 0x11
        else
            return 0xF
    }
    else if hit_left
        return 0xA
    else if hit_right
        return 0xB
    
    ; else let default hit-testing be done
}

Re: Gui +Resize - Caption

Posted: 01 Jun 2024, 19:10
by flyingDman
I am not sure what the most effective way of doing this but this seems to work:

Code: Select all

F1::
Gui, destroy
OnMessage(0x84, "WM_NCHITTEST",0)
OnMessage(0x83, "WM_NCCALCSIZE",0)
gui, color, c33FFA8
Gui, +resize MinSize200x200 maxsize400x400
Gui, Show, w300 h300
Return
;etc.
or use a toggle:

Code: Select all

F1::
Gui, destroy
OnMessage(0x84, "WM_NCHITTEST",t := !t)
OnMessage(0x83, "WM_NCCALCSIZE",t)
gui, color, c33FFA8
Gui, +resize MinSize200x200 maxsize400x400
Gui, Show, w300 h300
;etc.
Return

Re: Gui +Resize - Caption

Posted: 02 Jun 2024, 06:15
by GEOVAN
Hello,
Many many thanks for your reply!
It works, but please note the following:

If we apply Gui, -Caption , and then Gui, +Resize as in the following example, there is a thick BORDER added if we click in any area of Desktop outside the GUI (as shown in the screenshot).
Is there a way to avoid this annoying thick BORDER, please? - as shown in the following example:

Please, in order to see the problem:
(1)First click on button 1
(2)Second click on button 2
(3)Third click in any area outside the GUI

Example:

Code: Select all

#NoEnv
#Persistent
#SingleInstance  Ignore

Gui, Margin , 0, 0

Gui, Add, Button, x10 y3 h18 w76  gchbox_3 vBut3, Button 1
Gui, Add, Button, x100 y3 h18 w76  gchbox_4 vBut4, Button 2

Gui, Font, s10
Gui, Add, Text ,  x10 y40 cLime ,  Please, in order to see the problem: `n-------------------------------------------- `n `n(1)First click on button 1 `n  `n(2)Second click on button 2 `n `n(3)Third click in any area outside the GUI

Gui  +Maxsize%A_ScreenWidth%x%A_ScreenHeight% +Minsize250x60 

Gui, -0x30000  ; WS_MINIMIZEBOX := 0x20000, WS_MAXIMIZEBOX := 0x10000    ; no min and no max icons on top menu bar
Gui, color,   c5d5d5d 
Gui, Show ,w300 h300, My Sticky Notes

Return





chbox_3:
T3 := !T3
If (T3)    ; or --> If T3 = 1
  {
Gui, -Caption 
OnMessage(0x84, "WM_NCHITTEST")
OnMessage(0x83, "WM_NCCALCSIZE")

Sleep 10
Gui, +0x30000  ; WS_MINIMIZEBOX := 0x20000, WS_MAXIMIZEBOX := 0x10000    ; add min and max icons on top menu bar
Gui, Show,     , My Sticky Notes
  }

Else
  {
Gui, +Caption 
OnMessage(0x84, "WM_NCHITTEST",0)
OnMessage(0x83, "WM_NCCALCSIZE",0)

Sleep 10
Gui, -0x30000  ; WS_MINIMIZEBOX := 0x20000, WS_MAXIMIZEBOX := 0x10000    ; no min and no max icons on top menu bar
Gui, Show,   , My Sticky Notes
}  
     
Return





chbox_4:
FreezeGui2 := !FreezeGui2

IfEqual,FreezeGui2,1
     {
Gui, +Resize
Sleep 10
Gui, +0x30000  ; WS_MINIMIZEBOX := 0x20000, WS_MAXIMIZEBOX := 0x10000    ; add min and max icons on top menu bar
Gui, Show,  , My Sticky Notes
    }

Else     
    {
Gui, -Resize
Sleep 10
Gui, -0x30000  ; WS_MINIMIZEBOX := 0x20000, WS_MAXIMIZEBOX := 0x10000    ; no min and no max icons on top menu bar
Gui, Show,     , My Sticky Notes
}

Return



GuiClose:
goto ExitAll
Return




ExitAll:
ExitApp





WM_NCCALCSIZE()
{
    if A_Gui
        return 0    ; Sizes the client area to fill the entire window.
}

; Redefine where the sizing borders are.  This is necessary since
; returning 0 for WM_NCCALCSIZE effectively gives borders zero size.


WM_NCHITTEST(wParam, lParam)
{
    static border_size = 6
    
    if !A_Gui
        return
    
    WinGetPos, gX, gY, gW, gH
    
    x := lParam<<48>>48, y := lParam<<32>>48
    
    hit_left    := x <  gX+border_size
    hit_right   := x >= gX+gW-border_size
    hit_top     := y <  gY+border_size
    hit_bottom  := y >= gY+gH-border_size
    
    if hit_top
    {
        if hit_left
            return 0xD
        else if hit_right
            return 0xE
        else
            return 0xC
    }
    else if hit_bottom
    {
        if hit_left
            return 0x10
        else if hit_right
            return 0x11
        else
            return 0xF
    }
    else if hit_left
        return 0xA
    else if hit_right
        return 0xB
    
    ; else let default hit-testing be done
}


Screenshot:
image.png
image.png (155.53 KiB) Viewed 335 times

Re: Gui +Resize - Caption

Posted: 02 Jun 2024, 19:55
by Hellbent
One option is to create your own resize routine.

This only has control areas for top, bottom, left, and right. You can also add the 4 corners for diagonal resizing.
This also doesn't have the code to change the cursor, it can be added by using OnMessage( 0x200 )

.
resize without resize 1.gif
resize without resize 1.gif (118.99 KiB) Viewed 238 times
.

Code: Select all

#SingleInstance, Force
;****************************************
Gui1 := {}
Gui1.W := 300
Gui1.H := 200
UpdateResizeControlAreas( Gui1 )
Gui1.MinWidth := 250
Gui1.MinHeight := 60
;****************************************
Gui, +AlwaysOnTop +hwndhwnd -Caption
Gui1.Hwnd := hwnd
Gui, Color, 123456
Gui, Show, % "hide w" Gui1.W " h" Gui1.H " NA"
pos := GetWinPos( Gui1.Hwnd )
Gui1.X := pos.X
Gui1.Y := pos.Y
Gui, Show, % "x" Gui1.X " y" Gui1.Y " w" Gui1.W " h" Gui1.H " NA"
;****************************************
OnMessage( 0x201 , Func( "WindowClick" ).Bind( Gui1 ) )
;****************************************
return
GuiClose:
GuiContextMenu:
*ESC::ExitApp
;****************************************
WindowClick( Gui1 , w , l , msg , hwnd ){
	if( hwnd != Gui1.Hwnd )
		return
	CoordMode, Mouse, Client
	MouseGetPos, x , y 
	CoordMode, Mouse, Screen
	for k , v in Gui1.ResizeControls	{
		cc := Gui1.ResizeControls[ k ]
		if( PointInRect( x , y , cc ) ){
			pos := GetWinPos( Gui1.Hwnd )
			ox := pos.X + pos.W
			oy := pos.Y + pos.H
			Gui1.X := pos.X
			Gui1.Y := pos.Y
			While( GetKeyState( "LButton" , "P" ) ){
				MouseGetPos, x , y
				if( k = "Bottom" ){
					( ( Gui1.H := y - pos.y ) < Gui1.MinHeight ) ? ( Gui1.H := Gui1.MinHeight )
				}else if( k = "Right" ){
					( ( Gui1.W := x - pos.x ) < Gui1.MinWidth ) ? ( Gui1.W := Gui1.MinWidth )
				}else if( k = "Left" ){
					Gui1.W := Gui1.W + ( Gui1.X - x )
					if( Gui1.W <= Gui1.MinWidth ){
						Gui1.W := Gui1.MinWidth
						Gui1.X := ox - Gui1.MinWidth
					}else{
						Gui1.X := x
					}
				}else if( k = "Top" ){
					Gui1.H := Gui1.H + ( Gui1.Y - y )
					if( Gui1.H <= Gui1.MinHeight ){
						Gui1.H := Gui1.MinHeight
						Gui1.Y := oy - Gui1.MinHeight
					}else{
						Gui1.Y := y
					}
				}
				UpdateResizeControlAreas( Gui1 )
				Gui, Show, % "x" Gui1.X " y" Gui1.Y " w" Gui1.W " h" Gui1.H " NA"
				sleep, 30
			}
			return 0
		}
	}
}
;****************************************
PointInRect( x , y , rect ){
	if( x >= rect.X && x <= rect.X + rect.W && y >= rect.Y && y <= rect.Y + rect.H )
		return 1
	return 0
}
;****************************************
GetWinPos( hwnd ){
	local x , y , w , h
	WinGetPos, x , y , w , h , % "ahk_id " hwnd
	return { X: x , Y: y , W: w , H: h }
}
;****************************************
UpdateResizeControlAreas( Gui1 , Depth := 10 ){
	local cc := Gui1.ResizeControls := {}
	cc.Left := { X: 0 , Y: 0 , W: Depth , H: Gui1.H }
	cc.Top := { X: 0 , Y: 0 , W: Gui1.W , H: Depth }
	cc.Right := { X: Gui1.W - Depth , Y: 0 , W: Depth , H: Gui1.H }
	cc.Bottom := { X: 0 , Y: Gui1.H - Depth , W: Gui1.W , H: Depth }
}
;****************************************


Re: Gui +Resize - Caption

Posted: 03 Jun 2024, 10:22
by GEOVAN
Hello,
Thanks but actually i need the TOGGLE as @flyingDman solution, i want to TOGGLE as the simple following example:

Example:

Code: Select all

#NoEnv
#Persistent
#SingleInstance  Ignore

Gui, Margin , 0, 0

Gui, Add, Button, x10 y3 h18 w76  gchbox_1 vBut1, Button 1


Gui, Font, s10
Gui, Add, Text ,  x10 y40 cLime ,  Please, in order to see the problem: `n-------------------------------------------- `n `nToggle button 1 few times `n you will see the `nwindow size `nincreases all the time....


Gui  +Maxsize%A_ScreenWidth%x%A_ScreenHeight% +Minsize250x60 


Gui, color,   c5d5d5d 
Gui, Show ,w300 h300, My Sticky Notes

Return





chbox_1:

T1 := !T1

If (T1)    ; or --> If T1 = 1
  {

OnMessage(0x84, "WM_NCHITTEST")
OnMessage(0x83, "WM_NCCALCSIZE")
 
Gui, +Resize
Gui, Show,    , My Sticky Notes
  }



Else
  {

OnMessage(0x84, "WM_NCHITTEST",0)
OnMessage(0x83, "WM_NCCALCSIZE",0)

Gui, -Resize
Gui, Show,  , My Sticky Notes
}  
     
Return





GuiClose:
goto ExitAll
Return




ExitAll:
ExitApp





WM_NCCALCSIZE()
{
    if A_Gui
        return 0    ; Sizes the client area to fill the entire window.
}

; Redefine where the sizing borders are.  This is necessary since
; returning 0 for WM_NCCALCSIZE effectively gives borders zero size.


WM_NCHITTEST(wParam, lParam)
{
    static border_size = 6
    
    if !A_Gui
        return
    
    WinGetPos, gX, gY, gW, gH
    
    x := lParam<<48>>48, y := lParam<<32>>48
    
    hit_left    := x <  gX+border_size
    hit_right   := x >= gX+gW-border_size
    hit_top     := y <  gY+border_size
    hit_bottom  := y >= gY+gH-border_size
    
    if hit_top
    {
        if hit_left
            return 0xD
        else if hit_right
            return 0xE
        else
            return 0xC
    }
    else if hit_bottom
    {
        if hit_left
            return 0x10
        else if hit_right
            return 0x11
        else
            return 0xF
    }
    else if hit_left
        return 0xA
    else if hit_right
        return 0xB
    
    ; else let default hit-testing be done
}
Unfortunately using the above example - by toggle the "button 1", it do the job, but with the following error:
In every "button 1" CLICK ----> the result is that the GUI window size INCREASES and INCREASES and INCREASES and so on......
Please, how can we avoid this strange phenomenon, please?

Re: Gui +Resize - Caption

Posted: 03 Jun 2024, 12:14
by Hellbent
GEOVAN wrote:
Yesterday, 10:22
Hello,
Thanks but actually i need the TOGGLE as @flyingDman solution, i want to TOGGLE as the simple following example:
The toggle is simple to add. Just need to track two variables, one for the caption state and the other for the resize state

.
resize without resize 2.gif
resize without resize 2.gif (279.29 KiB) Viewed 135 times
.

Code: Select all

#SingleInstance, Force
;****************************************
Gui1 := {}
Gui1.W := 300
Gui1.H := 200
UpdateResizeControlAreas( Gui1 )
Gui1.MinWidth := 250
Gui1.MinHeight := 60
Gui1.CaptionState := 1
Gui1.ResizeState := 0
;****************************************
Gui, +AlwaysOnTop +hwndhwnd -Caption
Gui1.Hwnd := hwnd
Gui, Color, 123456
Gui, Add, Button, xm gToggleCaption, Toggle Caption
Gui, Add, Button, xm gToggleResize, Toggle Resize

Gui, Show, % "hide w" Gui1.W " h" Gui1.H " NA"
pos := GetWinPos( Gui1.Hwnd )
Gui1.X := pos.X
Gui1.Y := pos.Y
Gui, Show, % "x" Gui1.X " y" Gui1.Y " w" Gui1.W " h" Gui1.H " NA"
Gui, +Caption
;****************************************
OnMessage( 0x201 , Func( "WindowClick" ).Bind( Gui1 ) )
;****************************************
return
GuiClose:
GuiContextMenu:
*ESC::ExitApp
;****************************************
ToggleCaption:
	if( Gui1.CaptionState := !Gui1.CaptionState ){
		Gui, +Caption
		Gui1.ResizeState := 0
	}else{
		Gui, -Caption
	}
	return
;****************************************
ToggleResize:
	if( !Gui1.CaptionState )
		Gui1.ResizeState := !Gui1.ResizeState
	return
;****************************************
WindowClick( Gui1 , w , l , msg , hwnd ){
	if( hwnd != Gui1.Hwnd || !Gui1.ResizeState )
		return
	CoordMode, Mouse, Client
	MouseGetPos, x , y 
	CoordMode, Mouse, Screen
	for k , v in Gui1.ResizeControls	{
		cc := Gui1.ResizeControls[ k ]
		if( PointInRect( x , y , cc ) ){
			pos := GetWinPos( Gui1.Hwnd )
			ox := pos.X + pos.W
			oy := pos.Y + pos.H
			Gui1.X := pos.X
			Gui1.Y := pos.Y
			While( GetKeyState( "LButton" , "P" ) ){
				MouseGetPos, x , y
				if( k = "Bottom" ){
					( ( Gui1.H := y - pos.y ) < Gui1.MinHeight ) ? ( Gui1.H := Gui1.MinHeight )
				}else if( k = "Right" ){
					( ( Gui1.W := x - pos.x ) < Gui1.MinWidth ) ? ( Gui1.W := Gui1.MinWidth )
				}else if( k = "Left" ){
					Gui1.W := Gui1.W + ( Gui1.X - x )
					if( Gui1.W <= Gui1.MinWidth ){
						Gui1.W := Gui1.MinWidth
						Gui1.X := ox - Gui1.MinWidth
					}else{
						Gui1.X := x
					}
				}else if( k = "Top" ){
					Gui1.H := Gui1.H + ( Gui1.Y - y )
					if( Gui1.H <= Gui1.MinHeight ){
						Gui1.H := Gui1.MinHeight
						Gui1.Y := oy - Gui1.MinHeight
					}else{
						Gui1.Y := y
					}
				}
				UpdateResizeControlAreas( Gui1 )
				Gui, Show, % "x" Gui1.X " y" Gui1.Y " w" Gui1.W " h" Gui1.H " NA"
				sleep, 30
			}
			return 0
		}
	}
}
;****************************************
PointInRect( x , y , rect ){
	if( x >= rect.X && x <= rect.X + rect.W && y >= rect.Y && y <= rect.Y + rect.H )
		return 1
	return 0
}
;****************************************
GetWinPos( hwnd ){
	local x , y , w , h
	WinGetPos, x , y , w , h , % "ahk_id " hwnd
	return { X: x , Y: y , W: w , H: h }
}
;****************************************
UpdateResizeControlAreas( Gui1 , Depth := 10 ){
	local cc := Gui1.ResizeControls := {}
	cc.Left := { X: 0 , Y: 0 , W: Depth , H: Gui1.H }
	cc.Top := { X: 0 , Y: 0 , W: Gui1.W , H: Depth }
	cc.Right := { X: Gui1.W - Depth , Y: 0 , W: Depth , H: Gui1.H }
	cc.Bottom := { X: 0 , Y: Gui1.H - Depth , W: Gui1.W , H: Depth }
}
;****************************************


Re: Gui +Resize - Caption

Posted: 03 Jun 2024, 12:41
by GEOVAN
Thank you very much @Hellbent for your suggestions, but i prefer the method of @flyingDman , because with your method the RESIZE is difficult, because there are no RESIZE ARROWS shown and also there is no resize at corners and at the bottom and at the right of the GUI.

But many thanks for trying to help me, i appreciate very much your help.

I will wait if @flyingDman, has any solution of the problem described in my previous post:
In every "button 1" CLICK ----> the result is that the GUI window size INCREASES and INCREASES and INCREASES and so on......
Please, how can we avoid this strange phenomenon, please?

Re: Gui +Resize - Caption

Posted: 03 Jun 2024, 12:54
by Hellbent
If you aren't able to fix your issue you can add the corners the same way as the "top", "left", etc. are added

In the function that creates the resize rectangles you add "topleft", "topright", etc.
You change the old values from something like { X: 0 , W: Gui1.W } to { X: depth , W: Gui1.W - 2 * depth }.
Your corners would look something like this.

Code: Select all


cc.TopLeft := { X: 0 , Y: 0 , W: depth , H: depth }
cc.BottomRight := { X: Gui1.W - depth , Y: Gui1.H - depth , W: depth , H: depth }

Other than that you just add the 4 new direction to the click function with each being a combo of adjusting the x/y, w/h together.

Good luck with your project.