• Print

Author Topic: MessageBox!  (Read 314 times)

Prithak

  • Full Member
  • ***
  • Posts: 109
  • Programmer: A machine turns Coffee into Code.
MessageBox!
« on: May 05, 2018, 01:33:54 am »
Code: [Select]
SUB msgbox (word$, id$, title$)
    OPEN "message.vbs" FOR OUTPUT AS #1
    PRINT #1, "x = MsgBox (" + CHR$(34) + word$ + CHR$(34) + "," + id$ + "," + CHR$(34) + title$ + CHR$(34) + ")"
    CLOSE #1
    SHELL "start message.vbs"
END SUB
I am Sure Many of you guys figured this out but whatever it is really simple and it will help me a lot!!
Q: 0 is False and 1 is True, right?
A: 1

CletusSnow

  • Newbie
  • *
  • Posts: 18
Re: MessageBox!
« Reply #1 on: May 06, 2018, 01:29:44 am »
Yes, very easy. I've only been awake for ten minutes... but how can I get the value x back to QB?

Prithak

  • Full Member
  • ***
  • Posts: 109
  • Programmer: A machine turns Coffee into Code.
Re: MessageBox!
« Reply #2 on: May 06, 2018, 05:05:12 am »
Quote from: CletusSnow on May 06, 2018, 01:29:44 am
Yes, very easy. I've only been awake for ten minutes... but how can I get the value x back to QB?
Wait, Why do you want that??
Q: 0 is False and 1 is True, right?
A: 1

FellippeHeitor

  • QB64 Partner Site Owner
  • Hero Member
  • *
  • Posts: 1901
  • LET IT = BE
    • QB64.org
Re: MessageBox!
« Reply #3 on: May 06, 2018, 05:45:08 am »
Quote from: Prithak on May 06, 2018, 05:05:12 am
Wait, Why do you want that??

If you can't get a return value, how will you know what button the user clicked?



Here's a message box library I wrote for InForm that'll work cross platform, Windows, macOS and Linux. Hope you guys enjoy it:

Code: [Select]
'Sample usage:
Answer = MessageBox("Do you like this library?", "Obvious question", MsgBox_YesNo + MsgBox_Question)
IF Answer = MsgBox_Yes THEN
    PRINT "I knew you'd like it :-)"
ELSE
    PRINT "Maybe you didn't read it carefully enough."
END IF

'MessageBox Library:---------------------------------------------------------------------------------------------------
FUNCTION MessageBox& (Message$, Title$, Setup AS LONG)
    DECLARE LIBRARY
        FUNCTION __UI_MB& ALIAS MessageBox (BYVAL ignore&, message$, title$, BYVAL type&)
    END DECLARE

    IF Title$ = "" THEN Title$ = "MessageBox"

    $IF WIN THEN
        MessageBox& = __UI_MB(0, Message$ + CHR$(0), Title$ + CHR$(0), Setup + MsgBox_SystemModal + MsgBox_SetForeground)
    $ELSE
        IF (Setup AND 4) THEN
        MessageBox& = __UI_MB(0, Message$ + CHR$(0), Title$ + CHR$(0), 4)
        ELSE
        MessageBox& = __UI_MB(0, Message$ + CHR$(0), Title$ + CHR$(0), 0)
        END IF
    $END IF
END FUNCTION

FUNCTION MsgBox_OkOnly%%: MsgBox_OkOnly%% = 0: END FUNCTION
FUNCTION MsgBox_OkCancel%%: MsgBox_OkCancel%% = 1: END FUNCTION
FUNCTION MsgBox_AbortRetryIgnore%%: MsgBox_AbortRetryIgnore%% = 2: END FUNCTION
FUNCTION MsgBox_YesNoCancel%%: MsgBox_YesNoCancel%% = 3: END FUNCTION
FUNCTION MsgBox_YesNo%%: MsgBox_YesNo%% = 4: END FUNCTION
FUNCTION MsgBox_RetryCancel%%: MsgBox_RetryCancel%% = 5: END FUNCTION
FUNCTION MsgBox_CancelTryagainContinue%%: MsgBox_CancelTryagainContinue%% = 6: END FUNCTION

