Need variable in callback to retain its value, cannot be static

Need variable in callback to retain its value, cannot be static

Post by William Payn » Thu, 15 May 2003 10:00:51



Hello, I have a callback function (mdi client window procedure) and I need
to have a variable that retains its value between calls, but it cannot be
static. Is globals the only way to solve this?

// William Payne

 
 
 

Need variable in callback to retain its value, cannot be static

Post by Tim Robinso » Thu, 15 May 2003 16:36:12



Quote:> Hello, I have a callback function (mdi client window procedure) and I need
> to have a variable that retains its value between calls, but it cannot be
> static. Is globals the only way to solve this?

No. In general, the best way of associating some data with a window is to
allocate a structure of each, using new or malloc, then store a pointer to
it in one of the slots Windows gives you.  You can use
SetWindowLong/GetWindowLong(GWL_USER) or SetProp/GetProp for this.

--
Tim Robinson (MVP, Windows SDK)
http://www.themobius.co.uk/

 
 
 

Need variable in callback to retain its value, cannot be static

Post by William Payn » Thu, 15 May 2003 21:24:19





> > Hello, I have a callback function (mdi client window procedure) and I
need
> > to have a variable that retains its value between calls, but it cannot
be
> > static. Is globals the only way to solve this?

> No. In general, the best way of associating some data with a window is to
> allocate a structure of each, using new or malloc, then store a pointer to
> it in one of the slots Windows gives you.  You can use
> SetWindowLong/GetWindowLong(GWL_USER) or SetProp/GetProp for this.

> --
> Tim Robinson (MVP, Windows SDK)
> http://www.themobius.co.uk/

Thanks, I will do that.
 
 
 

1. HELP! Cannot read/write static variable from main()

Hello!

Can you help me? Ive got a big problem.
Im using MS Visual C++ and would like to have some
global variables I can reach from the main program and
from all classes Ive derived from a class called:  "mother"

Ive a headerfile mother.h containing the following:

class mother
{
public:
  static int test;
...

And my  main program contains:

#include <mother.h>
main()
{
     mother::test = 1;

This should work, shouldnt it?
It dosnt. I get a link error  LNK2001: unresolved external symbol in
main.obj ....

Even, if I try to write/read "test" using any code "mother.cpp", I get
the LINK ERROR.

I cant read/write that static variable from nowhere.
What can I do to have a static variable declared in a motherClass, which

I can reach from anywhere?

Which Linker Settings (DLL, etc. do I have to change??)
Whats going wrong?

Please help me.

Yours,
Ingo

2. Getting started with OpenDoc

3. DLL Callback fn from static app lib using Smart Callbacks!

4. Software Wanted

5. retain or not retain on init?

6. GDOS Support for Non-Atari Laser Printers???

7. Static variables and ordinary variables

8. Faulty Chip mem?

9. static variables in DLLs and local variables in FORTRAN

10. static variables vs global variables vs performance

11. Need help exporting static member variables

12. Static Variable using Another Static problem

13. static variables declared inside of non-static member functions