unique variables for every instance of a window class?

Started by mennowo, July 10, 2013, 04:56:02 PM

Previous topic - Next topic

mennowo

Hello,

I'm trying to make small floating windows to drag over the screen and place on top of other window. They are without anything special, just basic squares with a color. Making this kind of window and dragging them over the screen was rather easy, but now I run into trouble trying to have every window respond differently.

Every instance of the window class seems to utilize the same window proc, therefore sharing static variables. For my purposes, this is not good: the different windows should have their unique set of variables, including pointers, so as to be able to read data from arrays that belong to the parent window.

Is there a way to do this? Some other method to transfer unique information to each seperate instance of a window class, in order (for example) to paint them all in a unique way?

Any help appreciated!

Menno

TimoVJL

May the source be with you

frankie

Create dynamic memory associated with each window than store the pointer to private memory in GWL_USERDATA.
To set retrieve data see SetWindowLongPtr and GetWindowLongPtr
Free dynamic memory when destroying the window (WM_DESTROY).
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

mennowo

Thanks for the very fast responses!
Looking a little further I also found this tutorial which deals exactly with my problem:
http://www.catch22.net/tuts/custom-controls
"At this point you will hit a stumbling block. The problem is, your custom window procedure is a simple callback function, which processes all messages for all custom controls you create."
Sorry if I was a bit hasty posting this question, I had already spend quite a while trying to manage this...