Announcement

Collapse
No announcement yet.

Simple INPUTBOX

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

    Simple INPUTBOX

    Is it possible to have in PBCC a very simple
    INPUTBOX$ function (with its own window)?
    Something like
    answer$ = INPUTBOXCC$("Your name please:")

    I saw in an old post a suggestion to use DialogBox API
    but it seems that a good knowledge of the API is needed for this.

    Thank you,
    Victor

    #2
    With PB/CC, it does not get any easier than Dialogbox.

    Unless....

    .. Some kind soul writes a PB/CC "INPUTBOX$" FUNCTION (using DialogBoxIndirect), which would be a really nice project resulting in a no doubt very useful piece of code and the undying and quasi-eternal appreciation of all PB/CC programmers everywhere.

    I'll even start if for you ..

    Code:
    #IF NOT %DEF (%pb_cc32) 
     FUNCTION INPUTBOX ( some params go here )  AS STRING
        Some code goes here
     END FUNCTION 
    #ENDIF
    Of course, since YOU asked, YOU could do it. Search source code forum for examples of either DialogBoxIndirect[Param] or CreateDialogIndirect[Param]. The use of any of these four functions will show you how to build the dialog template and fill in the blanks left by the Windows SDK documentatation for those functions.

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

    Comment


      #3
      Here's a start:



      James

      Comment


        #4
        OK, I think that I understand: a typical PBCC user must forget
        about INPUTBOX and be happy with the good old INPUT,
        unless she/he is willing to investigate low-level Windows programming.

        Comment


          #5
          ...or to use Console Tools, which provides several different input boxes.

          -- Eric Pearson, Perfect Sync, Inc.
          "Not my circus, not my monkeys."

          Comment


            #6
            >...or to use Console Tools, which provides ..

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

            Comment


              #7
              This would work if the screen size could be correctly controlled.
              I've had no luck controlling screen sizes without Console Tools.
              Might try using virtual screens instead CONSOLE SET VIRTUAL

              Code:
              #COMPILE EXE
              #DIM ALL
              FUNCTION PBMAIN () AS LONG
                LOCAL s AS STRING
                CONSOLE SET SCREEN 10, 40
                LINE INPUT "Please enter your name: " s
              END FUNCTION

              Comment


                #8
                Code:
                #COMPILER PBCC 4
                DECLARE FUNCTION inputFunction LIB "c:\InputBoxCC.dll" _
                          ALIAS "inputFunction" (BYVAL Param1 AS STRING) AS STRING
                          
                FUNCTION PBMAIN () AS LONG
                    DIM answer AS STRING
                    answer = inputFunction("What's your name?")
                    PRINT answer
                    WAITKEY$
                END FUNCTION
                Michael, I liked the "Real Men" comment ('nuff said!). But I couldn't help take a little shortcut (a Marine once told me, if it's stupid but it works, it's not stupid. The DLL was written in PB/DLL 8.0. I can provide the source if anyone wants it. The compiled DLL, which you'll need to download and copy to your c:\ folder, is here: http://aatfss.net/InputBoxCC.dll
                Christopher P. Becker
                signal engineer in the defense industry
                Abu Dhabi, United Arab Emirates

                Comment


                  #9
                  Christpher,
                  I would like to see the source code for your InputFunction.

                  Comment


                    #10
                    Here's the obvious source, written on-line

                    Code:
                    ' Myfile.bas 
                    #COMPILE DLL 
                    FUNCTION InputFunction ALIAS "inputfunction" (BYVAL s AS STRING) EXPORT AS STRING
                        FUNCTION = INPUTBOX$(S) 
                    END FUNCTION
                    ' //END OF FILE
                    (If you can compile to a DLL, you must have PB/Windows, in which the INPUTBOX$ function is available!)
                    Last edited by Michael Mattias; 6 Aug 2008, 08:43 AM.
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                      #11
                      Code:
                      #COMPILE DLL
                      
                      GLOBAL UserName AS STRING
                      
                      CALLBACK FUNCTION OkButton () AS LONG
                          IF CBCTLMSG = 0 THEN
                              CONTROL GET TEXT CBHNDL, 101 TO UserName
                              DIALOG END CBHNDL, 1
                              FUNCTION = 1
                          END IF
                      END FUNCTION
                      
                      FUNCTION inputFunction ALIAS "inputFunction" (BYVAL Param1 AS STRING) EXPORT AS STRING
                          DIM hDlg   AS DWORD
                          DIM Result AS LONG
                          DIM w AS LONG
                          w = INT(LEN(Param1) * 5)   ' width of winidow
                          IF w < 105 THEN w = 105
                          DIALOG NEW 0, Param1,,, (w + 40), 30 TO hDlg
                          CONTROL ADD TEXTBOX, hDlg, 101, "", 14,  9, (w - 28), 12
                          CONTROL ADD BUTTON, hDlg, 102, "OK", w, 9, 30, 14, 1 CALL OkButton
                          DIALOG SHOW MODAL hDlg TO Result
                          IF Result THEN FUNCTION = UserName
                      END FUNCTION
                      Bulkier code, but smaller GUI. Whatever.
                      Christopher P. Becker
                      signal engineer in the defense industry
                      Abu Dhabi, United Arab Emirates

                      Comment


                        #12
                        Michael, you also have to realize that sometimes I enjoy re-inventing the wheel. I have much more experience with PBCC than PB/DLL/Win, so there's always a lesson or two even in writing small functions like that one.

                        I've learned a lot just from reading your posts.
                        Christopher P. Becker
                        signal engineer in the defense industry
                        Abu Dhabi, United Arab Emirates

                        Comment


                          #13
                          Woo, you went 'deluxe' in spite of your request for " a very simple INPUTBOX$"

                          FWIW, you could put that in your library of code you can use with either compiler with conditional compilation...

                          Code:
                          #IF %DEF(%pb_cc32) 
                            DECLARE FUNCTION InputBox LIB "mylib.dll" ALIAS "inputfunction" (BYVAL s AS STRING) AS STRING
                          #ENDIF
                          Or just put the two functions in a separate file and conditionally #INCLUDE instead of DECLARE...

                          You'd have to add the two optional parameters to your function header, but then you would have - literally - "INPUTBOX$ for PB/CC"

                          I've done this kind of thing with MSGBOX (for PB/CC) and STDOUT (for PB/WIN). That is, both MSGBOX and STDOUT are valid regardless of which compiler I am working with that day.



                          MCM
                          Last edited by Michael Mattias; 7 Aug 2008, 08:18 AM.
                          Michael Mattias
                          Tal Systems (retired)
                          Port Washington WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment


                            #14
                            Yes a LOT more code but I couldn't resist a native PBCC solution using the Link I posted above. PBCC 4.04

                            James

                            Code:
                            '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
                            'SED_PBCC
                            '------------------------------------------------------------------------------
                            ' PBCC InputBox For your using pleasure or not!
                            '------------------------------------------------------------------------------
                            '                                  James C. Fuller
                            '                                   August 7,2008
                            '------------------------------------------------------------------------------
                            '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
                            #COMPILE EXE
                            #INCLUDE "WIN32API.INC"
                            'Link Located in prior Message
                            #INCLUDE "JCFRTDLG.BAS"
                            '==============================================================================
                            SUB  CenterWindow ( _
                                BYVAL hWnd    AS DWORD _
                              )
                            
                              DIM WndRect AS RECT
                              DIM x       AS LONG
                              DIM y       AS LONG
                            
                              GetWindowRect hWnd, WndRect
                            
                              x = (GetSystemMetrics(%SM_CXSCREEN) _
                                - (WndRect.nRight-WndRect.nLeft))\2
                              y = (GetSystemMetrics(%SM_CYSCREEN) _
                                - (WndRect.nBottom-WndRect.nTop+GetSystemMetrics(%SM_CYCAPTION)))\2
                            
                              SetWindowPos hWnd, %NULL, x, y, 0, 0, %SWP_NOSIZE OR %SWP_NOZORDER
                            
                            END SUB
                            '==============================================================================
                            GLOBAL UserName AS STRING
                            '==============================================================================
                            FUNCTION InputFunction(BYVAL Param1 AS STRING) AS LONG
                                LOCAL sDlg AS STRING
                                LOCAL w,RetVal AS LONG
                                w = INT(LEN(Param1) * 5)   ' width of winidow
                                IF w < 105 THEN w = 105
                                DlgTemplate_Create sDlg, _
                                                  &H084C000D4&, _
                                                  0, _
                                                  0, _
                                                  %CW_USEDEFAULT, _
                                                  %CW_USEDEFAULT, _
                                                  (w + 40), _
                                                  30, _
                                                  "", _
                                                  "", _
                                                  Param1, _
                                                  0, _
                                                  400, _
                                                  0, _
                                                  "MS Sans Serif"
                            
                                DlgTemplate_AddControl      sDlg, _
                                                        14, _
                                                        9, _
                                                        (w-28), _
                                                        12, _
                                                        101, _
                                                        0, _
                                                        %WS_TABSTOP OR %WS_VISIBLE OR %WS_BORDER OR %ES_LEFT OR %ES_AUTOHSCROLL, _
                                                        %WS_EX_CLIENTEDGE OR %WS_EX_LEFT, _
                                                        "EDIT", _
                                                        "", _
                                                        ""
                            
                                DlgTemplate_AddControl      sDlg, _
                                                        w, _
                                                        9, _
                                                        30, _
                                                        14, _
                                                        %IDOK, _
                                                        0, _
                                                        %BS_PUSHBUTTON OR %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _
                                                        0, _
                                                        "BUTTON", _
                                                        "OK", _
                                                        ""
                            
                                sDlg = sDlg + CHR$(0)
                              RetVal = DialogBoxIndirectParam(GetModuleHandle(""), BYVAL STRPTR(sDlg), 0, CODEPTR(DlgProc), 0)
                              IF RetVal = -1 THEN
                                 PRINT "No Go"
                                 WAITKEY$
                              END IF
                            
                            END FUNCTION
                            '==============================================================================
                            FUNCTION _
                                DlgProc ( _
                                  BYVAL hDlg      AS DWORD,_
                                  BYVAL wMsg      AS DWORD,_
                                  BYVAL wParam    AS DWORD,_
                                  BYVAL lParam    AS LONG _
                                ) AS LONG
                            
                                SELECT CASE wMsg
                                    CASE %WM_INITDIALOG
                                        CenterWindow hDlg
                                    CASE %WM_COMMAND
                                        IF LO(WORD,wParam) = %IDOK THEN
                                            IF HI(WORD,wParam) = %BN_CLICKED THEN
                                                UserName = STRING$(GetWindowTextLength(GetDlgItem(hDlg,101))+1,32)
                                                GetWindowText GetDlgItem(hDlg,101),BYVAL STRPTR(UserName),LEN(UserName)
                                                SendMessage hDlg,%WM_CLOSE,0,0
                                            END IF
                                        END IF
                                    CASE %WM_CLOSE
                                        EndDialog hDlg,1
                                END SELECT
                            END FUNCTION
                            '==============================================================================
                            FUNCTION PBMAIN() AS LONG
                            
                                InputFunction "Enter Name"
                                ? UserName
                                WAITKEY$
                            END FUNCTION

                            Comment

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