GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-Mar-2006, 18:02
custo custo is offline
New Member
 
Join Date: Mar 2006
Posts: 9
custo is on a distinguished road

getting data from dialog before close


Hi, I apologize for this lamer question, but I can't still resolve this problem:

I open a dialog to get some information from user (few edit controls). When user cliks "ok" I want to get these information in parent window?

How can I pass these information? (and when? before closing dialog and after it is clicked to "ok" ?)
  #2  
Old 22-Mar-2006, 20:23
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 995
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: getting data from dialog before close


See the help for the UpdateData() function for more information, but basically when the user clicks 'OK', this is the function that transfers data from the dialog box to the data members that are tied to the dialog's controls. Then you should be able to use those variables as needed.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 23-Mar-2006, 04:13
custo custo is offline
New Member
 
Join Date: Mar 2006
Posts: 9
custo is on a distinguished road

Re: getting data from dialog before close


UpdateData() set values of local vars
but I need to set values of vars in parent window.

is this possible with UpdateData() as well?
  #4  
Old 23-Mar-2006, 04:45
Dominic Dominic is offline
Member
 
Join Date: Aug 2005
Posts: 123
Dominic will become famous soon enough

Re: getting data from dialog before close


One method that works for me is to send into the dialog a pointer to a structure declared in the parent. Then when the dialog closes (say use OnDestroy), write the values into that structure. They will then be available to the parent after the dialog has gone.

so:
1. create a public method that will take a pointer to a structure as its argument.
2. declare the structure in the parent before starting the dialog
3. After decalring the dialog, and before using DoModal(), call this new function and pass the address of the structure
4. in the OnDestroy function write the values back to the parent using the structure pointer.

Hope this helps
  #5  
Old 23-Mar-2006, 09:24
custo custo is offline
New Member
 
Join Date: Mar 2006
Posts: 9
custo is on a distinguished road

Re: getting data from dialog before close


yeah, I has already thought about something like that. thx
  #6  
Old 23-Mar-2006, 09:31
custo custo is offline
New Member
 
Join Date: Mar 2006
Posts: 9
custo is on a distinguished road

Re: getting data from dialog before close


Now I discovered a better way how to get info. When "DoModal" returns value, the dialog is still "alive" and so you can access its control edits etc...

Code:
Insert_Text_Dlg insert_dlg; int nResponse = insert_dlg.DoModal(); if (nResponse == IDOK) { CString s = insert_dlg.inserted_text; ... } else if (nResponse == IDCANCEL) { ... }
  #7  
Old 24-Mar-2006, 00:58
Dominic Dominic is offline
Member
 
Join Date: Aug 2005
Posts: 123
Dominic will become famous soon enough

Re: getting data from dialog before close


Looks a very reasonable way to do it. I think you have solved this problem now.
Regards
 
 

Recent GIDBlogUS Elections and the ?Voter?s Responsibility? by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 14:12
Strange C++ code memory leakage problem gaoanyu C++ Forum 7 04-Nov-2005 09:09
Help! Some basal questions about MFC xutingnjupt MS Visual C++ / MFC Forum 1 05-Dec-2004 04:38
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 16:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 10:36.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.