Welcome! Log In Create A New Profile

Advanced

Read/write variables passed in wParam/lParam

Posted by Sohan 
Sohan
Read/write variables passed in wParam/lParam
September 27, 2008 04:40AM
Hi,

I am trying to prevent the user from moving a window. This can be done by trapping WM_MOVING. The message passes a RECT structure in lParam. According to the documentation, if you set the structure members (i.e. X and Y coordinates) back to their previous values, the move can effectively be undone.

The question is: how can this be done in WL? I would need a WL structure variable which maps to the address passed in lParam. Is this possible?

At the moment, I simply manipulate MyWindow..X/Y to put the window back to its previous position. This works fine, but the window 'trembles' a bit, as a result of first being moved and then put back again. I am looking for a more elegant solution.

TIA,
/sohan
Piet van Zanten
Re: Read/write variables passed in wParam/lParam
September 27, 2008 09:57AM
Hi Sohan,

Indeed you need to setup a WL structure exactly equal to the RECT structure. You can pass the RECT structure to the WL structure using transfer. Then you change the members and transfer it back to the RECT structure.

Regards,
Piet
BLS
Re: Read/write variables passed in wParam/lParam
September 27, 2008 03:19PM
Hello Sohan,

Piet is right, a few lines of code may help ...

// You need this structure
RECT is structure
	left is int //Type C : LONG
	top is int //Type C : LONG
	right is int //Type C : LONG
	bottom is int //Type C : LONG
END

// Your Eventhandler procedure should be similar to this one :
PROCEDURE OnMoving(msg, wParam, lParam)
    //Let's modify the left, and top values of the rectangle structure lParam is pointing to.
    r is RECT
    r:left = originalLeftValue
    r:top = originalTopValue
    // note that lParam is a pointer to a RECT structure
    Transfer(lParam, &r, Dimension(r))
    
RESULT true
// In case that you need the data lParam is pointing to :
    Transfer(&r, lParam, Dimension(r))
// Transfer Syntax : Transfer(destination, source, size)

HTH, cose is untested !
Bjoern

Sohan
Re: Read/write variables passed in wParam/lParam
September 27, 2008 07:30PM
Thanks Piet, Bjoern, it works like a charm!

I thought that I was supposed to use a dynamic structure and make it refer to the lParam address. I tried things like:

r is RECT dynamic = lParam
r is RECT dynamic = &lParam

It never occurred to me that I could use an instantiated structure and *copy* its data to the external address.

Thanks again,
/sohan
BLS
Re: Read/write variables passed in wParam/lParam
September 27, 2008 07:52PM
Quote
Sohan
Thanks Piet, Bjoern, it works like a charm!

I thought that I was supposed to use a dynamic structure and make it refer to the lParam address. I tried things like:

r is RECT dynamic = lParam
r is RECT dynamic = &lParam

It never occurred to me that I could use an instantiated structure and *copy* its data to the external address.

Thanks again,
/sohan

Well Sohan, the Transfer() function is like memcpy() in C, respective RtlCopyMemory() offered by the Windows API.

To have fun, or just to better understand it :
    lParam += 4  
    // lParam is pointing to r:_left .. + 4 means lParam is NOW pointing to r:_top
    // int size is 4 byte so  ->    increase lParam with 4
  
   __top  is int = originalTopValue
 
    Transfer(lParam, &__top,  4)
As always ... just an ad hoc hack... not tested
Got it ?
Kind regards,

Bjoern Lietz-Spendig
WiNDEV - C/ C++ bindings, API programming, D programming
Sohan
Re: Read/write variables passed in wParam/lParam
September 28, 2008 12:54AM
Hi Bjoern,

I understand the concept of memory addressing. I was just caught up in thinking that a Windev variable should *refer* to the given address, instead of a local variable which is *copied* to this address. Ah well, I probably shouldn't have started working on this on a friday ...

Thanks for your remarks.

Cheers,
/sohan
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: