Announcement

Collapse
No announcement yet.

Extra window memory

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

  • Extra window memory

    Hello. I started using the extra window memory to store some window-related values, instead of using static/globals. The problem is, how to initialize the extra memory values on the window creation? I know the following:
    • The number of required extra bytes must be declared on the window class registration
    • On the window creation I must pass a pointer to the init values (lpParam)
    • On the %WM_CREATE message I must assign the lParam value to a CREATESTRUCT pointer
    • I must use the lpCreateParams item of CREATESTRUCT as a pointer to the init values. But...

    Windows NT: This member is the address of a SHORT (16_bit) value that specifies the size, in bytes, of the window creation data. The value is immediately followed by the creation data.
    The question is, how to use this lpCreateParams value? Must be used two ways, depending on the O.S. version?

    Thanks

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

    [This message has been edited by Aldo Cavini (edited September 10, 2001).]
    Rgds, Aldo

  • #2
    Found an article on MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/hh/winui/windows_06lu.asp)
    Windows NT/2000 or later: If the window is being created from a dialog template, this member is the address of a SHORT value that specifies the size, in bytes, of the window creation data. The value is immediately followed by the creation data.
    This quote is slightly different with respect what I quoted inside my first post (it was from Win32api.hlp). If the MSDN one is correct, hand created window behave all the same way, and all this forum is null (I tried it on Wn NT, and didn't find that SHORT value!). Please post a reply if is there something wrong.

    Thanks

    ------------------
    Rgds, Aldo

    Comment


    • #3
      If in doubt why not just use SetWindowLong( hWnd, %GWL_USERDATA, lDataPtr )
      and then GetWindowLong( hWnd, %GWL_USERDATA ) to retrieve the
      data?

      Cheers

      Florent

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

      Comment


      • #4
        Florent, thanks for the reply.

        I already use SetWindowLong and GetWindowLong. But they can be used only after the window was created. Are there other systems to pass a value you want to use during the window creation (i.e. inside the WM_CREATE message)?

        ------------------
        Rgds, Aldo

        Comment


        • #5
          You can do SetWindowLong in WM_CREATE
          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Michael,

            it isn't what I want. I'd like to use GetWindowLong inside the WM_CREATE message. Of course I can't use it, since the data isn't still stored. This is the reason I need to use some other method to pass the data. At the moment, to get the data pointer via the CREATESTRUCT type seems to work - I'd like to be confirmed this is not a wrong/dangerous method. Thanks anyway.

            ------------------
            Rgds, Aldo

            Comment


            • #7
              Aldo,
              One method is to call your Window Proc directly with a window handle of
              zero (before you create your window) passing your data pointer. Save it
              in a static var and use that until you receive your WM_CREATE message. Then you
              can store the pointer.

              James


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

              Comment


              • #8
                Sure, I use CreateStruct in one of my apps. works good. (That's an MDI application, so it uses MDICreateStruct, but I have to believe the "regular" one works just fine.

                Here's the code I use on WM_cREATE of the MDI child window to pass an ASCIIZ string:

                Code:
                  LOCAL pMdiC AS MDICreateStruct PTR
                  LOCAL pCC   AS CreateStruct    PTR
                   .....
                      CASE %WM_CREATE
                           pCC = lparam                 ' lparam = point to createstruct
                           pMDIC = @pcc.lpcreateparams  ' createstuct.lpcreateparms is pointer to mdicreatestuct
                           pZText = @pMDIC.lparam
                MCM
                (This would be a cool place for "C" type "casting", no?)


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

                Comment


                • #9
                  James,

                  thanks for the idea. I didn't think about directly calling the window proc. No way this method will fail.

                  Michael,

                  yes, I'm more or less conveinced getting the values I need via the CRATESTRUCT does the job. The problem is the remark I found inside the Win32api.hlp file - if it were true, all the programs using this method couldn't work under Win NT!

                  ------------------
                  Rgds, Aldo

                  Comment


                  • #10
                    If you are worried about getting a parameter to a DIALOG rather than a "standard window" you can use DialogBoxParam or CreateDialogParam.

                    Which reminds me...

                    Using DDT, I can't find a way to pass a parameter to a dialog.

                    A new feature might be the addition of a parameter option to DIALOG NEW or DIALOG SHOW, as in:

                    Code:
                    DIALOG NEW hParent&, title$, [x&], [y&], xx&, yy& [, style& [, exstyle&] [,Param&] TO hDlg&
                    OR...
                    Code:
                    DIALOG NEW   yadda, yadda
                    DIALOG PARAM hDlg, X&
                    CONTROL ADD  xxxxx
                    ....
                    DIALOG SHOW ...
                    Param would be available on the WM_INITDIALOG message of the dialogproc, maybe as CBUPARAM or something like that.

                    (I'm not sure when the dialog is created, on DIALOG NEW or DIALOG SHOW).

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

                    Comment

                    Working...
                    X