Well, this is a tip as well as it is a question...
This is directly linked to the question i put some time ago, Hooks in Win2000.
When creating a window manager under Winx, it is often a good idea to mention some extra data in window structure (that is creating the window with cbWndExtra specifying the amount of extra data), such as a pointer to the next window, extra tips, or i don't know what other extra information u could think of. To access this information, you would use the SetWindowLong function and set the GWL_USERDATA info to your window structure, for example.
Then, when using a hook function, you can get the window handle in the function from the message that is passed to it, and then get the window extra data using GetWindowLong(hWnd,GWL_USERDATA).
Well this sounds swell, and it works fine under win9x, NT 4 etc...
It works also on win2000, but only as long as your using your own created windows.
If you are willing to open a System dialog - such as Colors dialog box, or Printer Dialog box - you will be surprised to see that the program simply crashes.
I spent great deal of time trying to figure out why that happens, and i discovered that the xtra data returned for those windows it isn't NULL, as it should be -or as it is in the other versions of windows-. So when i cast that value to my own structure pointer, and then try to dereferenciate it... CRASH-BOOM-BAANG...
My guess is that, starting with win2000, the window extra data is allocated and used internally by Win2000.
Or, it is a BUG, and that extra data isn't set to 0, as it is in other versions of windows, including NT.
I'm looking forward to hear some opinions on this.
It's a matter of portability here, so the idea is to run the same code on previous Windows versions and on win2000 and getting the same resutlt (well at least getting the best of it).
This is directly linked to the question i put some time ago, Hooks in Win2000.
When creating a window manager under Winx, it is often a good idea to mention some extra data in window structure (that is creating the window with cbWndExtra specifying the amount of extra data), such as a pointer to the next window, extra tips, or i don't know what other extra information u could think of. To access this information, you would use the SetWindowLong function and set the GWL_USERDATA info to your window structure, for example.
Then, when using a hook function, you can get the window handle in the function from the message that is passed to it, and then get the window extra data using GetWindowLong(hWnd,GWL_USERDATA).
Well this sounds swell, and it works fine under win9x, NT 4 etc...
It works also on win2000, but only as long as your using your own created windows.
If you are willing to open a System dialog - such as Colors dialog box, or Printer Dialog box - you will be surprised to see that the program simply crashes.
I spent great deal of time trying to figure out why that happens, and i discovered that the xtra data returned for those windows it isn't NULL, as it should be -or as it is in the other versions of windows-. So when i cast that value to my own structure pointer, and then try to dereferenciate it... CRASH-BOOM-BAANG...
My guess is that, starting with win2000, the window extra data is allocated and used internally by Win2000.
Or, it is a BUG, and that extra data isn't set to 0, as it is in other versions of windows, including NT.
I'm looking forward to hear some opinions on this.
It's a matter of portability here, so the idea is to run the same code on previous Windows versions and on win2000 and getting the same resutlt (well at least getting the best of it).