Manually resizing with $RESIZE:ON
#1
As I posted in a different thread in the Help area, I thought I'd go ahead and share these two demos here to help preserve them for the future.

Demo 1 here is an example of how to use $RESIZE:ON to adjust your program's width and height, without adjusting the fontsize or scale.  This works basically like the IDE does, and resizes the number of rows and columns which you have available for use with the program:

Code: (Select All)
$Resize:On
activeScreen = _NewImage(80, 25, 0) 'standard screen 0
Screen activeScreen

DrawBorder
_Delay .25
clearInitialResize = _Resize 'clear thr size change from where QB64 first starts up

Do
    If _Resize Then
        tempScreen = _NewImage(_ResizeWidth \ _FontWidth, _ResizeHeight \ _FontHeight, 0)
        Screen tempScreen
        _FreeImage activeScreen
        activeScreen = tempScreen
        DrawBorder
    End If
Loop Until _KeyHit
System

Sub DrawBorder
    Color 4
    For x = 1 To _Width
        Locate 1, x: Print Chr$(219);
        Locate _Height, x: Print Chr$(219);
    Next
    For y = 1 To _Height
        Locate y, 1: Print Chr$(219);
        Locate y, _Width: Print Chr$(219);
    Next
    Color 15
    Locate _Height \ 2, _Width \ 2 - 12: Print "Resize On, Non-Scale Demo"
    Locate _Height \ 2 + 2, 3: Print "Width:"; _Width
    Locate _Height \ 2 + 3, 3: Print "Height:"; _Height
End Sub



Demo 2 here works in a very similar manner, except it uses two screens.  The activeScreen always remains the same size -- 640 x 400 pixels, in this case, and the viewScreen changes size and scales the image on the screen to suit whatever size we expand it to:

Code: (Select All)
$Resize:On
activeScreen = _NewImage(640, 400, 256) '256 color screen so we can use _PUTIMAGE for scaling
viewScreen = _NewImage(640, 400, 256) 'a second screen to scale to
Screen viewScreen
_Dest activeScreen: _Source activeScreen

DrawBorder
_Delay .25
clearInitialResize = _Resize 'clear thr size change from where QB64 first starts up

Do
    If _Resize Then
        tempScreen = _NewImage(_ResizeWidth, _ResizeHeight, 256)
        Screen tempScreen
        _FreeImage viewScreen
        viewScreen = tempScreen
    End If
    _PutImage , activeScreen, viewScreen
    _Limit 30
Loop Until _KeyHit
System

Sub DrawBorder
    Color 4
    For x = 1 To _Width \ _FontWidth
        Locate 1, x: Print Chr$(219);
        Locate _Height \ _FontHeight, x: Print Chr$(219);
    Next
    For y = 1 To _Height \ _FontHeight
        Locate y, 1: Print Chr$(219);
        Locate y, _Width \ _FontWidth: Print Chr$(219);
    Next
    Color 15
    Locate 3, 3: Print "Resize On, Scale-Size Demo"
    Locate 5, 3: Print "Width:"; _Width
    Locate 6, 3: Print "Height:"; _Height
End Sub


Note that neither of these demos maintain aspect ratio, so images may stretch or skew depending on how you resize them.  If this isn't your desired effect, then you'd have to adjust for that inside the program with a few IF statements manually.  Wink
Reply
#2
nice job
Reply
#3
$RESIZE requires the Windows title bar is present. This demo will show how $RESIZE:ON is suspended when we start the program without a title bar using Win32 API commands.

Code: (Select All)
$RESIZE:ON
DECLARE DYNAMIC LIBRARY "user32"
    FUNCTION GetWindowLongA& (BYVAL hwnd AS LONG, BYVAL nIndex AS LONG)
    FUNCTION SetWindowLongA& (BYVAL hwnd AS LONG, BYVAL nIndex AS LONG, BYVAL dwNewLong AS LONG)
    FUNCTION SetWindowPos& (BYVAL hwnd AS LONG, BYVAL hWndInsertAfter AS LONG, BYVAL x AS LONG, BYVAL y AS LONG, BYVAL cx AS LONG, BYVAL cy AS LONG, BYVAL wFlags AS LONG)
END DECLARE
DIM hWnd AS LONG
hWnd = _WINDOWHANDLE
_DELAY .1
GWL_STYLE = -16
ws_border = &H800000
WS_VISIBLE = &H10000000
DO
    winstyle& = GetWindowLongA&(hWnd, GWL_STYLE)
LOOP UNTIL winstyle&
DO
    a& = SetWindowLongA&(hWnd, GWL_STYLE, winstyle& AND WS_VISIBLE)
LOOP UNTIL a&
a& = SetWindowPos&(hWnd&, 0, 0, 0, 0, 0, 39) ' Required to allow printing where title bar used to be.
_DELAY .1
CLS: LOCATE 2, 1: PRINT " Try to resize. You can't. Now press a key to restore title bar and retry!"