FUNCTION MsgBox_Critical%: MsgBox_Critical% = 16: END FUNCTION
FUNCTION MsgBox_Question%: MsgBox_Question% = 32: END FUNCTION
FUNCTION MsgBox_Exclamation%: MsgBox_Exclamation% = 48: END FUNCTION
FUNCTION MsgBox_Information%: MsgBox_Information% = 64: END FUNCTION

FUNCTION MsgBox_DefaultButton1%: MsgBox_DefaultButton1% = 0: END FUNCTION
FUNCTION MsgBox_DefaultButton2%: MsgBox_DefaultButton2% = 256: END FUNCTION
FUNCTION MsgBox_DefaultButton3%: MsgBox_DefaultButton3% = 512: END FUNCTION
FUNCTION MsgBox_Defaultbutton4%: MsgBox_Defaultbutton4% = 768: END FUNCTION

FUNCTION MsgBox_AppModal%%: MsgBox_AppModal%% = 0: END FUNCTION
FUNCTION MsgBox_SystemModal%: MsgBox_SystemModal% = 4096: END FUNCTION
FUNCTION MsgBox_SetForeground&: MsgBox_SetForeground& = 65536: END FUNCTION

FUNCTION MsgBox_Ok%%: MsgBox_Ok%% = 1: END FUNCTION
FUNCTION MsgBox_Cancel%%: MsgBox_Cancel%% = 2: END FUNCTION
FUNCTION MsgBox_Abort%%: MsgBox_Abort%% = 3: END FUNCTION
FUNCTION MsgBox_Retry%%: MsgBox_Retry%% = 4: END FUNCTION
FUNCTION MsgBox_Ignore%%: MsgBox_Ignore%% = 5: END FUNCTION
FUNCTION MsgBox_Yes%%: MsgBox_Yes%% = 6: END FUNCTION
FUNCTION MsgBox_No%%: MsgBox_No%% = 7: END FUNCTION
FUNCTION MsgBox_Tryagain%%: MsgBox_Tryagain%% = 10: END FUNCTION
FUNCTION MsgBox_Continue%%: MsgBox_Continue%% = 11: END FUNCTION
- InForm for QB64 http://qb64.org/inform

- vWATCH64 (debugger for QB64) http://bit.ly/vWATCH64v1-103

- Games: http://bit.ly/2048_qb64 * http://bit.ly/ClonedShades_qb64source * http://bit.ly/2aqK866 * http://bit.ly/SpaceshipQB64 * http://bit.ly/2rD1pPP

Prithak

  • Full Member
  • ***
  • Posts: 109
  • Programmer: A machine turns Coffee into Code.
Re: MessageBox!
« Reply #4 on: May 06, 2018, 05:54:29 am »
Quote from: FellippeHeitor on May 06, 2018, 05:45:08 am
Quote from: Prithak on May 06, 2018, 05:05:12 am
Wait, Why do you want that??

If you can't get a return value, how will you know what button the user clicked?



Here's a message box library I wrote for InForm that'll work cross platform, Windows, macOS and Linux. Hope you guys enjoy it:

Code: [Select]
'Sample usage:
Answer = MessageBox("Do you like this library?", "Obvious question", MsgBox_YesNo + MsgBox_Question)
IF Answer = MsgBox_Yes THEN
    PRINT "I knew you'd like it :-)"
ELSE
    PRINT "Maybe you didn't read it carefully enough."
END IF

'MessageBox Library:---------------------------------------------------------------------------------------------------
FUNCTION MessageBox& (Message$, Title$, Setup AS LONG)
    DECLARE LIBRARY
        FUNCTION __UI_MB& ALIAS MessageBox (BYVAL ignore&, message$, title$, BYVAL type&)
    END DECLARE

    IF Title$ = "" THEN Title$ = "MessageBox"

    $IF WIN THEN
        MessageBox& = __UI_MB(0, Message$ + CHR$(0), Title$ + CHR$(0), Setup + MsgBox_SystemModal + MsgBox_SetForeground)
    $ELSE
        IF (Setup AND 4) THEN
        MessageBox& = __UI_MB(0, Message$ + CHR$(0), Title$ + CHR$(0), 4)
        ELSE
        MessageBox& = __UI_MB(0, Message$ + CHR$(0), Title$ + CHR$(0), 0)
        END IF
    $END IF
