A while back I was writing a C++ program with the Win32 API that would display a dialog box and then listen to the messages it generated. At one point, I was interested in associating a piece of data with the dialog window. Were I manually creating the window and attaching a window proc, I'd just use SetWindowLongPtr
to set the GWLP_USERDATA
field to a pointer to the data to associate. However, in this case I was creating and displaying the window with DialogBoxParam
, and it wasn't clear whether this function was associating that data with its own internal state. Since the MSDN didn't have a description of what would happen in this case, I ended up using some other approach to solve the problem.
My question 开发者_StackOverflow社区is this - is it safe to use SetWindowLongPtr
to overwrite the GWLP_USERDATA
value in a window created by DialogBoxParam
?
Technically, the GWLP_USERDATA is for the use of the (base in the case of subclassing) window class to use. Because dialogs are a ready made class, GWLP_USERDATA is for internal use - whihc is why dialogs supply a DWLP_USER field for your DialogProc implementation's use.
As things stand however, all the internal window classes supplied by Microsoft - EDIT, BUTTON, Dialog and so on, do not, and cannot use GWLP_USERDATA for application compatibility reasons, so they are effectively available for the application to use.
精彩评论