DO
    _LIMIT 30
    b$ = INKEY$
    IF LEN(b$) THEN
        IF b$ = CHR$(27) THEN END
        ' Restore title bar.
        a& = SetWindowLongA&(hWnd, GWL_STYLE, winstyle& OR ws_border)
        a& = SetWindowPos&(hWnd&, 0, 0, 0, 0, 0, 39)
        CLS: _DELAY .75
        LOCATE 2, 1: PRINT " Okay. Now you can resize the window with a mouse drag."
    END IF
LOOP

Pete
Reply
#4
You've taken too many options out of your window flags...

Code: (Select All)
$Resize:On
Declare Dynamic Library "user32"
    Function GetWindowLongA& (ByVal hwnd As Long, Byval nIndex As Long)
    Function SetWindowLongA& (ByVal hwnd As Long, Byval nIndex As Long, Byval dwNewLong As Long)
    Function SetWindowPos& (ByVal hwnd As Long, Byval hWndInsertAfter As Long, Byval x As Long, Byval y As Long, Byval cx As Long, Byval cy As Long, Byval wFlags As Long)
End Declare
Dim hWnd As Long
hWnd = _WindowHandle
_Delay .1
GWL_STYLE = -16
ws_sizebox = &H40000
ws_border = &H800000
WS_VISIBLE = &H10000000
Do
    winstyle& = GetWindowLongA&(hWnd, GWL_STYLE)
Loop Until winstyle&
Do
    a& = SetWindowLongA&(hWnd, GWL_STYLE, winstyle& And WS_VISIBLE Or ws_sizebox)
Loop Until a&
a& = SetWindowPos&(hWnd&, 0, 0, 0, 0, 0, 39) ' Required to allow printing where title bar used to be.
_Delay .1
Cls: Locate 2, 1: Print " Try to resize. You can't. Now press a key to restore title bar and retry!"

Do
    _Limit 30
    b$ = InKey$
    If Len(b$) Then
        If b$ = Chr$(27) Then End
        ' Restore title bar.
        a& = SetWindowLongA&(hWnd, GWL_STYLE, winstyle& Or ws_border)
        a& = SetWindowPos&(hWnd&, 0, 0, 0, 0, 0, 39)
        Cls: _Delay .75
        Locate 2, 1: Print " Okay. Now you can resize the window with a mouse drag."
    End If
Loop


You've got to have a border of some sort where the user can grab to drag and resize...  I've did this before, and not had the gap up top where the window title is missing, but I'm not certain now which flag that was that needed toggling.
Reply
#5
Just the thread I needed to see.  I started playing with RESIZE yesterday with an image program.   Nice to see these examples to help understand how to use it.

- Dav

Find my programs here in Dav's QB64 Corner
Reply
#6
That restored the ability to resize the window, but we now have another prime contestant for the 3rd Annual Bud Tugly Award.

Code: (Select All)
$RESIZE:ON
DECLARE DYNAMIC LIBRARY "user32"
    FUNCTION GetWindowLongA& (BYVAL hwnd AS LONG, BYVAL nIndex AS LONG)
    FUNCTION SetWindowLongA& (BYVAL hwnd AS LONG, BYVAL nIndex AS LONG, BYVAL dwNewLong AS LONG)
    FUNCTION SetWindowPos& (BYVAL hwnd AS LONG, BYVAL hWndInsertAfter AS LONG, BYVAL x AS LONG, BYVAL y AS LONG, BYVAL cx AS LONG, BYVAL cy AS LONG, BYVAL wFlags AS LONG)
END DECLARE
DIM hWnd AS LONG
hWnd = _WINDOWHANDLE
_DELAY .1
GWL_STYLE = -16
WS_SIZEBOX = &H40000 ' Same as WS_THICKBORDER = &H40000
WS_POPUP = &H4800000 ' Can be used to make a razor thin border but is not resizable.
ws_border = &H800000
WS_VISIBLE = &H10000000
DO
    winstyle& = GetWindowLongA&(hWnd, GWL_STYLE)
LOOP UNTIL winstyle&
DO
    a& = SetWindowLongA&(hWnd, GWL_STYLE, winstyle& AND WS_VISIBLE OR WS_SIZEBOX)
LOOP UNTIL a&
a& = SetWindowPos&(hWnd&, 0, 0, 0, 0, 0, 39) ' Required to allow printing where title bar used to be.
_DELAY .1

PALETTE 7, 63
COLOR 0, 7
VIEW PRINT: CLS: LOCATE 2, 1: PRINT " Try to resize. You can't. Now press a key to restore title bar and retry!"

DO
    _LIMIT 30
    b$ = INKEY$
    IF LEN(b$) THEN
        IF b$ = CHR$(27) THEN END
        ' Restore title bar.
        a& = SetWindowLongA&(hWnd, GWL_STYLE, winstyle& OR ws_border)
        a& = SetWindowPos&(hWnd&, 0, 0, 0, 0, 0, 39)
        CLS: _DELAY .75
        LOCATE 2, 1: PRINT " Okay. Now you can resize the window with a mouse drag."
    END IF
LOOP

Interesting that the thickbrder properties do not completely vanish when the title bar style is brought back. See black border on right and bottom.

