Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extended message box
#1
Lightbulb 
How difficult would it be to create a "deluxe" edition of the Message Box which supports a large amount of text? What I mean is, an "OK" button, and a text field with scrollbars that could hold reasonably a larger amount of text than an ordinary Message Box. Take for instance the dialog seen in many Windows installers, to display the License Agreement, and usually has two buttons: "I agree" or "I decline".  Just offer the one button to get out of the dialog.

It would be a good alternative to the "SCREEN 0" to show more stuff that could fit on that screen. The problem could be how large to make the window and the scrollable text holder.

Code: (Select All)
/------------------------------------------------\
| +-----------------------------------+          |
| |This is an example of text.       ^|          |
| |                                  I|  +-----+ |
| |                                  I|  | OK  | |
| |                                  I|  +-----+ |
| |                                  I|          |
| |<================================>V|          |
| +-----------------------------------+          |
\------------------------------------------------/

I have taken the idea from the Purebasic Code Archive, which used WinAPI, and created a version of it with Autohotkey. It should be doable with TinyFileDialog library. Of course, this is something that should be supported on all platforms.

I have also created a scrollable window that works with the mouse but some of you would find it clunky.
Reply
#2
(02-11-2023, 08:41 PM)mnrvovrfc Wrote: How difficult would it be to create a "deluxe" edition of the Message Box which supports a large amount of text? What I mean is, an "OK" button, and a text field with scrollbars that could hold reasonably a larger amount of text than an ordinary Message Box. Take for instance the dialog seen in many Windows installers, to display the License Agreement, and usually has two buttons: "I agree" or "I decline".  Just offer the one button to get out of the dialog.

It would be a good alternative to the "SCREEN 0" to show more stuff that could fit on that screen. The problem could be how large to make the window and the scrollable text holder.

Code: (Select All)
/------------------------------------------------\
| +-----------------------------------+          |
| |This is an example of text.       ^|          |
| |                                  I|  +-----+ |
| |                                  I|  | OK  | |
| |                                  I|  +-----+ |
| |                                  I|          |
| |<================================>V|          |
| +-----------------------------------+          |
\------------------------------------------------/

I have taken the idea from the Purebasic Code Archive, which used WinAPI, and created a version of it with Autohotkey. It should be doable with TinyFileDialog library. Of course, this is something that should be supported on all platforms.

I have also created a scrollable window that works with the mouse but some of you would find it clunky.

Can you show some screenshots of the version you made? That might give us an idea of what functions we should be calling.
Tread on those who tread on you

Reply
#3
Who in this wide world wants to scroll horizontally when they are reading?

It's why word wrap was invented.
b = b + ...
Reply
#4
Horizontal scroll is only a possibility, not a requirement.

The example code I have is in Purebasic, do you still want to see it?

I just remembered I also have a "Tinyscreendialog" which is not the implementation used by QB64PE, but was a Freebasic "library" by someone else. It was by one of the early contributors of the QB64 Wiki. Allowed to build simple dialogs much like Autohotkey. With that I was able to build an extended message box which had a text field that could scroll vertically, and otherwise "OK" button.

