|
-
July 19th, 2010, 08:51 AM
#1
What is actually LPARAM, WPARAM & LRESULT in detail?
typedef UINT_PTR WPARAM;
typedef LONG_PTR LPARAM;
typedef LONG_PTR LRESULT;
What actually there are?
LPARAM & LRESULT. Can i cast of point them to a class object?
For example,
in a WndProc, and inside a switch case (maybe WM_CREATE), can I cast LRESULT to point to a RECT myrect and use it as return tp the WndProc
LRESULT CALLBACK WndProc (...)
{
.....
swith(Msg){
case WM_CREATE:
.....
return lresult;
break;
....
}
return : efWindowProc(hwnd, iMsg, wParam, lParam);
}
then in somehere else WndProc (a child window), i can do this to retrieve the pointer to the myrect such as
Rect rect = SendMessage(hwndparent, WM_CREATE, null, null);
It is possible? How do i cast it?
-
July 19th, 2010, 10:18 AM
#2
Re: What is actually LPARAM, WPARAM & LRESULT in detail?
Just numbers of certain size.
LPARAM & LRESULT. Can i cast of point them to a class object?
Yes. But you should take special care about referenced object: its life cycle must allow you to access it in message handler. Until it gets handled you must not do anything that results in object deletion/relocation.
Any C++ compliant way you do. Typically it happens by taking object address and casting it to corresponding xPARAM.
Last edited by Igor Vartanov; July 19th, 2010 at 10:24 AM.
Best regards,
Igor
-
July 19th, 2010, 10:24 AM
#3
Re: What is actually LPARAM, WPARAM & LRESULT in detail?
life cycle, you are right about it. I been put in my note from the beginning. Kind of dangerous if I miss it.
Can you show some example mate. Can I return a lresult (which point to a, say, a RECT) for the wndproc().
-
July 19th, 2010, 10:33 AM
#4
Re: What is actually LPARAM, WPARAM & LRESULT in detail?
Code:
// you can do this
RECT g_myRect = {0}; // of global scope
LRESULT CALLBACK WndProc (...)
{
.....
swith(Msg){
case WM_CREATE:
.....
lresult = reinterpret_cast<LRESULT>(&g_myRect);
return lresult;
....
}
return ::DefWindowProc(hwnd, iMsg, wParam, lParam);
}
Code:
// you cannot do that
LRESULT CALLBACK WndProc (...)
{
.....
swith(Msg){
case WM_CREATE:
.....
RECT myRect = {0}; // of function scope, to be destroyed on function return!!!
.....
lresult = reinterpret_cast<LRESULT>(&myRect);
return lresult;
....
}
return ::DefWindowProc(hwnd, iMsg, wParam, lParam);
}
Best regards,
Igor
-
July 19th, 2010, 10:41 AM
#5
Re: What is actually LPARAM, WPARAM & LRESULT in detail?
BTW, WM_CREATE is very rigid in aspect of returning LRESULT values.
Best regards,
Igor
-
July 19th, 2010, 10:55 AM
#6
Re: What is actually LPARAM, WPARAM & LRESULT in detail?
Hahahah. Just for example. Anyways, that clear me up and now I know why MS have wparam and lparam as one for numeric data and one can be cast to point to any object.
Learn one more thing today. Thanks Mate. Really, thanks. I been sitting here from 5.30pm after work today and now its 12am in Malaysia. But it really a rewarding day, today. coding come to several milestone, and then, you. Thanks
Last edited by Irwan; July 19th, 2010 at 11:01 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|