views:

9

answers:

1

I'm creating modeless child dialogs from a parent dialog class and i want to share the class data of its parent window with all child dialog classes I'll be creating. how would i go do that?

A: 

One way of doing it is to use SetWindowLongPtr():

SetWindowLongPtr(hwndParent, GWLP_USERDATA, (LONG_PTR)&parent_class);

This will set the USERDATA field on the parent hwnd to be the address of the parent class. Then in your WM_INITDIALOG handler, call GetWindowLongPtr() on your parent HWND and cast it back to the correct pointer type.

A better way to do it is to use CreateDialogParam() and in your WM_INITDIALOG handler you'll get the value you pass in the dwInitParam field, which would be the pointer to your parent class.

jeffamaphone