Code: (Select All)
Procedure MessageWindow(Titel.s, Text.s)
    xwidth = 320
    xheight = 160
    ewindow = OpenWindow(#PB_Any, 0, 0, xwidth, xheight, Titel, #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    If ewindow
        pip = 0
        Repeat
            pip = FindString(Text, "|", pip + 1)
            If pip
                If Mid(Text, pip + 1, 1) = "0"
                    ch = Val(Mid(Text, pip + 2, 3))
                    If ch = 124: ch = 1: EndIf
                    If ch
                        Text = Left(Text, pip - 1) + Chr(ch) + Mid(Text, pip + 5)
                    EndIf
                EndIf
            EndIf
        Until pip = 0
        Text = ReplaceString(Text, "|", Chr(13) + Chr(10))
        Text = ReplaceString(Text, #SOH$, "|")
        ewindowcontent = StringGadget(#PB_Any, 0, 0, xwidth, xheight - 32, Text, #PB_String_ReadOnly | #ES_MULTILINE | #PB_String_BorderLess | #WS_VSCROLL | #WS_HSCROLL)
        okbut = ButtonGadget(#PB_Any, xwidth / 2 - 60, xheight - 28, 120, 28, "OK")
        Repeat
            ev = WaitWindowEvent()
            If (ev = #PB_Event_Gadget) And (EventGadget() = okbut)
                Break
            EndIf
        Until ev = #PB_Event_CloseWindow
        CloseWindow(ewindow)
    EndIf
EndProcedure

As I've said, it was derrived from Purebasic Code Archive. The size of the dialog is hardcoded because it was meant to be a demonstration of using "any" amount of text as the message. Of course it could be made larger, until the limits of the screen, up to the programmer. It uses pipe "|" character to delimit a newline, so there was no need to inject a CHR$(13). It might have to be adjusted, however, to send the right newline combination depending on operating system.

EDIT #2: AH screenshots! Will have to go back to Windows LOL and dig even deeper into my backups for an EXE file created with that programming system. Or the only program I wrote with Freebasic which only gives tag information to an OGG Vorbis file.
Reply
#5
I'm not going to install Purebasic only to do a screenshot, in fact never again. Sorry.

I was unable to find the "utility" which uses "vorbiscomment" program from the OGG Vorbis tools, with the "Tinydialog" library for Freebasic, I think it was written by stylin?

Welp, I created something that could work on any platform, but it's not quite the same as I requested on this topic.

Code: (Select All)
OPTION _EXPLICIT
DIM txt$, a$, ff AS LONG
DIM SHARED crlf$
crlf$ = CHR$(13)
$IF WIN THEN
    crlf$ = crlf$ + chr$(10)
$ELSEIF LINUX THEN
    crlf$ = CHR$(10)
$END IF

ff = FREEFILE
txt$ = ""
OPEN "fd13.bas" FOR INPUT AS ff
DO UNTIL EOF(ff)
    LINE INPUT #ff, a$
    txt$ = txt$ + a$ + crlf$
LOOP
CLOSE ff

readtextwindow txt$
SYSTEM

SUB readtextwindowex (s$, wantwidth, wantheigh, wantcolorf, wantcolorb)
    STATIC prevwindow AS LONG
    DIM breakaway AS _UNSIGNED _BIT
    DIM update AS _UNSIGNED _BIT
    DIM a$, na$, ke$, ch AS INTEGER, kk AS INTEGER
    DIM AS LONG wantminus, wantchrwd, faketextwindow, numele, l, u, uu, p, up, lastline, top, numnum, y, otop
    IF s$ = "" THEN EXIT SUB
    prevwindow = _COPYIMAGE(0)
    IF wantwidth < 40 OR wantwidth > 160 THEN wantwidth = 120
    IF wantheigh < 20 OR wantheigh > 50 THEN wantheigh = 40
    wantminus = 10
    wantchrwd = wantwidth - wantminus
    IF wantcolorf < 0 OR wantcolorf > 15 THEN wantcolorf = 0
    IF wantcolorb < 0 OR wantcolorb > 15 THEN wantcolorb = 7
    IF wantcolorf = wantcolorb THEN wantcolorf = 0: wantcolorb = 7
    faketextwindow = _NEWIMAGE(wantwidth, wantheigh, 0)
    SCREEN faketextwindow
    COLOR wantcolorf, wantcolorb
    CLS
    _SCREENMOVE _MIDDLE
    numele = 1000
    REDIM sf(1 TO numele) AS STRING
    breakaway = 0
    l = 0
    u = INSTR(s$, crlf$)
    uu = 1
    DO
        IF u = 0 THEN breakaway = NOT breakaway
        IF breakaway THEN
            a$ = MID$(s$, uu)
            na$ = _TRIM$(a$)
            IF na$ = "" THEN EXIT DO
        ELSE
            a$ = SEG1$(s$, uu, u)
            na$ = _TRIM$(a$)
            IF a$ <> na$ THEN a$ = na$
            p = INSTR(a$, crlf$)
            DO WHILE p > 0
                a$ = LEFT$(a$, p - 1) + MID$(a$, p + 1)
                p = INSTR(a$, crlf$)
            LOOP
        END IF
        l = l + 1
        IF l > numele THEN
            numele = numele + 1000
            REDIM _PRESERVE sf(1 TO numele) AS STRING
        END IF
        p = LEN(a$)
        IF p > wantchrwd THEN
            up = wantchrwd + 1
            ch = ASC(a$, up)
            DO UNTIL ch = 32
                up = up - 1
                ch = ASC(a$, up)
            LOOP
            sf(l) = LEFT$(a$, up - 1)
            a$ = MID$(a$, up + 1)
            p = LEN(a$)
            DO WHILE p > wantchrwd
                l = l + 1
                IF l > numele THEN
                    numele = numele + 1000
                    REDIM _PRESERVE sf(1 TO numele) AS STRING
                END IF
                up = wantchrwd + 1
                ch = ASC(a$, up)
                DO UNTIL ch = 32
                    up = up - 1
                    ch = ASC(a$, up)
                LOOP
                sf(l) = LEFT$(a$, up - 1)
                a$ = MID$(a$, up + 1)
                p = LEN(a$)
            LOOP
            l = l + 1
            IF l > numele THEN
                numele = numele + 1000
                REDIM _PRESERVE sf(1 TO numele) AS STRING
            END IF
        END IF
        sf(l) = a$
        IF breakaway THEN EXIT DO
        uu = u + LEN(crlf$)
        u = INSTR(uu, s$, crlf$)
    LOOP UNTIL breakaway

    lastline = l - wantheigh
    top = 1
    update = 1
    numnum = 0
    DO
        _LIMIT 1000
        IF update THEN
            update = 0
            CLS
            p = top
            FOR y = 1 TO wantheigh
                LOCATE y, 1
                PRINT sf(p);
                p = p + 1
                IF p > l THEN EXIT FOR
            NEXT
        END IF
        ke$ = INKEY$
        IF ke$ <> "" THEN
            kk = ASC(ke$)
            IF kk = 0 THEN kk = ASC(ke$, 2) * -1
            SELECT CASE kk
                CASE -81, 32
                    update = 1
                    otop = top
                    top = top + wantheigh - 2
                    IF top > lastline THEN top = lastline
                    IF top < 1 OR top > l THEN update = 0: top = otop
                CASE -80, -77, 13
                    otop = top
                    top = top + 1
                    IF top > lastline THEN top = lastline ELSE update = 1
                    IF top < 1 OR top > l THEN update = 0: top = otop
                CASE -79
                    update = 1
                    top = lastline
                CASE -72, -75
                    top = top - 1
                    IF top < 1 THEN top = 1 ELSE update = 1
                CASE -73
                    update = 1
                    top = top - wantheigh - 2
                    IF top < 1 THEN top = 1
                CASE -71
                    update = 1
                    top = 1
                CASE 27: EXIT DO
                CASE 48 TO 57
                    IF numnum = 0 THEN
                        numnum = VAL(ke$)
                    ELSE
                        numnum = VAL(ke$) * 10 + numnum
                    END IF
                    IF numnum < 1 OR numnum > lastline THEN
                        numnum = 0
                    ELSE
                        update = 1
                        top = numnum
                    END IF
            END SELECT
        END IF
    LOOP

    ERASE sf
    SCREEN prevwindow
    _FREEIMAGE faketextwindow
END SUB

SUB readtextwindow2ex (sa() AS STRING, wantwidth, wantheigh, wantcolorf, wantcolorb)
    STATIC a$
    DIM AS LONG lb, ub, i
    lb = LBOUND(sa)
    ub = UBOUND(sa)
    FOR i = lb TO ub
        a$ = a$ + sa(i)
        IF i < ub THEN a$ = a$ + crlf$
    NEXT
    readtextwindowex a$, wantwidth, wantheigh, wantcolorf, wantcolorb
    a$ = ""
END SUB

SUB readtextwindow (s$)
    readtextwindowex s$, -1, -1, -1, -1
END SUB

SUB readtextwindow2 (sa() AS STRING)
    readtextwindow2ex sa(), -1, -1, -1, -1
END SUB

FUNCTION SEG1$ (astr$, stapos AS LONG, endpos AS LONG)
    DIM sp AS LONG, ep AS LONG, l AS LONG
    IF astr$ = "" THEN SEG1$ = "": EXIT FUNCTION
    sp = stapos
    ep = endpos
    l = LEN(astr$)
    IF sp < 1 THEN sp = l + sp
    IF ep < 1 THEN ep = l + ep
    IF (sp < 1 AND ep < 1) OR (sp > l AND ep > l) THEN SEG1$ = "": EXIT FUNCTION
    IF sp < 1 THEN sp = 1
    IF ep < 1 THEN ep = 1
    IF sp > l THEN sp = l
    IF ep > l THEN ep = l
    IF sp > ep THEN SWAP sp, ep
    SEG1$ = MID$(astr$, sp, ep - sp + 1)
END FUNCTION

Change the text filename to the one you want on the line with "OPEN" statement.

For a string variable delimited by newline characters, call "readtextwindow". If it's a string array, call "readtextwindow2". If you want control over the screen colors and the screen dimensions, use the ordinary subprogram call. Note this is SCREEN 0, not graphics screen. Also I believe in the second version of this, which now I can't find in my backups, had mouse support. This presented one, however, supports the arrow keys.

I still want one which looks like standard dialogs out of an operating system desktop.
Reply
#6
Well, could you at least post a screenshot of the results you got with the code you just posted?
Tread on those who tread on you

Reply
#7
(02-13-2023, 07:21 PM)mnrvovrfc Wrote: I'm not going to install Purebasic only to do a screenshot, in fact never again. Sorry.

maybe smallbasic or Justbasic are worth a shot?
Reply
#8
I have PureBasic ..but i don't see a point why i  do that
looks to me like discovery of hot water..

message box in winApi is derived from Dialog class and as such have some great points and limitations
u can simply use Toolwindow -> class and make custom message box


[Image: PB-Message-Window.png]


Attached Files Image(s)
   
Reply
#9
Thumbs Up 
(02-14-2023, 10:03 AM)aurel Wrote: I have PureBasic ..but i don't see a point why i  do that
looks to me like discovery of hot water..

Thank you mate!

But I wrote a version somewhere (then that should have been with Autohotkey) where the "OK" button was on the left-hand side of the dialog, leaving the text box as high inside the window as possible. That is better because most people expect word-wrap going from left to right. Maybe it's the same eg. for those that write in Arabic but right to left...
Reply
#10
Well this requires Yad. It could probably be done with Zenity but that's about it for Linux. Windows could well do this as I've already demonstrated although poorly. I still want this. Smile

[Image: spiral-kde-yad-ext-msgbox.png]
Reply




Users browsing this thread: 2 Guest(s)