NO

Author Topic: unique variables for every instance of a window class?  (Read 3130 times)

mennowo

  • Guest
unique variables for every instance of a window class?
« on: July 10, 2013, 04:56:02 PM »
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

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: unique variables for every instance of a window class?
« Reply #1 on: July 10, 2013, 05:22:59 PM »
Examine WNDCLASS cbClsExtra and cbWndExtra
May the source be with you

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: unique variables for every instance of a window class?
« Reply #2 on: July 10, 2013, 05:24:47 PM »
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).
« Last Edit: July 10, 2013, 05:27:39 PM by frankie »
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

mennowo

  • Guest
Re: unique variables for every instance of a window class?
« Reply #3 on: July 10, 2013, 05:28:16 PM »
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...