Announcement

Collapse
No announcement yet.

Sending values to a CALLBACK FUNCTION

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

  • Sending values to a CALLBACK FUNCTION

    What is the correct method for doing this?

    I dont want to use a global variable cos im creating a window
    with a function that can be called from different apps.
    The function is #INCLUDED into each app as needed and I dont want
    to have to add a bunch of Globals to each app.

    To simplify the problem lets say I want to send the starting value
    for say a COMBOBOX. The app that calls the function and passes the
    number of the desired item to be displayed first.

    When I create a new window with the COMBOBOX in it, i need to pass
    that number to the CALLBACK FUNCTION.

    The problem is the callback function does not allow for arguments.

    How do you guys deal with this?

    Code:
    CALLBACK FUNCTION SelectCB() AS LONG
    SELECT CASE CBMSG
        CASE %WM_INITDIALOG
            COMBOBOX SELECT CBHNDL, 201, StartVal' Set MsgBox to desired Item
    '
    '
    '
    END SELECT
    END FUNCTION
    ------------------
    Kind Regards
    Mike

    [This message has been edited by Mike Trader (edited August 19, 2001).]

  • #2
    Global is the simple way. If this is an include file, make the
    global there and if included several times, just set a constant
    around that global with the following:

    Code:
    $IF NOT %DEF(%I_SET_THAT_GLOBAL)
     Global funky as Long
     %I_SET_THAT_GLOBAL = 1
    $ENDIF
    You need to use a global. Look in Win32API to see how they handle
    it if this is not clear.

    ------------------
    Barry

    Comment


    • #3
      Not to disagree with Mr. Erick, but using the DDT callbacks there is no way to pass a parameter to the callback function. OF course, you can generally retrieve any info about a DDT-control within the dialog callback.

      As far as the WinAPI, the standard control messages only allow for user data for a limited number of controls (e.g, the listview control), and even then it's limited.

      Of course, if you write your own callbacks, you can do darn near anything.

      In this case (pass a value to a 'library' procedure), DialogBoxParam or CreateDialogParam will let you pass a parameter (accessible as lparam when processin WM_INITDIALOG) to a dialog.

      And, there's always the Windowextra fields, but unless I'm mistaken, those fields are reserved for both Windows' and DDT's use, and you'd really need to register a class to take advantage of them.

      MCM



      [This message has been edited by Michael Mattias (edited August 19, 2001).]
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Folks, of course there are ways to send values to a callback - this method is at the heart of GUI programming - it is called MESSAGING.

        For example, you can do it with a registered (custom) window message (see RegisterWindowMessage) or send a %WM_USER message.

        Basically, you set the WPARAM/CBWPARAM and LPARAM/CBLPARAM to the value you want to pass. You can also pass pointers as one or both of the parameters too.

        For example:
        Code:
        DIALOG SEND hDlg, %WM_USER + 999, p1&, p2&
        ...
        CALLBACK FUNCTION dlgproc
          SELECT CASE CBMSG
            CASE %WM_USER + 999
              P1 = CBWPARAM : P2 = CBLPARAM
              ... do something with these values
              FUNCTION = 1
          END SELECT
        END FUNCTION

        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:lan[email protected]

        Comment

        Working...
        X