If i set the cbWndExtra of a window class to "sizeof(struct RECT *)", how do i use those extra bytes?
Posted on 2002-07-05 19:17:13 by ChimpFace9000
use GetWindowLong and SetWindowLong. for example:

invoke SetWindowLong, hWnd, 0, ADDR rcRect

this will set the address of rcRect to the first 4 bytes of the extra memory allocated. to retreive it:

invoke GetWindowLong, hWnd, 0
Posted on 2002-07-05 21:43:56 by Sloat
In that example you are only using the 4 bytes to store a pointer, where 16 was reserved to store just the data. As well the Get/SetUserLong style to use is "GWL_USERDATA" for normal windows and "DWL_USER" for dialog boxes. (Instead of the '0' parameter indicated above). Actually the "0" null is incorrect anyways, so i assume windows defaults to this style if the value is not found:
GWL_WNDPROC                          equ -4

GWL_HINSTANCE equ -6
GWL_HWNDPARENT equ -8
GWL_STYLE equ -16
GWL_EXSTYLE equ -20
GWL_USERDATA equ -21
GWL_ID equ -12



You can reserve up to 40 bytes of info this way in every window, but typically it is only used to store 4 (an adress pointer) in pratice. This is done just as Sloat has shown you. The catch is you still need to have allocted memory to point to, before you store it's pointer here.

Im not sure how to access the bytes beyond the first 4, as Get/SetWindowLong only gives you the VALUE found at the first 4 bytes of allocated memory in its EAX return. It would be nice to somehow get eh ADDRESS of this extra memory (and im sure there is an api to do this), but at the moment i dont know it.

If you do get the address, the you dont need to allocate more memory, just to get a pointer to it and place it into the window long data. I will re-itterate tho, you only get up 40 bytes this way anyways! So for large amounts of data to be stored, its best to go with the method Sloat as shown you...


my 2 cents ;)
:alright:
NaN
Posted on 2002-07-06 01:58:26 by NaN
I *assumed* that any bytes allocated beyond the first four would be accessible by doing something like:

long0=GetWindowLong(hWnd,0);
long1=GetWindowLong(hWnd,4);
long2=GetWindowLong(hWnd,8);


Can anyone verify if this assumption is correct?
Posted on 2002-07-06 04:03:26 by AmkG
Quoting PlatformSDK:

Specifies the zero-based offset to the value to be retrieved. Valid values are in the range zero through the number of bytes of extra window memory, minus four; for example, if you specified 12 or more bytes of extra memory, a value of 8 would be an index to the third 32-bit integer. To retrieve any other value, specify one of the following values.


NaN, I don't think there's any way to get a pointer to the window
memory...
Posted on 2002-07-06 09:22:51 by f0dder
Yes, using the value 0 would set or retrieve the 4 bytes that he has allocated. But one could just as well use GWL_USERDATA. In that case, one doesn't have to reserved any additional bytes. Note that for dialog boxes, you must reserve at least 30 bytes. In conclusion, you can store up to 44 bytes with the window without allocating more memory.
Posted on 2002-07-06 09:58:06 by Sephiroth3