Announcement

Collapse
No announcement yet.

Dialog Show Modal

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

  • Dialog Show Modal

    Syntax: DIALOG SHOW MODAL hDlg [[,] CALL callback] [TO lResult&]

    According to the help:
    lResult&
    When the modal dialog is destroyed using the DIALOG END statement, the resulting value is assigned to the lResult& variable, if specified. lResult& is excluded from becoming a Register variable by the compiler, since this value can be assigned from outside of the function containing the DIALOG SHOW MODAL statement, and this may only be performed with a memory variable. However, if the target variable is explicitly declared as a register variable, PowerBASIC raises a compile-time Error 491 ("Invalid register variable").
    What value is assigned to the lResult& variable?

    Is the same result assigned if the user clicks on the system close dialog button?

    If I trap the %WM_DESTROY message and set "FUNCTION =" will that be returned to the lResult& variable?
    Walt Decker

  • #2
    Not a DDT programmer here, but in sdk when you call EndDialog() to end a modal dialog box one has the option of returning any value one wishes as the second parameter to the EndDialog call...

    Code:
    BOOL EndDialog
    (
      HWND hDlg,    // handle to dialog box
      int nResult   // value to return
    );
    We're talking about the 'int nResult' parameter. I imagine that is what the DDT dialog engine is placing in lResult. Sometimes its nice to return some value obtained from a text box in the dialog, sometimes just a %TRUE or %FALSE. In terms of how it gets assigned, I'm assumming that is the same as with sdk, i.e., the programmer has to assign the value in code within the 'Callback' function. Typically, a dialog box will have 'OK' and 'Cance' buttons, or things like that. When these are executed it is up to the programmer to obtain whatever values are necessary from the controls in the dialog box and return them through the function call mechanism. The same would be true in dealing with [x] buttons. Hope this helps. I'm basing what I said on sdk, but I can't imagine in broad outline it would be much different with DDT.
    Last edited by Fred Harris; 12 Feb 2008, 09:46 PM.
    Fred
    "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

    Comment


    • #3
      It's the value sent by the second parameter of DIALOG END
      kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

      Comment


      • #4
        Well, what I need to do is determine whether a user wants to continue setting up parameters or quit the application. My thought is something like this:

        Code:
        FUNCTION PBMAIN()
        
        LOCAL lRes AS LONG
        
        lRes = StartDlg(0, 1)
        
        IF lRes > 0 then
          lRes = StartDlg(0, 2)
        END IF
        END FUNCTION
        
        FUNCTION StartDlg(BYVAL hDlg AS LONG, BYVAL Flag AS BYTE)
        
        LOCAL lRes AS LONG
        
        ' DIALOG SETUP CODE
        
        DIALOG SHOW MODAL, CALL StartDlgCB TO lRes
        
        FUNCTION = lRes
        END FUNCTION 
        
        CALLBACK FUNCTION StartDlgCB()
        
        STATIC lRes AS LONG
        
        'CALLBACK HANDLING CODE
        
          CASE %WM_DESTROY
             IF lRes THEN FUNCTION = lRes
        
        END FUNCTION
        So, I'm wondering if setting "FUNCTION = " to some value sets lResult& in the show modal statement. If not, I'll have to come up with another solution.
        Walt Decker

        Comment


        • #5
          No that can't be done as the result from WM_DESTROY is lost. If you trap WM_SYSCOMMAND (the close button/Alt+F4), then you can use DIALOG END to return the result:

          Code:
          CALLBACK FUNCTION StartDlgCB()
           
            STATIC lRes AS LONG
           
            SELECT CASE CONST CBMSG
           
                   CASE %WM_SYSCOMMAND
                        IF (CBWPARAM AND &HFFF0) = %SC_CLOSE THEN
                           ' User closing dialog...
                           DIALOG END CBHNDL, lRes
                           ' Do this to stop Windows closing the dialog...
                           FUNCTION = %TRUE
                        END IF
           
            END SELECT
           
          END FUNCTION
          Last edited by Kev Peel; 12 Feb 2008, 10:23 PM.
          kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

          Comment


          • #6
            Thanks, Kev. That seems like a redundant way to do it. I think I'll look at another option before I do that one.
            Walt Decker

            Comment


            • #7
              note:
              Code:
                      Case %WM_SYSCOMMAND 'Traps Any Alt key but only F4 closes              
                            ?Using$("Alt Key pressed " & $CrLf & _
                                    "    CbMsg = #" & $CrLf & _
                                    "    CbCtl = #" & $CrLf & _
                                    " CbCtlMsg = #", _
                                    CbMsg, CbCtl, CbCtlMsg)
              Dunno what value (the info) may have but just thought it curious.
              It's a pretty day. I hope you enjoy it.

              Gösta

              JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
              LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

              Comment


              • #8
                Just my two cents worth on Dialog End and lresult&. I've found it useful when I want an application to gracefully close files, etc before it ends to always react to that value. I've found that clicking the X to close a dialog will always return a 0 to lresult&, hence I trap that and make it branch to shutdown code for the program before I EXIT FUNCTION.

                If I use Child dialogs as message boxes I use the lresult to branch to new appropriate dialog or processing code based on choices made in the popup dialog.

                Bob Mechler

                Comment


                • #9
                  If the dialog is shown modally we can assume variables in that procedure and declared before the dlg creation, then we are able to set a pointer to this variable by using SetProp() API like (pseudo):

                  Local nResult as Long

                  Dialog create to hwnd
                  Setprop( hWnd, "result", Varptr( nResult ) )
                  Dialog show modal

                  In the dlg proc:
                  Local nResult as Long ptr
                  nResult = GetProp( cbhndl, "result" )
                  @nResult = 1234

                  Don't forget to remove the property on WM_DESTROY.
                  hellobasic

                  Comment

                  Working...
                  X