Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a DialogBox from within a DialogBox

Status
Not open for further replies.

NormRumac

Programmer
Sep 4, 2003
41
0
0
CA
Hi.

I have one dialog box window containing a button, which, once the user clicks on it, pops up another dialog box prompting the user for some input.

The code is (something) like this:

BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BUTTONPRESS:
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE (IDD_GETUSERINPUT),hwnd, UserInputDlgProc);
break;
}
.
. <= rest of code here
.
}

The code works from the sense that the 2nd dialog box pops up when the user clicks the button. However, what is the *correct* way to obtain the inputted user value from the 2nd dialog box? The above function needs to get the value from that dialog box and do something with it.

I thought of creating a global variable that can be written to within the 2nd dialog box's function, but this just doesnt seem like good programming practice. And not only that, I am getting strange bugs (race conditions?) in my program that makes me very suspicious about the manner in which I implemented this code.

Any Ideas? Is there something fundamentally wrong with embedding one dialog box within another dialog box?

Any help is greatly appreciated.

Thanks,
--Norm
 
The EndDialog function, which ends the second dialog box, accepts a return-value parameter (EndDialog ( hDlg, ReturnValue )), which you can obtain in the calling procedure like this: ReturnValue = DialogBox ( ... );

With appropriate type casting the return value can be (a pointer to) any type.


Marcel
 
Hi,

I also adopt this approach as well. However, what I do is similar to what Mercel suggests but I create a struct(ure) to represent the data in the &quot;popup&quot; dialog box.

Then create the dialog using DialoxBoxParam() and pass the address of the structure to the box. In the Callback function for the &quot;popup&quot; I have a static pointer to the struct. I assign the address to this in the WM_INITDIALOG, then in my IDOK I copy the Data into the struct's members.

So, when the popup dialog ends I have access to what was entered.

HTH

P.S. I know this post is old but I've only just signed up and I saw you were monitoring this so I though I would share what I do with you.
 
Thanks for the info. I'm doing something similar to that now also.

--Norm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top