The only solution to the ugly divided color situation might be to figure out the method Windows goes about to paint the window background and see if painting the window background white would completely cover the black space.

Pete
If eggs are brain food, Biden takes his scrambled.
Reply
#7
@Pete

Code: (Select All)
$Resize:On
Declare Dynamic Library "user32"
    Function GetWindowLongA& (ByVal hwnd As Long, Byval nIndex As Long)
    Function SetWindowLongA& (ByVal hwnd As Long, Byval nIndex As Long, Byval dwNewLong As Long)
    Function SetWindowPos& (ByVal hwnd As Long, Byval hWndInsertAfter As Long, Byval x As Long, Byval y As Long, Byval cx As Long, Byval cy As Long, Byval wFlags As Long)
End Declare
Dim hWnd As Long
hWnd = _WindowHandle
_Delay .1
GWL_STYLE = -16
WS_SIZEBOX = &H40000 ' Same as WS_THICKBORDER = &H40000
WS_POPUP = &H4800000 ' Can be used to make a razor thin border but is not resizable.
ws_border = &H800000
WS_VISIBLE = &H10000000
WS_CHILD = &H40000000
Do
    winstyle& = GetWindowLongA&(hWnd, GWL_STYLE)
Loop Until winstyle&
Do
    a& = SetWindowLongA&(hWnd, GWL_STYLE, winstyle& And WS_VISIBLE Or WS_SIZEBOX Or WS_CHILD)
Loop Until a&
a& = SetWindowPos&(hWnd&, 0, 0, 0, 0, 0, 39) ' Required to allow printing where title bar used to be.
_Delay .1

Palette 7, 63
Color 0, 7
View Print: Cls: Locate 1, 1: Print " Try to resize. Pete can't, but Steve can! Now press a key to restore title bar and retry!"

Do
    _Limit 30
    b$ = InKey$
    If Len(b$) Then
        If b$ = Chr$(27) Then End
        ' Restore title bar.
        a& = SetWindowLongA&(hWnd, GWL_STYLE, winstyle& Or ws_border)
        a& = SetWindowPos&(hWnd&, 0, 0, 0, 0, 0, 39)
        Cls: _Delay .75
        Locate 2, 1: Print " Okay. Now you can resize the window with a mouse drag."
    End If
Loop
Reply
#8
Unfortunately WS_CHILD does not change the appearance. In fact, it adds an undesirable lack of focus. Run it, bring up the browser full screen then try to click the task bar icon. The window should pop up, right? Wrong. It won't regain focus as a child window. It probably needs instructions to do so. Anyway, since it doesn't make a difference, I tossed it.

So resize is now enabled but that ugly black row is still present. Half way home.


[Image: Screenshot-780.png]


Code: (Select All)
$RESIZE:ON
DECLARE DYNAMIC LIBRARY "user32"
    FUNCTION GetWindowLongA& (BYVAL hwnd AS LONG, BYVAL nIndex AS LONG)
    FUNCTION SetWindowLongA& (BYVAL hwnd AS LONG, BYVAL nIndex AS LONG, BYVAL dwNewLong AS LONG)
    FUNCTION SetWindowPos& (BYVAL hwnd AS LONG, BYVAL hWndInsertAfter AS LONG, BYVAL x AS LONG, BYVAL y AS LONG, BYVAL cx AS LONG, BYVAL cy AS LONG, BYVAL wFlags AS LONG)
END DECLARE
DIM hWnd AS LONG
hWnd = _WINDOWHANDLE
_DELAY .1
GWL_STYLE = -16
WS_SIZEBOX = &H40000 ' Same as WS_THICKBORDER = &H40000
WS_POPUP = &H4800000 ' Can be used to make a razor thin border but is not resizable.
ws_border = &H800000
WS_VISIBLE = &H10000000
WS_CHILD = &H40000000
DO
    winstyle& = GetWindowLongA&(hWnd, GWL_STYLE)
LOOP UNTIL winstyle&
DO
    a& = SetWindowLongA&(hWnd, GWL_STYLE, winstyle& AND WS_VISIBLE OR WS_SIZEBOX)
LOOP UNTIL a&
a& = SetWindowPos&(hWnd&, 0, 0, 0, 0, 0, 39) ' Required to allow printing where title bar used to be.
_DELAY .1

WIDTH 50, 25
PALETTE 7, 63
COLOR 0, 7
VIEW PRINT: CLS: LOCATE 2, 1: PRINT " Resize works, but ugly black row near top."

DO
    _LIMIT 30
    b$ = INKEY$
    IF LEN(b$) THEN
        IF b$ = CHR$(27) THEN END
        ' Restore title bar.
        a& = SetWindowLongA&(hWnd, GWL_STYLE, winstyle& OR ws_border)
        a& = SetWindowPos&(hWnd&, 0, 0, 0, 0, 0, 39)
        CLS: _DELAY .75
        LOCATE 2, 1: PRINT " Okay. Back to normal window again."
    END IF
LOOP

Pete
Reply




Users browsing this thread: 1 Guest(s)