Announcement

Collapse
No announcement yet.

Console SET SCREEN fix and CPRINT update

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    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.

    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
    How long is an idea?

    Comment


    • #22
      If you can't get the console "window" - I put 'window' in quotes deliberately because I've never found console "windows" to behave like "real" windows - to do what you want it to do, you might find it convenient to eschew the use of the 'console console' and use a 'real window console' like this one...
      Use Listview control as a console. September 13 2003.
      .. or even use a 'real window window' created with CreateWindowEx() or one of the Windows' 'dialog' functions.

      e.g. this program here, compiles and runs 'as is' using either PB/Windows or PB/CC of the generation noted..
      Directory List with Non-ASCII (Unicode) characters in file names 5-31-08

      (Yes, that program is obsolete for anyone using PB/CC 6 or PB/Win 10, which include 'native' wide character string handling).

      MCM
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #23
        Thank you. I will check them out.
        I wanted something that always works if I should ever size a console.
        The PB SET CONSOLE simply doesn't work in all situations.
        How long is an idea?

        Comment


        • #24
          You're welcome Mike!
          Code:
          SUB Init
            LOCAL Rows,Cols,ncW,ncH AS LONG
            Rem DisableX
            CURSOR OFF
            CON.LOC = 0,0
            CON.CAPTION$ = "Largest console"
            GetMaxConsoleSize Rows,Cols
            ConsoleResizeEx(Cols,Rows,Cols,Rows)
            SetWindowLong CONSHNDL, %GWL_STYLE, (GetWindowLong (CONSHNDL, %GWL_STYLE) XOR %WS_THICKFRAME XOR %WS_MAXIMIZEBOX)
            DESKTOP GET SIZE TO ncW, ncH
            CON.LOC = (ncW-CON.SIZE.X)\2,(ncH-CON.SIZE.Y)\2       ' Center on screen
            PrintCenter " Rgds, Dave Biggs!",79
          END SUB
          Rgds, Dave

          Comment


          • #25
            Originally posted by Dave Biggs View Post
            You're welcome Mike!
            Code:
            SUB Init
              LOCAL Rows,Cols,ncW,ncH AS LONG
              Rem DisableX
              CURSOR OFF
              CON.LOC = 0,0
              CON.CAPTION$ = "Largest console"
              GetMaxConsoleSize Rows,Cols
              ConsoleResizeEx(Cols,Rows,Cols,Rows)
              SetWindowLong CONSHNDL, %GWL_STYLE, (GetWindowLong (CONSHNDL, %GWL_STYLE) XOR %WS_THICKFRAME XOR %WS_MAXIMIZEBOX)
              DESKTOP GET SIZE TO ncW, ncH
              CON.LOC = (ncW-CON.SIZE.X)\2,(ncH-CON.SIZE.Y)\2       ' Center on screen
              PrintCenter " Rgds, Dave Biggs!",79
            END SUB
            Hi Dave.
            In PBCC5 legacy code what happen to CON.LOC and CON.CAPTION$?
            CONSOLE SET LOC x&, y& should be the father of CON.LOC, what about
            CON.CAPTION$? Has it got a father too? Or it is necessary to resort to
            an API?
            Last edited by salvatore renda; 28 Jan 2013, 10:44 PM.

            Comment


            • #26
              Online manual:
              http://www.powerbasic.com/support/help/pbcc/index.htm
              How long is an idea?

              Comment


              • #27
                Originally posted by Mike Doty View Post
                Thanks, I found something:
                Legacy Syntax
                CONSOLE NAME StrgExpr
                Now the conversion to PBCC5 is doable.

                Comment


                • #28
                  I've posted a modifiied, faster version of CPrint:

                  Fast Print on console

                  Comment

                  Working...
                  X