News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Some words on User defined Controls.

Started by xandaz, January 21, 2012, 05:30:49 PM

Previous topic - Next topic

xandaz

   Hi guys. I passed the day trying to understand how to create user defined controls. I managed to create my own Static Control and i feel like sharing. It looks kinda crapy but it works fine tho simple.
   Thanks guys.

qWord

the next step would be to make your control independent from global variables, thus it can be used more than one time (also: thread save).
You can do this by allocating extra memory with the class or by using window-properties (Get/SetProp()).
FPU in a trice: SmplMath
It's that simple!

xandaz

   Yes q. I'm just in an early stage of study. Also... something wierd happened. Those variables in the .data after the control proc were previously declared inside the control proc but there was data-loss. Do you know why? Thanks Q.
    Bests and later all.

xandaz

   ooops... i meant before the .data instead of after.

xandaz

   Hey Qw. I've reading the API ref and the Get/SetProp functions are used for strings or atoms (which can be only 16 bit because for what i've read only the LOWORD is used). Have i misunderstood something or should i just cbWndExtra? Thanks.
   Later guys

qWord

Quote from: xandaz on January 21, 2012, 07:05:08 PM
   Hey Qw. I've reading the API ref and the Get/SetProp functions are used for strings or atoms (which can be only 16 bit because for what i've read only the LOWORD is used). Have i misunderstood something or should i just cbWndExtra? Thanks.
   Later guys
A property is identified by a string OR by an atom. The properties value is a DWORD (hData = HANDLE = PVOID = any 32 bit value).

The following schematic shows both methods:
Set/Get/RemoveProp:
CNTRL_DATA struct
value1 DWORD ?
value2 DWORD ?
;...
CNTRL_DATA ends

WM_CREATE:
mov ebx,alloc(SIZEOF CNTRL_DATA)
fn SetProp,hWnd,"pCntrlData",ebx
mov [ebx].CNTRL_DATA.value1,...
...
WM_WHATEVER:
mov ebx,rv(GetProp,hWnd,"pCntrlData")
; ebx = ptr CNTRL_DATA
...
WM_DESTROY:
mov ebx,rv(GetProp,hWnd,"pCntrlData")
; free resources
free ebx
    fn RemoveProp,hWnd,"pCntrlData"


class extra mem:
...
mov wc.cbWndExtra,SIZEOF PVOID
...

WM_CREATE:
mov ebx,alloc(SIZEOF CNTRL_DATA)
invoke SetWindowLong,hWnd,0,ebx
mov [ebx].CNTRL_DATA.value1,...
...
WM_WHATEVER:
mov ebx,rv(GetWindowLong,hWnd,0)
; ebx = ptr CNTRL_DATA
...
WM_DESTROY:
mov ebx,rv(GetWindowLong,hWnd,0)
; free resources
free ebx


Which to use? - it your decision, but the second one (cbWndExtra) is probably faster.
FPU in a trice: SmplMath
It's that simple!

xandaz

   Yeah... Guess i'll do that. I've been trying to do some controls in library format but i had some problems with STRUCT. Im not very keen on this macro stuff but it errors. I made this StdWindow example from the template i have qeditor and inserted a struct and it errors too. Says index value past end of string or something. Can someone look? Just assemble the example and see what happens.
    Thanks and later

qWord

FPU in a trice: SmplMath
It's that simple!

xandaz


xandaz

   anyway...if i use GetWindowLong,hWnd,0 it'll returned the pointer to WndExtra? or the value of the first dword?
   Does the pointer change? ...for instance from one message to the other?

qWord

Quote from: xandaz on January 23, 2012, 01:06:31 AMif i use GetWindowLong,hWnd,0 it'll returned the pointer to WndExtra? or the value of the first dword?
The first DWORD is returned. For 4 the second, for 8 the third,...
Quote from: xandaz on January 23, 2012, 01:06:31 AMDoes the pointer change? ...for instance from one message to the other?
no - each window will have its own memory.
FPU in a trice: SmplMath
It's that simple!

xandaz

   Thanks.  But is there a way to get the pointer and then change memory through register opperations? like
GetWindowLongPtr,hWnd,GWLP_USERDATA
mov edi,eax
invoke CreateCompatibleDC,[edi].ps.hdc
movm [edi].hMemDC,eax
etc...

or do i need to SetWindowLong everytime i need to change variables in the memory?
Thanks