Page 2 of 2

Re: Console resize

Posted: Tue Nov 05, 2024 4:55 pm
by Axolotl
you can do it this way....

Code: Select all

Procedure DisableWindowSizing(hWnd, State) 
  Protected currStyle 

  currStyle = GetWindowLongPtr_(hwnd, #GWL_STYLE)
  If State
    Style = currStyle & ~#WS_SIZEBOX   ; <-- remove style flag #WS_SIZEBOX 
  Else
    Style = currStyle | #WS_SIZEBOX    ; <-- add style flag #WS_SIZEBOX 
  EndIf 
  SetWindowLongPtr_(hWnd, #GWL_STYLE, Style) 
  SetWindowPos_(hWnd, 0, 0, 0, 0, 0, #SWP_NOZORDER | #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)  
EndProcedure 


OpenConsole() 
;ConsoleTitle("Console fixed size")

stdout = GetStdHandle_(#STD_OUTPUT_HANDLE) 

OpenLibrary(0, "kernel32.dll")
hWin = CallFunction(0, "GetConsoleWindow")
CloseLibrary(0)

; ;...Remove the Size option from the menu
; system_menu = GetSystemMenu_(hWin, #False) 
; DeleteMenu_(system_menu, 2, #MF_BYPOSITION) 
; DrawMenuBar_(hWin) 

ConsoleTitle("Console fixed size")
DisableWindowSizing(hWin, #True) 

With windowSize.SMALL_RECT
  \left   =  0 
  \top    =  0 
  \right  = 79 
  \bottom = 24 
EndWith
SetConsoleWindowInfo_(stdout, #True, @windowSize)

With bufferSize.COORD
  \x = 80 
  \y = 25 
EndWith 
SetConsoleScreenBufferSize_(stdout, PeekL(bufferSize))
Repeat 
  in$ = Input() 
  If in$ = "on" 
    ConsoleTitle("Console changeable size")
    DisableWindowSizing(hWin, #False) 
  ElseIf in$ = "off" 
    ConsoleTitle("Console fixed size")
    DisableWindowSizing(hWin, #True) 
  ElseIf in$ = "exit" 
    Break 
  EndIf 
Until in$ = "" 
  
CloseConsole()


Re: Console resize

Posted: Wed Nov 06, 2024 1:57 am
by Armoured
Axolotl wrote: Tue Nov 05, 2024 4:55 pm you can do it this way....

Code: Select all

Procedure DisableWindowSizing(hWnd, State) 
  Protected currStyle 

  currStyle = GetWindowLongPtr_(hwnd, #GWL_STYLE)
  If State
    Style = currStyle & ~#WS_SIZEBOX   ; <-- remove style flag #WS_SIZEBOX 
  Else
    Style = currStyle | #WS_SIZEBOX    ; <-- add style flag #WS_SIZEBOX 
  EndIf 
  SetWindowLongPtr_(hWnd, #GWL_STYLE, Style) 
  SetWindowPos_(hWnd, 0, 0, 0, 0, 0, #SWP_NOZORDER | #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)  
EndProcedure 


OpenConsole() 
;ConsoleTitle("Console fixed size")

stdout = GetStdHandle_(#STD_OUTPUT_HANDLE) 

OpenLibrary(0, "kernel32.dll")
hWin = CallFunction(0, "GetConsoleWindow")
CloseLibrary(0)

; ;...Remove the Size option from the menu
; system_menu = GetSystemMenu_(hWin, #False) 
; DeleteMenu_(system_menu, 2, #MF_BYPOSITION) 
; DrawMenuBar_(hWin) 

ConsoleTitle("Console fixed size")
DisableWindowSizing(hWin, #True) 

With windowSize.SMALL_RECT
  \left   =  0 
  \top    =  0 
  \right  = 79 
  \bottom = 24 
EndWith
SetConsoleWindowInfo_(stdout, #True, @windowSize)

With bufferSize.COORD
  \x = 80 
  \y = 25 
EndWith 
SetConsoleScreenBufferSize_(stdout, PeekL(bufferSize))
Repeat 
  in$ = Input() 
  If in$ = "on" 
    ConsoleTitle("Console changeable size")
    DisableWindowSizing(hWin, #False) 
  ElseIf in$ = "off" 
    ConsoleTitle("Console fixed size")
    DisableWindowSizing(hWin, #True) 
  ElseIf in$ = "exit" 
    Break 
  EndIf 
Until in$ = "" 
  
CloseConsole()

Thanks Axolotl! :)