END FUNCTION

FUNCTION MsgBox_OkOnly%%: MsgBox_OkOnly%% = 0: END FUNCTION
FUNCTION MsgBox_OkCancel%%: MsgBox_OkCancel%% = 1: END FUNCTION
FUNCTION MsgBox_AbortRetryIgnore%%: MsgBox_AbortRetryIgnore%% = 2: END FUNCTION
FUNCTION MsgBox_YesNoCancel%%: MsgBox_YesNoCancel%% = 3: END FUNCTION
FUNCTION MsgBox_YesNo%%: MsgBox_YesNo%% = 4: END FUNCTION
FUNCTION MsgBox_RetryCancel%%: MsgBox_RetryCancel%% = 5: END FUNCTION
FUNCTION MsgBox_CancelTryagainContinue%%: MsgBox_CancelTryagainContinue%% = 6: END FUNCTION

FUNCTION MsgBox_Critical%: MsgBox_Critical% = 16: END FUNCTION
FUNCTION MsgBox_Question%: MsgBox_Question% = 32: END FUNCTION
FUNCTION MsgBox_Exclamation%: MsgBox_Exclamation% = 48: END FUNCTION
FUNCTION MsgBox_Information%: MsgBox_Information% = 64: END FUNCTION

FUNCTION MsgBox_DefaultButton1%: MsgBox_DefaultButton1% = 0: END FUNCTION
FUNCTION MsgBox_DefaultButton2%: MsgBox_DefaultButton2% = 256: END FUNCTION
FUNCTION MsgBox_DefaultButton3%: MsgBox_DefaultButton3% = 512: END FUNCTION
FUNCTION MsgBox_Defaultbutton4%: MsgBox_Defaultbutton4% = 768: END FUNCTION

FUNCTION MsgBox_AppModal%%: MsgBox_AppModal%% = 0: END FUNCTION
FUNCTION MsgBox_SystemModal%: MsgBox_SystemModal% = 4096: END FUNCTION
FUNCTION MsgBox_SetForeground&: MsgBox_SetForeground& = 65536: END FUNCTION

FUNCTION MsgBox_Ok%%: MsgBox_Ok%% = 1: END FUNCTION
FUNCTION MsgBox_Cancel%%: MsgBox_Cancel%% = 2: END FUNCTION
FUNCTION MsgBox_Abort%%: MsgBox_Abort%% = 3: END FUNCTION
FUNCTION MsgBox_Retry%%: MsgBox_Retry%% = 4: END FUNCTION
FUNCTION MsgBox_Ignore%%: MsgBox_Ignore%% = 5: END FUNCTION
FUNCTION MsgBox_Yes%%: MsgBox_Yes%% = 6: END FUNCTION
FUNCTION MsgBox_No%%: MsgBox_No%% = 7: END FUNCTION
FUNCTION MsgBox_Tryagain%%: MsgBox_Tryagain%% = 10: END FUNCTION
FUNCTION MsgBox_Continue%%: MsgBox_Continue%% = 11: END FUNCTION
I made this code for simple error messages :D

But thank you for the function!
Q: 0 is False and 1 is True, right?
A: 1

bplus

  • Hero Member
  • *****
  • Posts: 764
  • B = B + _
Re: MessageBox!
« Reply #5 on: May 06, 2018, 09:42:09 am »
I was testing the Message Box code from Windows Libraries in Wiki trying to make a very simple sub called tell to relay a message and got very strange results specially after first loop.

It appears the the variables are not clearing but building on last values but it is also taking comments I make in code and putting them in the box!?!?  ??? how the heck is it doing that?

Is this a known bug? or am I setting up things wrongly?

Code: [Select]
' 2018-05-06 I am getting goofy results specially when I call the sub a second time!!!
' how does the exe behave? crappy too!


' http://www.qb64.net/wiki/index.php/Windows_Libraries   scroll way way down to Message Box
'Message Box Constant values as defined by Microsoft (MBType)

'box type
CONST MB_OK& = 0 'OK button only
CONST MB_OKCANCEL& = 1 'OK & Cancel
CONST MB_ABORTRETRYIGNORE& = 2 'Abort, Retry & Ignore
CONST MB_YESNOCANCEL& = 3 'Yes, No & Cancel
CONST MB_YESNO& = 4 'Yes & No
CONST MB_RETRYCANCEL& = 5 'Retry & Cancel
CONST MB_CANCELTRYCONTINUE& = 6 'Cancel, Try Again & Continue

'icon
CONST MB_ICONSTOP& = 16 'Error stop sign icon
CONST MB_ICONQUESTION& = 32 'Question-mark icon
CONST MB_ICONEXCLAMATION& = 48 'Exclamation-point icon
CONST MB_ICONINFORMATION& = 64 'Letter i in a circle icon

'default button
CONST MB_DEFBUTTON1& = 0 '1st button default(left)
CONST MB_DEFBUTTON2& = 256 '2nd button default
CONST MB_DEFBUTTON3& = 512 '3rd button default(right)
CONST MB_APPLMODAL& = 0 'Message box applies to application only
CONST MB_SYSTEMMODAL& = 4096 'Message box on top of all other windows
CONST MB_SETFOCUS& = 65536 'Set message box as focus
CONST IDOK& = 1 'OK button pressed
CONST IDCANCEL& = 2 'Cancel button pressed
CONST IDABORT& = 3 'Abort button pressed
CONST IDRETRY& = 4 'Retry button pressed
CONST IDIGNORE& = 5 'Ignore button pressed
CONST IDYES& = 6 'Yes button pressed
CONST IDNO& = 7 'No button pressed
CONST IDTRYAGAIN& = 10 'Try again button pressed
CONST IDCONTINUE& = 1 'Continue button pressed
'----------------------------------------------------------------------------------------

DECLARE LIBRARY
    FUNCTION MessageBox& (BYVAL Zer0 AS LONG, Message AS STRING, Title AS STRING, BYVAL MBType AS _UNSIGNED LONG)
END DECLARE

'DO
'    msg& = 0: icon& = 0: DB& = 0
'    CLS
'    PRINT "Box types:"
'    PRINT " 0 = OK"
'    PRINT " 1 = OK & Cancel"
'    PRINT " 2 = Abort, Retry & Ignore"
'    PRINT " 3 = Yes, No & Cancel"
'    PRINT " 4 = Yes & No"
'    PRINT " 5 = Retry & Cancel"
'    PRINT " 6 = Cancel, Try Again & Continue"
'    INPUT "Enter Message Box type(0 to 6 other Quits): ", BOX&
'    IF BOX& < 0 OR BOX& > 6 THEN EXIT DO
'    INPUT "Enter Icon&(0=none, 1=stop, 2=?, 3=!, 4=info): ", icon&
'    IF BOX& THEN INPUT "Enter Default Button(1st, 2nd or 3rd): ", DB&
'    IF DB& THEN DB& = DB& - 1 'adjust value to 0, 1, or 2
'    msg& = MsgBox&("Box Title", "Box text message", BOX&, icon&, DB&, 4096) 'on top of all windows
'    PRINT "Button ="; msg&
'LOOP

'try to setup a simple message sub
WHILE 1
    CLS
    PRINT "Testing a simple message sub 'tell':"
    INPUT "Enter a title: "; t$
    IF t$ = "" THEN PRINT "goodbye": END
    INPUT "Enter a message: "; m$
    IF m$ = "" THEN PRINT "goodbye": END
    tell t$, m$
WEND
END
SUB tell (title$, message$)
    'make copies to assure calling variables are not changed
    m$ = message$
    t$ = title$
    sent& = MessageBox&(0, m$, t$,  4096 + 65536) '< tried other numbers here for different icons, box type... but even the most basic does not work
