Announcement

Collapse
No announcement yet.

Custom Message Box DLL for use with PBCC

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

    Custom Message Box DLL for use with PBCC

    In this post, where he created a TXT WIndow based Fixed Font message box replacement for PBCC:
    'Mono-Spaced (fixed pitch) "Messagebox" for PBCC. 'Uses a TXT.WINDOW, so can be compiled and run in PBCC or PBWin. 'It is an update to: ' https://forum.powerbasic.com/forum/user-to-user-discussions/programming/823645-formatting-a-print-output-with-commas-and-decimal-points?p=823677#post823677 'The OP in that thread

    Dale wrote
    'If you have both PBWin and PBCC, I suggest compiling Stuart's to DLL for use
    'with PBCC. This one is intended as an option for users who only have PBCC.​


    I thought that sounded like a good idea, so I compiled it for those who don't have PBWIn. The DLL is a compilation of the code at
    Discussion thread for this post here: https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/823790-custom-message-discussion#post823790 'A Message box replacement as a PowerBasic Static Link Library 'Selectable font and optional colours and timeout. 'Autosizes and positions in centre of screen.


    Here's a simple test application in PBCC:
    '
    Code:
    #COMPILE EXE
    #DIM ALL
    
    DECLARE FUNCTION DlgMsgBox LIB "DlgMsgBox.dll" ALIAS "DLGMSGBOX" (hParent AS DWORD, wsText AS WSTRING,lButtons AS LONG,wsTitle AS WSTRING, _
             wsFont AS WSTRING,lFontsize AS LONG, _
             OPT lFGColour AS LONG, lBGColour AS LONG, lTimeOutSecs AS LONG)  AS LONG
    
    FUNCTION PBMAIN () AS LONG
        TestDlgMsg(CON.HANDLE)   'only need to pass console handle if you to deactivate the console  (using %WM_SYSTEMMODAL or %WM_TASKMODAL) while the messagebox is active
        ? "done"
        WAITKEY$
    END FUNCTION
    
    FUNCTION TestDlgMsg(hWnd AS DWORD) AS LONG
       LOCAL wsMsg AS WSTRING
       LOCAL lRet AS LONG
        wsMsg = "This is a Warning Message." & $LF & _
             "It tells you something important"  & $LF & _
             "..."  & $LF & _
             "Thie message will time out after ten seconds" &    _
             " and return 'Cancel' (%MB_DEFBUTTON1)."
     DO
          lRet = DlgMsgBox(hWnd,wsMsg,%MB_CANCELTRYCONTINUE OR %MB_DEFBUTTON1 OR %MB_ICONWARNING OR %MB_TASKMODAL,"This is a Messagebox", _
                 "Arial Bold",10,%RGB_RED,%RGB_YELLOW,10)
          SELECT CASE lRet
             CASE %IDCANCEL
                ? "Cancelled"
             CASE %IDRETRY
                ? "Retry"
             CASE %IDCONTINUE
             ? "Continue"
         END SELECT
    LOOP WHILE lRet = %IDRETRY
    END FUNCTION
    '


    The DLL and PBWIn source are in the attached Zip

    Click image for larger version  Name:	MsgboxPBCC.jpg Views:	0 Size:	65.1 KB ID:	823817
    Attached Files
    Last edited by Stuart McLachlan; 28 May 2023, 03:08 AM.
    =========================
    https://camcopng.com
    =========================

    #2
    Nice work Stuart, as always. I did something similar long ago and then added support for copy (Ctrl+C and Ctrl+Insert), because some people may expect that to work just like in ordinary messagebox. In my case, I simply used an equate, a couple of keyboard accelerators and some code to put contents into clipboard under %WM_COMMAND/%IDC_COPY (IF CB.CTLMSG = 1 THEN). Not really necessary, but maybe an idea for future features.
    ​'
    Code:
      '------------------------------------------------------------------
      ' Ctrl+V  and  Ctrl+Insert = Copy support...
      LOCAL hAccel AS DWORD
      REDIM ac(1) AS ACCELAPI
      ac(0).fvirt = %FVIRTKEY OR %FCONTROL : ac(0).key = %VK_C      : ac(0).cmd = %IDC_COPY
      ac(1).fvirt = %FVIRTKEY OR %FCONTROL : ac(1).key = %VK_INSERT : ac(1).cmd = %IDC_COPY
      ACCEL ATTACH hDlg, AC() TO hAccel
      '------------------------------------------------------------------
    '

    Comment


      #3
      Originally posted by Borje Hagsten View Post
      Nice work Stuart, as always. I did something similar long ago and then added support for copy (Ctrl+V and Ctrl+Insert), because some people may expect that to work just like in ordinary messagebox. In my case, I simply used an equate, a couple of keyboard accelerators and some code to put contents into clipboard under %WM_COMMAND/%IDC_COPY (IF CB.CTLMSG = 1 THEN). Not really necessary, but maybe an idea for future features.
      ​'
      Code:
      '------------------------------------------------------------------
      ' Ctrl+V and Ctrl+Insert = Copy support...
      LOCAL hAccel AS DWORD
      REDIM ac(1) AS ACCELAPI
      ac(0).fvirt = %FVIRTKEY OR %FCONTROL : ac(0).key = %VK_C : ac(0).cmd = %IDC_COPY
      ac(1).fvirt = %FVIRTKEY OR %FCONTROL : ac(1).key = %VK_INSERT : ac(1).cmd = %IDC_COPY
      ACCEL ATTACH hDlg, AC() TO hAccel
      '------------------------------------------------------------------
      '
      Good Idea. I often use Ctrl+C to copy an ordinary messagebox's contents to the clipboard. I'll add that.
      =========================
      https://camcopng.com
      =========================

      Comment


        #4
        Ok, I've just updated the zip attachment in Post #1 to be a new version which supports Ctrl+C = Copy to Clipboard!

        (Also updated the SLL version in Source Code.)
        =========================
        https://camcopng.com
        =========================

        Comment


          #5
          In your test program, hDlg is undefined.
          "Not my circus, not my monkeys."

          Comment


            #6
            Originally posted by Eric Pearson View Post
            In your test program, hDlg is undefined.
            Oops, that's what you get when you change something in the posted code without testing it again.

            I originally had TestDlgMsg(hDlg AS DWORD... because it was originally for PBWin.
            I changed it to TestDlgMsg(hWnd AS DWORD... after I posted it because I realised that the parent was not a Dialog (it's a console) , so hDLg was inappropriate.
            I forgot to change it in the call as well.

            I've edited the posted code to lRet = DlgMsgBox(hWnd,...

            Thanks for spotting it.
            =========================
            https://camcopng.com
            =========================

            Comment


              #7
              ((insignificant - I would have used hCon. (hTWnd for TXT.WINDOW, hGWin for GRAPHIC WINDOW)))

              {next cat to skin please ... }
              Dale

              Comment


                #8
                Originally posted by Dale Yarker View Post
                ((insignificant - I would have used hCon. (hTWnd for TXT.WINDOW, hGWin for GRAPHIC WINDOW)))

                {next cat to skin please ... }
                That function TestDlgMessage is generic and can be used in either a PBWIn or a PBCC application and the parent could be any sort of window, not just a console or dialog , so the generic hWnd is a logical name ( unless you want to make it hParent as in the DLL declaration ).

                (Here's a turtle, skin that next )
                =========================
                https://camcopng.com
                =========================

                Comment


                  #9
                  > 'only need to pass console handle if you [plan?] to deactivate the console
                  > '(using %WM_SYSTEMMODAL or %WM_TASKMODAL) while the messagebox is active


                  If you don't pass the console windows handle, then even with %MB_TASKMODAL, if you accidentally click on the console, the message box can completely disappear behind a large console window. Worse, neither one will respond to the keyboard. This can completely confound a user. Even if they notice the separate button on the Task Bar and click it, then dismiss the message box, keyboard/mouse focus will not properly return to the console.

                  Also, I recommend against ever using %MB_SYSTEMMODAL, except in very rare circumstances. Highly frowned upon. A typical user's only other choice may be to turn off the computer.

                  Mixing GUIs and consoles is tricky! (Writing Console Tools was a nightmare, especially back when 95/98/ME was still a thing.)

                  Here's a challenge for you... It's possible -- unless they changed it after Win7 -- to add a standard GUI pulldown menu to a console window, just like it was a dialog.
                  "Not my circus, not my monkeys."

                  Comment


                    #10
                    Originally posted by Eric Pearson View Post
                    If you don't pass the console windows handle, then even with %MB_TASKMODAL, if you accidentally click on the console, the message box can completely disappear behind a large console window.
                    That's because I was using DIALOG DISABLE and %HWND_TOP since it was originally PBWin.
                    I've modified it to use %HWND_TOPMOST​ with %MB_TASKMODAL so that it stays on top of the console window. if called from a PBCC application without passing the cosnsole handle.

                    Attachment in Post #1 updated.

                    (I've also modified it so that Ctrl+C works properly with Unicode such as Greek or Russian text)

                    Also, I recommend against ever using %MB_SYSTEMMODAL, except in very rare circumstances. Highly frowned upon. A typical user's only other choice may be to turn off the computer.​
                    Frowned on by whom? Got any references?
                    MS just says:
                    "Same as MB_APPLMODAL except that the message box has the WS_EX_TOPMOST style. Use system-modal message boxes to notify the user of serious, potentially damaging errors that require immediate attention (for example, running out of memory). This flag has no effect on the user's ability to interact with windows other than those associated with hWnd.​"
                    =========================
                    https://camcopng.com
                    =========================

                    Comment


                      #11
                      > Frowned on by whom?

                      Ah, thanks, you're right! I went back to the Console Tools Help File, and that warning applied only to Platform 1.
                      "Not my circus, not my monkeys."

                      Comment

                      Working...
                      X
                      😀
                      🥰
                      🤢
                      😎
                      😡
                      👍
                      👎