If so, what if I want to keep some information when one message is processed. Obviously I need to save such information in a global or static data. As the result, it makes window procedure non-reentrant.
I am not for sure what you're implying. You usually parse these message asap since they are only active during the procedure. If you feel the need to collect them for later, you can create a vector of messages.
What you say about global or static data is correct, but why not keep them in local variables? They would be located in the stack frame and each "call instance" of the window procedure would get its own set of them.
If I save them in local variables then next time I enter the window procedure again, I will lose them. So that is why I need to keep them in static or global variables. But that would make window procedure non-reentrant. I wonder if there is any requirement that Window procedure must be reentrant? Thanks.
Originally Posted by Eri523
What you say about global or static data is correct, but why not keep them in local variables? They would be located in the stack frame and each "call instance" of the window procedure would get its own set of them.
If I save them in local variables then next time I enter the window procedure again, I will lose them. So that is why I need to keep them in static or global variables.
Maybe a way to make that issue less severe is to limit static/global storage to certain message handlers rather than the entire window procedure. If you still got reentrance issues then, you might implement some syncronization stuff and/or something like the vector approach suggested by Joeman.
On the sidenote: That vector approach somehow resembles something like your own local message queue. Interesting picture...
If so, what if I want to keep some information when one message is processed. Obviously I need to save such information in a global or static data.
Absolutely not obvious. You may allocate a structure/object/memory and pass the pointer to CreateWindow. There in WM_CREATE handler you store it in window properties and use whenever you want that later.
Can you explain in more details how to allocate a structure/object/memory and pass the pointer to CreateWindow? I couldn't relate SetProp with CreateWindow. Thanks a lot.
Originally Posted by Igor Vartanov
Absolutely not obvious. You may allocate a structure/object/memory and pass the pointer to CreateWindow. There in WM_CREATE handler you store it in window properties and use whenever you want that later.
I enter the window procedure again, I will lose them. So that is why I need to keep them in static or global variables. But that would make window procedure non-reentrant. I wonder if there is any requirement that Window procedure must be reentran
If I want to show the time when the window was opened in the window last time, how can I do that by using SetProp and GetProp? If I save the time when processing WM_CREATE, then the time I get is always current time.
Thanks.
Originally Posted by Joeman
What You do is this
Code:
CreateWindowEx
(
0,
"class name here",
"window name here",
WS_OVERLAPPEDWINDOW | WS_VISIBLE ,
x,
y,
Width,
Height,
HWND_DESKTOP,
NULL,
Instance_Here,
(void*)this
);
I think it is a design issue not coding issue. Whenever I open the window, the time saved to a struct is always current time when processing WM_CREATE. Basically I want to get last time when the window was opened. But unfortunately the last time is always overwritten by current time.
Okey, here is my code. Basically I want to show last time when the window is opened. But current time is always shown instead. Would you please point out what mistake I made. Thanks.
You mean, some miracle happens in your program? Or silicon chips made a plot against you?
I hardly see the difference. Design issue? Is that your design? Then just fix it.
Bookmarks