END SUB
FUNCTION MsgBox& (Title AS STRING, Message$, BoxType&, Icon&, DBtn&, Mode&)
    SELECT CASE Icon&
        CASE 1: Icon& = MB_ICONSTOP& 'warning X-sign icon
        CASE 2: Icon& = MB_ICONQUESTION& 'question-mark icon
        CASE 3: Icon& = MB_ICONEXCLAMATION& 'exclamation-point icon
        CASE 4: Icon& = MB_ICONINFORMATION& 'lowercase letter i in circle
        CASE ELSE: Icon& = 0 'no icon
    END SELECT
    IF BoxType& > 0 AND DBtn& > 0 THEN 'set default button as 2nd(256) or 3rd(512)
        SELECT CASE BoxType&
            CASE 2, 3, 6
                IF DBtn& = 2 THEN Icon& = Icon& + MB_DEFBUTTON3& ELSE Icon& = Icon& + MB_DEFBUTTON2& '3 button
            CASE ELSE: Icon& = Icon& + MB_DEFBUTTON2& '2nd button default
        END SELECT
    END IF
    Focus& = MB_SETFOCUS&
    MsgBox& = MessageBox&(0, Message$, Title, BoxType& + Icon& + Mode& + Focus&) 'focus on button
END FUNCTION
« Last Edit: May 06, 2018, 09:55:48 am by bplus »
Will you still love me, will you still need me, when I'm (QB) 64?

FellippeHeitor

  • QB64 Partner Site Owner
  • Hero Member
  • *
  • Posts: 1901
  • LET IT = BE
    • QB64.org
Re: MessageBox!
« Reply #6 on: May 06, 2018, 10:45:34 am »
Your strings must end with CHR$(0) if you intend to pass them to Windows’ API. You’ll notice that in my code above as I’m using the API too.
- InForm for QB64 http://qb64.org/inform

- vWATCH64 (debugger for QB64) http://bit.ly/vWATCH64v1-103

- Games: http://bit.ly/2048_qb64 * http://bit.ly/ClonedShades_qb64source * http://bit.ly/2aqK866 * http://bit.ly/SpaceshipQB64 * http://bit.ly/2rD1pPP

bplus

  • Hero Member
  • *****
  • Posts: 764
  • B = B + _
Re: MessageBox!
« Reply #7 on: May 06, 2018, 11:34:45 am »
Thanks Fellippe!
Code: [Select]
' 2018-05-06 mod of
' http://www.qb64.net/wiki/index.php/Windows_Libraries   scroll way way down to Message Box
DECLARE LIBRARY
    FUNCTION MessageBox& (BYVAL Zer0 AS LONG, Message AS STRING, Title AS STRING, BYVAL MBType AS _UNSIGNED LONG)
END DECLARE
'try to setup a simple message sub
WHILE 1
    CLS
    PRINT "Testing a simple message sub 'tell':"
    INPUT "Enter a title: "; t$
    IF t$ = "" THEN PRINT "goodbye": END
    INPUT "Enter a message: "; m$
    IF m$ = "" THEN PRINT "goodbye": END
    tell t$, m$
WEND
END

SUB tell (title$, message$)
    'make copies to assure calling variables are not changed
    m$ = message$ + CHR$(0)
    t$ = title$ + CHR$(0)
    sent& = MessageBox&(0, m$, t$, 4096 + 65536)
END SUB



It's funny, I went to take a snap shot and the message box jumped on top of the snap shot app. :)
Will you still love me, will you still need me, when I'm (QB) 64?

eoredson

  • Hero Member
  • *****
  • Posts: 633
  • I programmed myself into a psychiatric conniption!
    • QB45 Oredson files at Filegate Network
Re: MessageBox!
« Reply #8 on: May 11, 2018, 08:49:42 pm »
Yet more boxes:

http://www.qb64.net/forum/index.php?topic=14395.0

Erik.
« Last Edit: May 11, 2018, 09:34:05 pm by eoredson »
Games: DNDDOOR - https://bit.ly/EriksDNDDoor DUNGEON - https://bit.ly/EriksDungeon
Interpreter - https://bit.ly/EriksSICK Hex Editor - https://bit.ly/EriksHexEditor
Utilities - https://bit.ly/EriksUtils Old QB64 - https://bit.ly/OldQB64
QB64 shell - https://bit.ly/QB64shell

  • Print