|
Keep a public CString member variable in Child dialog class, set the member variable before calling the DoModal() or Create function of child dialog. Call SetWindowText of edit control in InitDialog.
for. eg
If CMainDlg is your Main dialog class and CChildDialog be the child.
in header of CChildDialog you declare a public member variable to hold the string
class CChildDialog : public CDialog
{
public :
CString m_strText;
}
and in your button click function of CMainDlg do this
void CMainDlg::OnClick_Button()
{
CChildDialog oChildDlg;
oChildDlg.m_strText = strText; oChildDlg.DoModal();
}
Set the variable value in CChildDialog's OnInitDialog as
CChildDialog::OnInitDialog()
{
SetDlgItemText(ID_OF_YOUR_EDIT, m_strText);
}
You can also set the text by modifying your constructor of CChildDialog, such as
CChildDialog::CChildDialog(CString strText)
|
|
|
|
|
From class wizard, maindialog's member variables I added a member variable to the editbox which gets the editbox's value and then as you said, I equalize each variables but than it returns nothing from main dialog ???
|
|
|
|
|
|
I did it as Mahdu replied and by your hint... like
void mainform::OnBnClickedButton2()
{
GetDlgItemText(IDC_EDIT1,newform.strtext);
}
BOOL newform::OnInitDialog()
{
SetDlgItemText(IDC_EDIT1, strtext);
}
THANKS TO YOU ALL FOR REPLIES PEOPLE!!! YOU ARE GREAT... )
|
|
|
|
|
How about something like:
CMainDlg::OnButtonClick()
{
CString strText;
m_edit.GetWindowText(strText);
CSecondDlg dlg;
dlg.setData(strText);
dlg.DoModal();
}
CSecondDlg::setData( LPCTSTR lpszText )
{
m_strText = lpszText;
}
CSecondDlg:OnInitDialog()
{
m_edit.SetWindowText(m_strText);
} I'm a big fan of weak coupling, so tying these two dialogs together like this would not be my first choice. I would opt for a "data transfer" or "liaison" class instead. This is a one-instance class where you would put all of your shared data.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Thanks for your reply David... I would like to criticise your post if I was more skilled... But seems to me for now... Maybe not, in the future?? Just joking, thanks again...
|
|
|
|
|
By the way, you can just explain this :
CFileDialog *pOpenDlg=new CFileDialog(FALSE,".txt",NULL,OFN_OVERWRITEPROMPT,"Text Files (*.txt)|*.txt|All Files(*.*)|*.*||");
if you want some more charity from our heavenly father?? PLEASE!
|
|
|
|
|
Try and put this code in a button click and see what happens. then you will understand why is this code required.
Every new day is another chance to change your life.
|
|
|
|
|
hi,
how do i get a list of LANGID in array?
i want initialize an array with LANGIDs (for example i do this in a loop).
int count;
WORD* arr = new WORD[count];
please help me
Zo.Naderi-Iran
|
|
|
|
|
The current list should be in file WinNT.h; search for keyword LANG_NEUTRAL . See also second response.
modified 12-Oct-11 5:18am.
|
|
|
|
|
Further research suggests you should use one of the locale support functions such as EnumSystemLocalesEx()[^].
|
|
|
|
|
zon_cpp wrote: how do i get a list of LANGID in array?
Hi,
I believe Microsoft discourages using the MLANG interface. At least that's what it use to say on MSDN. However I looked just now and could not find the do-not-use disclaimer. With that being said... A few years ago I managed to figure out how to use some of the vaguely documented interfaces. Here is what I use to enumerate available locales:
HRESULT hr = CoInitialize(NULL);
if(SUCCEEDED(hr))
{
IMultiLanguage * pml;
hr = CoCreateInstance(CLSID_CMultiLanguage,NULL,CLSCTX_ALL,IID_IMultiLanguage,(void**)&pml);
if(SUCCEEDED(hr))
{
RFC1766INFO info;
ULONG num;
IEnumRfc1766 *rfc1766;
hr = pml->EnumRfc1766(&rfc1766);
if(SUCCEEDED(hr))
{
while(S_OK == rfc1766->Next(1,&info,&num))
{
WORD wLangID = LANGIDFROMLCID(info.lcid);
}
}
}
pml->Release();
}
CoUninitialize();
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
How to bold a specific listcontrol row?
|
|
|
|
|
in OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult) event of CListCtrl
void CMyList::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLVCUSTOMDRAW pLVCD reinterpret_cast<LPNMLVCUSTOMDRAW>(pNMHDR);
switch(pLVCD->nmcd.dwDrawStage)
{
case CDDS_ITEMPREPAINT:
if(pLVCD->nmcd.dwItemSpec == 1)
{
pLVCD->clrTextBk = RGB(235,235,235);
}
break;
}
}
Zo.Naderi-Iran
|
|
|
|
|
It will chage the color of text, I need to make it BOLD
|
|
|
|
|
Hi,
Modify the code zon_cpp gave you and use something like this in the CDDS_ITEMPREPAINT case:
HFONT hOldFont = (HFONT)SelectObject(pLVCD>hdc, m_Font);
SelectObject(pLVCD>hdc, hOldFont);
In your header add:
CFont m_Font;
In your dialog constructor add something like:
m_Font.CreateFont(13,0,0,0,FW_NORMAL,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,DEFAULT_PITCH | FF_DONTCARE,_T("MS Shell Dlg 2"));
Best Wishes,
-David Delaune
|
|
|
|
|
|
I'm trying to read text from a text file. I look for in msdn how to read and write in text file, and I found this:
http://msdn.microsoft.com/es-es/library/6337eske.aspx[^]
I made this funtion to read from my text file:
void CDlgResultados::loadFromFile(void)
{
CString path= GetUserHomeDir() + _T("\\Documents\\file.txt");
TCHAR szBuffer[256];
UINT nActual = 0;
CFile myFile;
if ( myFile.Open(path, CFile::modeCreate |
CFile::modeRead ) )
{
myFile.Write( szBuffer, sizeof( szBuffer ) );
myFile.Flush();
myFile.Seek( 0, CFile::begin );
nActual = myFile.Read( szBuffer, sizeof( szBuffer ) );
}
m_Edit.SetWindowTextW(szBuffer);
}
But when I run the app and I press the button to read the file, I get a error that it said:
You dont have acces to this file.
|
|
|
|
|
What is the actual value of the string in your path variable, at the time you try to create the file?
|
|
|
|
|
this is the value:
C:\Users\Antonio\Documents\file.txt
|
|
|
|
|
OK, and does that directory exist and can you create that file manually? If so then check also the suggestions from other commenters below.
|
|
|
|
|
Yes, this directory exist and I made the file manually.
|
|
|
|
|
Use the class CStdioFile to read text file.
google for example, there are many.
Watched code never compiles.
|
|
|
|
|
Rule number 0 when working with files. Always check return codes, so you know which call is failing.
Best guess is that when you call to Write() to the file, you do not have permissions, since your Open() call doesn't specify that permission. Maybe the create Permission implies this, but I'm not sure.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
antonio343 wrote: , I get a error that it said: You dont have acces to this file.
Open the file using
CFile::modeReadWrite OR CFile::modeWrite it seems you don't have permission to write.
|
|
|
|