SLEEP 10 needed at end of ConsoleResizeEx
Scrollbar will sometimes appear.
Added SLEEP 10 at the end of ConsoleResizeEx appears to fix.
Change %TestSleep to 0 or 1 to test.
Scrollbar will sometimes appear.
Added SLEEP 10 at the end of ConsoleResizeEx appears to fix.
Change %TestSleep to 0 or 1 to test.
Code:
#DIM ALL 'InitConsole.bas #INCLUDE "win32api.inc" ' %TestSleep = 0 'Change to 1 to correct problem using SLEEP 10 at end of ConsoleReSizeEX ' UNION WINDOW_SIZE wDw AS DWORD wCo AS COORD END UNION ' FUNCTION PBMAIN AS LONG LOCAL rows,cols AS LONG '0,0 for largest console DO InitConsole rows,cols LOCATE 1,1 ? "Hold down a key." IF %TestSleep THEN ? "SLEEP is now ON which appears to fix scrollar. Please change %TestSleep to 0 to see problem." CON.CAPTION$ = "SLEEP 10. PROBLEM FIXED? ELSE ? "SLEEP is now OFF so scrollbar may appear. Please change %TestSleep to 1 to correct." CON.CAPTION$ = "SLEEP NOT USED" END IF WAITKEY$ LOOP END FUNCTION ' SUB InitConsole(Rows AS LONG, Cols AS LONG) CURSOR OFF CON.LOC = 0,0 IF rows = 0 AND cols = 0 THEN GetMaxConsoleSize Rows,Cols ConsoleResizeEx(Cols,Rows,Cols,Rows) SetWindowLong CONSHNDL, %GWL_STYLE, (GetWindowLong (CONSHNDL, %GWL_STYLE) XOR %WS_THICKFRAME XOR %WS_MAXIMIZEBOX) 'Dave Biggs END SUB ' SUB GetMaxConsoleSize(Rows AS LONG, Cols AS LONG) ' Arie Verheul http://www.powerbasic.com/support/pb...458#post384458 LOCAL WindowSize AS DWORD WindowSize = GetLargestConsoleWindowSize (GETSTDOUT) Rows = HI(WORD, WindowSize) Cols = LO(WORD, WindowSize) ''- 1 ' Column count seems to be rounded upwards END SUB ' SUB ConsoleResizeEx (OPT BYVAL WColumns??, BYVAL WRows??, BYVAL BColumns??, BYVAL BRows??, BYVAL hBuffer&) ' ' v1.03 by Yuzree Esmera ' Requires Windows 2000 or later, PBCC 5 or later. ' ' Resizes a Screen Buffer and/or it's associated Window according to the ' specified dimensions. ' ' WColumns?? [In, Optional] ' Target width of the Window in character columns. ' Defaults to current Window width if NULL or unspecified. ' ' WRows?? [In, Optional] ' Target height of the Window in character rows. ' Defaults to current Window height if NULL or unspecified. ' ' BColumns?? [In, Optional] ' Target width of the Screen Buffer in character columns. ' Defaults to current Screen Buffer width if NULL or unspecified. ' ' BRows?? [In, Optional] ' Target height of the Screen Buffer in character rows. ' Defaults to current Screen Buffer height if NULL or unspecified. ' ' hBuffer& [In, Optional] ' The handle of the Screen Buffer to resize. ' Defaults to the active Screen Buffer's handle if NULL or unspecified. REGISTER Wx??, Wy??, Bx??, By?? LOCAL CBI AS CONSOLE_SCREEN_BUFFER_INFO 'Unicode support #IF %DEF (%UNICODE) LOCAL zTmp AS WSTRINGZ * 8 #ELSE LOCAL zTmp AS ASCIZ * 8 #ENDIF DO WHILE GetConsoleScreenBufferInfo (BYVAL hBuffer&, BYVAL VARPTR(CBI)) = 0& 'Exit if already tried &adiv>mp; still unsuccessful IF LEN(zTmp) THEN EXIT SUB 'hBuffer& is likely invalid; open handle to active Screen Buffer zTmp = "CONOUT$" hBuffer& = CreateFile (BYVAL VARPTR(zTmp), _ BYVAL %GENERIC_READ OR %GENERIC_WRITE, _ BYVAL %FILE_SHARE_WRITE, BYVAL 0&, _ BYVAL %OPEN_EXISTING, BYVAL 0&, BYVAL 0&) LOOP 'Get maximum width & height possible (discounting Screen Buffer) POKE DWORD, VARPTR(CBI.dwMaximumWindowSize), GetLargestConsoleWindowSize (BYVAL hBuffer&) 'Initialize working variables Wx?? = IIF&(WColumns??, WColumns??, CBI.srWindow.xRight - CBI.srWindow.xLeft + 1??) Wy?? = IIF&(WRows??, WRows??, CBI.srWindow.xBottom - CBI.srWindow.xTop + 1??) Bx?? = IIF&(BColumns??, BColumns??, MAX&(CBI.dwSize.X, Wx??)) By?? = IIF&(BRows??, BRows??, MAX&(CBI.dwSize.Y, Wy??)) 'Limit target Window dimensions to lowest of target, Screen Buffer or max possible Wx?? = MIN&(Wx??, Bx??, CBI.dwMaximumWindowSize.X) Wy?? = MIN&(Wy??, By??, CBI.dwMaximumWindowSize.Y) 'Resize Window to smallest possible RESET CBI SetConsoleWindowInfo (BYVAL hBuffer&, BYVAL 1&, BYVAL VARPTR(CBI.srWindow)) 'Resize Screen Buffer to target dimensions CBI.dwSize.X = Bx?? CBI.dwSize.Y = By?? SetConsoleScreenBufferSize (BYVAL hBuffer&, BYVAL PEEK(DWORD, VARPTR(CBI.dwSize))) 'Resize Window to target dimensions CBI.srWindow.xRight = Wx?? - 1?? CBI.SrWindow.xBottom = Wy?? - 1?? SetConsoleWindowInfo (BYVAL hBuffer&, BYVAL 1&, BYVAL VARPTR(CBI.srWindow)) 'Cleanup IF LEN(zTmp) THEN CloseHandle (hBuffer&) #IF %TestSleep SLEEP 10 'required or scrollbars may appear #ENDIF END SUB
Comment