为求解答,小弟我将所有的分都给出,老子小弟我不过了(李云龙语)
为求解答,我将所有的分都给出,老子我不过了(李云龙语)
我在编写一个记事本程序的时候想有一个定时的功能,即假如在4月5日当天有工作安排的话,开机运行程序时,之前保存在电脑中的文件名为4月5日;txt的文件将跳出,显示在视图区,并有提示对话框出现。现在这些都可以实现了,但是当我在点激本程序界面的新建菜单项和之前已经打开过的表单文件名菜单项时却也出现了4月5日的文件内容和提示对话框,这将如何解决呢?
下面是我的相关问题代码
在CMyEditView.cpp中的OnInitialUpdate():
void CMyEditView::OnInitialUpdate()
{
CEditView::OnInitialUpdate();
CString strname,strDate,strfile;
((CMy34App *)AfxGetApp())-> m_pMyEditView = this;
CEdit& ed=this-> GetEditCtrl();
COleDateTime time=COleDateTime::GetCurrentTime();
strDate.Format( "%d年%d月%d日 ", time.GetYear(), time.GetMonth(), time.GetDay());
strname =strDate+ ".txt ";
UpdateData(false);
CFile file;
CFileFind finder;
BOOL bWorking = finder.FindFile( "E:\\my code\\34\\*.txt ");//我的文件存放在这里
while (bWorking)
{
bWorking = finder.FindNextFile();
strfile=finder.GetFileName();
if (strfile==strname)//开机一运行,如果在E:\my code\中有已经存在和开机当天
//日期一样的文件名,则在视图中显示并提示
break;
}
strname=finder.GetFilePath();
if(file.Open(strname,CFile::modeReadWrite,NULL))
{
MessageBox( "你今天有安排,请点击红圈以显示您今天要做的工作。 ");
char *pBuf=NULL;
DWORD dwFileLen;
dwFileLen=file.GetLength();
pBuf= new char [dwFileLen+1];
pBuf[dwFileLen]=0;
file.Read(pBuf,dwFileLen);
ed.SetWindowText(pBuf);
file.Close();
//UpdateData(false);
}
}
------解决方案--------------------
添加一个成员变量flag ,初始化为true;
void CMyEditView::OnInitialUpdate()
{
CEditView::OnInitialUpdate();
if(flag)
{
...//你的代码
flag = false;
}
}
这样就可以了。。。
------解决方案--------------------
CWINAPP实例在运行时你的界面线程还没开始呢,没开始当然得不到EDIT的句柄了
我在编写一个记事本程序的时候想有一个定时的功能,即假如在4月5日当天有工作安排的话,开机运行程序时,之前保存在电脑中的文件名为4月5日;txt的文件将跳出,显示在视图区,并有提示对话框出现。现在这些都可以实现了,但是当我在点激本程序界面的新建菜单项和之前已经打开过的表单文件名菜单项时却也出现了4月5日的文件内容和提示对话框,这将如何解决呢?
下面是我的相关问题代码
在CMyEditView.cpp中的OnInitialUpdate():
void CMyEditView::OnInitialUpdate()
{
CEditView::OnInitialUpdate();
CString strname,strDate,strfile;
((CMy34App *)AfxGetApp())-> m_pMyEditView = this;
CEdit& ed=this-> GetEditCtrl();
COleDateTime time=COleDateTime::GetCurrentTime();
strDate.Format( "%d年%d月%d日 ", time.GetYear(), time.GetMonth(), time.GetDay());
strname =strDate+ ".txt ";
UpdateData(false);
CFile file;
CFileFind finder;
BOOL bWorking = finder.FindFile( "E:\\my code\\34\\*.txt ");//我的文件存放在这里
while (bWorking)
{
bWorking = finder.FindNextFile();
strfile=finder.GetFileName();
if (strfile==strname)//开机一运行,如果在E:\my code\中有已经存在和开机当天
//日期一样的文件名,则在视图中显示并提示
break;
}
strname=finder.GetFilePath();
if(file.Open(strname,CFile::modeReadWrite,NULL))
{
MessageBox( "你今天有安排,请点击红圈以显示您今天要做的工作。 ");
char *pBuf=NULL;
DWORD dwFileLen;
dwFileLen=file.GetLength();
pBuf= new char [dwFileLen+1];
pBuf[dwFileLen]=0;
file.Read(pBuf,dwFileLen);
ed.SetWindowText(pBuf);
file.Close();
//UpdateData(false);
}
}
------解决方案--------------------
添加一个成员变量flag ,初始化为true;
void CMyEditView::OnInitialUpdate()
{
CEditView::OnInitialUpdate();
if(flag)
{
...//你的代码
flag = false;
}
}
这样就可以了。。。
------解决方案--------------------
CWINAPP实例在运行时你的界面线程还没开始呢,没开始当然得不到EDIT的句柄了