We have a struct defined as :

typedef struct tagWINDOWPOS { /* wp */
   HWND hwnd;
HWND hwndInsertAfter;
int x;
int y;
int cx;
int cy;
UINT flags;
} WINDOWPOS;

Then we are sent a message...

WM_WINDOWPOSCHANGING
    WPARAM wParam
LPARAM lParam;
Parameters
wParam
This parameter is not used.
lParam
Pointer to a WINDOWPOS structure that contains information about the window's new size and position.

And this is the code which gets the message

case WM_WINDOWPOSCHANGING:
    WINDOWPOS * pWinPos;
pWinPos = lParam;
break;

lParam contains the address of the struct. Here we want to access to the struct.
But there is a problem with the code. pWinPos is a constant pointer, so we can't simply assign an address to it.

So, finally, here is my question...
How can I access to the WINDOWPOS struct whose address is given by lParam

pWinPos is not constant. but you do need a cast. either an old c style or a reinterpret_cast<WINDOWPOS*>(lParam)

Is

WINDOWPOS wp;
WINDOWPOS * pwp;
pwp = &wp;

convenient?

Then we can access to the sub-fields this way :

pwp->x
pwp->uflags
etc...

i prefer....

WINDOWPOS* wp = (WINDOWPOS*)lParam;

Thanks.
Type conversion works well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.