[comp.windows.ms.programmer] Windows extra bytes

neh@rci.dk (Niels Erik Holm) (05/16/91)

------------------------------------------------------------------------
How to get the address of the (internal) window structure ????
------------------------------------------------------------------------

Background:

There have been some articles concerning the topic:

   How to retrieve user-defined data based on the window handle ?

Several people have answered that one of the best way (and simplest) is
to use the cbWndExtra field when the window class is created, and use
GetWindowWord to access the values stored in the extra bytes. I have used 
this in the following way:

   struct ... table[MAX_WINS];	/* Structure array of any kind */

   hWnd = CreateWindow(....);	/* Create the window */
   index = get_free_entry();	/* Get free entry into table */
   SetWindowWord(hWnd,0,index);	/* Store the index in the extra bytes */

   ...

   ix = GetWindowWord(hWnd,0);	/* Retrieve the index */

What I would like to is to store the structure (not just the index) 
associated with the window in the extra bytes allocated behind the
(internal) windows structure.

   ...
   wc.cbWndExtra = sizeof(struct ...);
   ...
   RegisterClass(&wc);		/* Register the window class */


My question is now: How can I get the address of the windows structure ?
It is necessary to know the address in order to access the extra data area
efficiently.

Any help is appriciated.

Best regards.

Niels Erik Holm
RC International
Denmark
Mail address: neh@rci.dk
---------------------------------------------------------------------------
Every day, once a day, give yourself a present. Don't plan it, don't wait
for it, just... let it happen.  Could be a new shirt at the men's store,
a catnap in your office chair, or two cups of good, hot, black coffee.
(Dale Cooper in Twin Peaks).
---------------------------------------------------------------------------

kensy@microsoft.UUCP (Ken SYKES) (05/20/91)

In article <1991May16.080047.3388@rci.dk> neh@rci.dk (Niels Erik Holm) writes:
>
>What I would like to is to store the structure (not just the index) 
>associated with the window in the extra bytes allocated behind the
>(internal) windows structure.
>
>   ...
>   wc.cbWndExtra = sizeof(struct ...);
>   ...
>   RegisterClass(&wc);		/* Register the window class */
>
>
>My question is now: How can I get the address of the windows structure ?
>It is necessary to know the address in order to access the extra data area
>efficiently.
>

First thing to remember is that the window structure sits in USER's heap
and putting big structures in there will drain the system resources
quickly.  If you want to put a big structure (say, > 10 bytes or so) in
the window handle think about putting a Local or Global memory handle
in there instead.  

Now, if you want to put a small structure in there you can use a macro to
map a field in the structure to an index in the window and use GetWindowWord.
If you're really concerned about speed a fixed local memory handle is
probably your best bet.  Yank it out at the top of the function and then
you have your pointer to your structure.

Ken Sykes
Disclaimer: The above opinions are solely my own.