I think I am missing something basic here. Maybe I describe what I am trying to do:
I want to display a dialog with 2-3 buttons and some text. When the user clicks one of the buttons I want to display to him as text the contents of a struct. I have the struct in main and I do not know how to access it in the dialog's onButtonClick.
I thought it is done via lparam. So I expected to create the dialog with the struct in lparam and then the callback function will pass it along to onButton clicked. (Maybe this is not the right way to do that)
So I expected to create the dialog with the struct in lparam and then the callback function will pass it along to onButton clicked. (Maybe this is not the right way to do that)
According to MSDN it is passed in not "along to onButton clicked" notification but as LPARAM with WM_INITDIALOG message!
So handle WM_INITDIALOG message, cast the passed in LPARAM to your struct pointer and save somewhere to data of this structure. Then you'll be able to use this data for your dialog.
You don't need WM_INITDIALOG or LPARAM. Looks like you were headed in the right direction in your first post. You can create and set member variables in the dialog and set them after you instantiate but before you Create the dialog. Once you do that, you can access them at any time inside the dialog. You could create individual members and copy them from the struct, or just declare a pointer to your struct, and populate it.
OK. Now I can access struct's members when I catch WM_INITDIALOG in my custom onInitDialog().
I still do not understand how to access/pass this struct from/to onButtonClicked().
Do you or don't use any C++ framework? If you do, Arjay is right, and you never need it be a separate structure. But if you don't, you need to invent some mechanism that allows the structure address be found by dialog window handle. Global map, or SetProp/GetProp typically do the trick.
Bookmarks