URGENT!! MFC function call error
HI
I am using MFC .net single document extending from CRichEditView class
I want to call a function from my view class during startup of the program. I tried to call it from the constractor method of the view class but non statc function call error.
sample code
CMyView::CMyView()//constractor
{
......
LoadText(); //error with this call
......
}
void CMyView::LoadText()
{
CString str="something"; //my actual code reads something from txt file.
CRichEditView::SetWindowText(str);
}
How can call LoadText() method during start up of my MFC single document GUI ?
[878 byte] By [
kin2] at [2007-12-22]
The constructor of a CWnd/CView based class is much too early to be performing HWND activities. The constructor is only the object that wraps the CWnd. The window itself has not yet been created. You have to wait until the OnCreate to do anything with the HWND (e.g. SetWindowText). So override the OnCreate and after the call to the base class, do what you need.
ok
I tried as u said, I called LoadText() function in CMyView::OnCreate(..) function as bellow
int
CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct){
if (CRichEditView::OnCreate(lpCreateStruct) == -1)return -1;...
CRichEditView::SetWindowText("Good");
CWordPadView::LoadText();
//MessageBox("Go");
return 0;
}
but it is not working for both calls i.e
CRichEditView::SetWindowText("Good");
CWordPadView::LoadText();
it simply run without error.
But //MessageBox("Go"); works
ok
I tried as u said, I called LoadText() function in CMyView::OnCreate(..) function as bellow
int
CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct){
if (CRichEditView::OnCreate(lpCreateStruct) == -1)return -1;...
CRichEditView::SetWindowText("Good");
CMyView::LoadText();
//MessageBox("Go");
return 0;
}
but it is not working for both calls i.e
CRichEditView::SetWindowText("Good");
CMyView::LoadText();
it simply run without error.
But //MessageBox("Go"); works
tried this way
but the folowing fragment does not set the editor text on start up
int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CRichEditView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
GetRichEditCtrl().SetWindowText("Hello World");
return 0;
}
what do u think is the problem.
is there any function call that will reset windows text after call of OnCreate.
Tanx to Viorel.
It works whith rhis ..
void CMyView::OnInitialUpdate()
{
CRichEditView::OnInitialUpdate();
GetRichEditCtrl().SetWindowText(_T("Hello World"));
}