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 31-May-2006, 10:04
steph steph is offline
New Member
 
Join Date: May 2006
Posts: 15
steph is on a distinguished road

Accessing values from a different dialog


Hi All!

So far, I have a dialog that when a button is pressed, another dialog appears with more buttons. Now let's say a button is pressed on this second dialog, and another dialog appears with an edit box on it that is supposed to display a string that was displayed in the first dialog.

I have tired to did this on me own, but it is not working...can you tell me in detail how to access the string in the first dialog, so that I can display it's value in the third dialog's edit box?

Thank you in advance!
Steph
  #2  
Old 03-Jun-2006, 15:40
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 992
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Accessing values from a different dialog


Ok, this is one way it can work: it's basically "passing the string along"
(this is pseudo code, so ignore my wacky variable and function names)

[some of these you may already have]
preliminary things:
in Dialog1's class:
a. add a CString var. for the edit box (dlgTxt1 )

in Dialog2's class:
a. add a CString var. ( dlgTxtPassThru ) [to hold the string from Dialog1]
b. add a member function (return type void) to set this value, with a CString argument. (I'll use 'setTextPass' for this example)

in Dialog3's class:
a. add a CString var. for the edit box ( dlgTxtFinalDest )
b. add a member function (return type void) to set this value, with a CString argument. (I'll use 'setTextFinal' for this example)

Note that each setText* function is a simple String assignment, for example:
Code:
void setTextPass(CString aString) // in Dialog2 { dlgTxtPassThru = aString; // aString is the passed-in dlgTxt1. } void setTextFinal(CString aString) // in Dialog3 { dlgTxtFinalDest = aString; // aString is the passed-in dlgTxtPassThru. }
Now tie it all together...
1. in the Dialog1's button handler (that opens Dialog2) first call UpdateData() to populate dlgTxt1.

then at the point between where the dialog2 is created and before the DoModal() call, as shown here:
Code:
Dialog2* dlg2 = new Dialog2(...); // <<== here ==>> dlg2->DoModal();

2. insert this statement to pass dlgTxt1 to to dlg2:
Code:
dlg2->SetTextPass( dlgTxt1 );
dialog2 now has the string...

So, in dialog2's button handler (that opens dialog3), again at the point between where dialog3 is created and before the DoModal() call...

3. insert these two statements to pass dlgTxtPassThru to dlg3:
Code:
... dlg3->setTxtFinal( dlgTxtPassThru ); UpdateData(FALSE); ...
The text should appear in Dialog3's text field!
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 09-Jun-2006, 10:56
steph steph is offline
New Member
 
Join Date: May 2006
Posts: 15
steph is on a distinguished road

Re: Accessing values from a different dialog


TurboPT,

To be honest, I did not quite understand your explanation. However, I found another way around it. Thank you for your help anyway. It is ALWAYS very much appreciated.

I am having some difficulty though with the following (Google has not been a good friend of mine lately):
1. I used a picture object (type: bitmap), and in the "Picture Properties", under the "Extended Styles" tab, I checked off "Modal frame" to give it a button looking effect. Now what I would like is that when the user clicks on this "button", I want it to look as though it is being pressed, so I would like to "uncheck" modal frame and "check off" client edge (which is another option that can be checked off under the "Extended Styles" tab. Do you have any idea of what code to use in this case?
2. The following regards all of my edit boxes. When the user clicks once I would like its text to be selected (highlighted), then when the user clicks again, the text is unselected and the cursor is simply positioned where the user has clicked. I used the following code, which I got from the internet:
CEdit* pEdit = ( CEdit* ) GetDlgItem(IDC_EDIT_AUTOBA);
pEdit->SetSel(0,3,FALSE);
3. As my program is running, is it possible to change the bitmap displayed in a picture object (for example the one I described in #1)?
4. When the tab key on the keyboard is pressed, the edit boxes (in turn) become in focus and the text is selected; however, if the text is longer than what can be displayed in the edit box (because of the edit box’s size), the cursor is at the end of the text, displaying the end of the text. What I want is for the text to be selected as it was, but for the beginning of the text to be displayed (instead of the end of the text). Is this possible?

If I was confusing in any way, please let me now. I will do my best to explain further.

Thank you (again),
You are a great help,
Steph
  #4  
Old 10-Jun-2006, 01:06
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 992
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Accessing values from a different dialog


For #1, wouldn't it be better to just put a bitmap on a button? (not sure how this would impact #3, what are you trying to do?)

for #2, I'll have to check.

for #4, I know that SetSel(0,0) will move to the beginning of the text, but it won't keep the highlight though. (I'll see if there might be another way)
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #5  
Old 12-Jun-2006, 15:05
steph steph is offline
New Member
 
Join Date: May 2006
Posts: 15
steph is on a distinguished road

Re: Accessing values from a different dialog


TurboPT,

I tried following what you explained (on 03-Jun-2006, at 15:40) about accessing values from different dialogs, but I could not make it work

Well I know that the two "transferring" functions were being called, but the edit boxes were not being updated. When I added the UpdateData(FALSE); statement to the end of these functions....a window pops up, and I have to abort the program...I don't know why this happens.

Let's say I am looking at the CJobRenameDlg dialog and I press the OK button, I used the following code here:

void CJobRenameDlg::OnButtonJobRenameOk()
{ // passing he value stored in m_strDisplayJobRename to the function
...
UpdateData();
CJobOptionsDlg *m_dJobOptionsDlg;
m_dJobOptionsDlg = new CJobOptionsDlg;
m_dJobOptionsDlg->SetTextPass(m_strDisplayJobRename);
EndDialog(IDD_DIALOG_JOB_RENAME);
}

It is then supposed to close the CJobRenameDlg dialog, and the text that was passed was supposed to display on a temporary edit box I created on the CJobOptionsDlg dialog. Here are the functions I used regarding this dialog:

void CJobOptionsDlg::SetTextPass(CString text)
{
MessageBox("Function has been called", "SetTextPass", MB_OK);
m_strDisplayTemp = text;
// UpdateData(FALSE);
}

void CJobOptionsDlg::OnButtonJobCancel()
{
...
UpdateData();
CTry1Dlg *m_dTry1Dlg;
m_dTry1Dlg = new CTry1Dlg;
m_dTry1Dlg->SetTextPass2(temp);
EndDialog(IDD_DIALOG_JOB_OPTIONS);
}

Now, I am still looking at the CJobOptionsDlg dialog and I press the Cancel button, the code I used above calls the SetTextPass2 function (declared in the CTry1Dlg dialog) as shown below:

void CTry1Dlg::SetTextPass2(CString text2)
{
MessageBox("Function has been called", "SetTextPass2", MB_OK);
m_strDisplayStaticJob = text2;
// UpdateData(FALSE);
}

Thanks,
Steph
  #6  
Old 12-Jun-2006, 15:39
steph steph is offline
New Member
 
Join Date: May 2006
Posts: 15
steph is on a distinguished road

Re: Accessing values from a different dialog


TurboPT,

It probably would have been better to use a button and then add a bitmap on top, as apposed to using a picture object and adding a bitmap. However, unfortunately, at this point it may be too late...I have so many done already, and I have spent all day trying to figure out how to add a bitmap to an already created button...I can't seem to figure it out....so I think it may be best to just switch between the picture's properties "client edge" and "modal frame" instead. Today I found out that I could use the following code to set the "client edge" property "on":

m_ctlDel.ModifyStyleEx(0, WS_EX_CLIENTEDGE, SWP_DRAWFRAME | SWP_FRAMECHANGED);

However, I do not know how to turn either this or the "modal frame" property "off". As well, I am still trying to find out how to turn the "modal frame" property "on" during run time.

As for my text selection problem I mentioned in a previous message, I set an integer variable called clickedSinceInFocus to zero (0) in the OnInitDialog function of the main dialog (CTry1Dlg) to keep track of how many times an edit box with the ID IDC_EDIT_AUTOBA has been clicked since it has been in focus. If it is only once I wanted the text to be selected (as if it were double clicked) and if the edit box were clicked more than that, then the cursor would simply be placed where the user clicked.


void CTry1Dlg::OnSetfocusEditAutoba()
{

if (clickedSinceInFocus == 0)
{
// MessageBox("clickedSinceInFocus == 0", "Entered", MB_OK);

// Attempt #1
// m_ctlDisplayAutoBA.SetSel(0,-1);

// Attempt #2
// ((CEdit*)GetDlgItem(IDC_EDIT_AUTOBA))->SetSel(0, -1);

// Attempt #3
// CEdit* pEdit = ( CEdit* ) GetDlgItem(IDC_EDIT_AUTOBA);
// pEdit->SetSel(0,0);

// Attempt #4
// CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_AUTOBA);
// ASSERT(pEdit != NULL);
// pEdit->SetSel(0,1);

// Attempt #5
// CWnd* pWnd = GetDlgItem(IDC_EDIT_AUTOBA);
// ASSERT(pWnd != NULL);
// HWND hWnd = pWnd->GetSafeHwnd();
// ASSERT(hWnd != NULL);
// SendMessage(hWnd, EM_SETSEL, -1, -1);

clickedSinceInFocus = 1;
UpdateData(FALSE); // Update dialog
}
UpdateData(FALSE); // Update dialog
}

void CTry1Dlg::OnKillfocusEditAutoba()
{

clickedSinceInFocus = 0;
UpdateData(FALSE); // Update dialog
}

Please, let me know where I went wrong.

Thanks,
Steph
  #7  
Old 16-Jun-2006, 19:11
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 992
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Accessing values from a different dialog


I'm looking at the other two things you sent previously, but here are the items necessary to have a bitmap on a button.

1. set the button's property for bitmap use:
a. right-click a button
b. choose properties
c. select the 'Styles' tab
d. check the Bitmap checkbox
2. add icon(s) to your resources (I simply used my avatar when trying this)
3. add a HBITMAP data member to the class (I used: HBITMAP m_hBmp )
4. the code: [place in OnInitDialog()]
CPP / C++ / C Code:
CButton* btn;
btn = (CButton*)GetDlgItem( IDC_BUTTON2);
m_hBmp = LoadBitmap(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDB_BITMAP1));
btn->SetBitmap( m_hBmp );
5. size the button to best fit the image, unless, of course, you dynamically set the button size to match the image size. (I haven't done the dynamic part)

...on to the next thing...
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #8  
Old 16-Jun-2006, 19:27
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 992
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Accessing values from a different dialog


I may have another idea for the dialog text thing...

Have you taken a look at function: GetDlgItemText() ?

It would probably still need to be used in the same manner as what I tried the other way. That is, use it between a new instance (to the other dialog), but before EndDialog().
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #9  
Old 19-Jun-2006, 12:20
steph steph is offline
New Member
 
Join Date: May 2006
Posts: 15
steph is on a distinguished road

Re: Accessing values from a different dialog


TurboPT,

I don't understand....can you clarify, please?

Thanks,
Steph
  #10  
Old 19-Jun-2006, 13:24
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 992
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Accessing values from a different dialog


Which post: 7, 8, or both? (I did those separately to split their topics)
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 4) 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
CTabCtrl Child dialog control problems Vix MS Visual C++ / MFC Forum 5 06-Feb-2007 10:54
How to update the child dialog box Arbo MS Visual C++ / MFC Forum 1 01-Jun-2005 14:25
dialog based application hezyse MS Visual C++ / MFC Forum 1 20-Mar-2005 19:16
Help! Some basal questions about MFC xutingnjupt MS Visual C++ / MFC Forum 1 05-Dec-2004 04:38
controling dialog objects & multiple source files omills MS Visual C++ / MFC Forum 0 15-Jul-2004 00:30

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

All times are GMT -6. The time now is 16:32.


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