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?

2
  • Can you elaborate on what you mean by class data? The WindowClass or a pointer to your class that implements the parent? And how are you creating the child dialog (what API call)?
    – i_am_jorf
    Jul 19, 2010 at 0:25
  • I want to access the functions of parent class into child class and i'm creating the child dialog by creating an instance of child class inside parent class which uses CreateDialog API.
    – Kevin
    Jul 19, 2010 at 0:39

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.