Announcement

Collapse
No announcement yet.

More Requests!

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

  • More Requests!

    Hello Guys and Girls!

    Well, I just thought of another REALLY cool addition to PBDLL...

    I would love to be able to send parameters with callback functions. This would help passing variables between callbacks without the need for globals.

    Code:
    callback function dlgproc(byval long, byval asciiz ptr, ...
    dialog show hdlg call dlgproc(flags, datafile, etc...
    The reason this came up was because I have a dialog box with some buttons on it. Each button has been subclassed to its own callback function handler. One button creates another dialog box and its associated callback. Inside that callback function there are some chunks of code that need to read data from a textbox in the main dialog... (hope that made sense)

    I guess what I would really like is to be able to share variables with other callback functions without having to use globals. I have spent a good amount of time learning NOT to use globals...(smile)

    What do you think?

    -------------
    Cheers

  • #2
    I'm probably not understanding your question, but why not access the text of the control directly? I use this (probably poorly written) routine to do that:

    Code:
    FUNCTION GetDlgText(BYVAL hDlg AS LONG, BYVAL CtrlID AS LONG) AS STRING
        DIM lngTextLength AS LONG
        DIM strTempBuffer AS STRING
        lngTextLength=GetWindowTextLength(GetDlgItem(hDlg, CtrlID))
        strTempBuffer=SPACE$(lngTextLength + 1)
        GetWindowText GetDlgItem(hDlg, CtrlID), BYVAL STRPTR(strTempBuffer),lngTextLength + 1
        FUNCTION = strTempBuffer
    END FUNCTION
    Pass it the hWnd to the Dialog and the control ID of the text box and there you have it. But that may require you to have the hWnd of the Dialog in a global, but you were going to have to have it anyway to send that dialog a message to one of its callbacks, right? I'm sure there's some very clever way of getting the handle of a dialog given its resource id or class name, but it's not coming to me at the moment... but that one global would serve you for every child item on the dialog...

    Well anyway, now I'm confused again, but maybe this will help.

    [This message has been edited by Troy King (edited May 27, 2000).]
    Troy King
    katravax at yahoo dot com

    Comment


    • #3
      Windows provides a built-in way to associate data with controls and windows, by using "properties". These can be used to remove the dependancy on GLOBAL variables.

      Take a look at SetProp(), GetProp(), EnumProps(), RemoveProp().


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

      Comment


      • #4
        Lance --
        It's necessary to use RemoveProp, ff a window is destroyed ?

        ------------------

        Comment


        • #5
          Absolutely! You should do this with the %WM_DESTROY handler.

          BTW, if you use child dialogs, use DestroyWindow() calls in the parents %WM_DESTROY handler to explicitly destroy the child dialogs, and hence guarantee than child dialog callback's can use RemoveProp().


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

          Comment


          • #6
            His question is pretty valid, had the same one myself a while back...Mine was on the same subclassing thing I believe, but I resolved my issue....

            However, This piece here caught my attention:

            GetWindowText GetDlgItem(hDlg, CtrlID), BYVAL STRPTR(strTempBuffer),lngTextLength + 1

            Can't that can be replaced with this?
            Control Get Text hDlg, CtrlID To strTempBuffer


            That's what is nice about DDT, HOWEVER his question is valid but Jim H helped me find a way around MOST of those issues, using CBWparam, cbmsg, cbLparam etc, so no handle has to be passed etc, but there are certain global strings that still gotta get there, and it would be nice to pass them via commandline to eliminate global variables..



            ------------------
            Scott
            mailto:[email protected][email protected]</A>
            MCSE, MCP+Internet
            Scott Turchin
            MCSE, MCP+I
            http://www.tngbbs.com
            ----------------------
            True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

            Comment

            Working...
            X