创建的窗口只是瞬间闪现,求解决方法

wujunshinc 2011-04-21 09:16:42
userdlg *userdlg1;
userdlg1=new userdlg(this);
userdlg1->Create(IDD_USERDLG);
/*userdlg1->SetDlgItemText(IDC_EDIT1,allcanused::Oname);
userdlg1->SetDlgItemText(IDC_EDIT3,allcanused::OID);
userdlg1->SetDlgItemText(IDC_EDIT2,allcanused::ODID);
userdlg1->SetDlgItemText(IDC_EDIT4,allcanused::OTEL); */
userdlg1->ShowWindow(SW_RESTORE);

...全文
167 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
wujunshinc 2011-04-22
  • 打赏
  • 举报
回复
最后说下我自己的能力吧,也就是刚刚开始学习MFC的情况,不过很多时候都是模仿着别人的例子,然后自己重新编代码,检测错误方面,基础不是很扎实,感觉看书很慢,所以就直接多套套例子试炼,有爱的坛友们给些建议吧
wujunshinc 2011-04-22
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 visualeleven 的回复:]

引用 14 楼 wujunshinc 的回复:
恩,发现这个问题后,我改掉了,把InitInstance()添加为
login login1;
m_pMainWnd = &login1;//新加的一条
int ifok =login1.DoModal();
if (ifok==IDOK)
{

}
else if (ifok==IDCANCEL)
{

}……
[/Quote]
发现问题和您说的差不多,我将login设为主窗口后,把CDialog::OnOK();变为UpdateData();后就能出现了,我现在的任务就是在按正确输入确定之后隐藏主窗口
wujunshinc 2011-04-22
  • 打赏
  • 举报
回复
[Quote=引用 21 楼 smwhotjay 的回复:]

逻辑/实现/ui都在一起 - -
[/Quote]
呵呵,给些建议吧
zhonglingqqxh 2011-04-22
  • 打赏
  • 举报
回复
没有消息循环吧
smwhotjay 2011-04-22
  • 打赏
  • 举报
回复
逻辑/实现/ui都在一起 - -
wujunshinc 2011-04-22
  • 打赏
  • 举报
回复
汗,忘记修改回来了,删不了帖子
重发一遍
BOOL CNewsqlApp::InitInstance()
{
AfxEnableControlContainer();
// 初始化COM,创建ADO连接等操作
AfxOleInit();
m_pConnection.CreateInstance(__uuidof(Connection));
// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
// 因为它有时会经常出现一些想不到的错误。jingzhou xu
try
{
// 打开本地Access库Demo.mdb
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=bs.mdb","","",adModeUnknown);

}
catch(_com_error& e)
{
//调用在CAdoRWAccessDlg中打印错误信息的静态函数
CNewsqlDlg::dump_com_error(e);
return FALSE;
}
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.

#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
login login1;
// m_pMainWnd = &login1;
int ifok =login1.DoModal();
if (ifok==IDOK)
{

}
else if (ifok==IDCANCEL)
{

}
/* CNewsqlDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}*/

// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}

wujunshinc 2011-04-22
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 bokutake 的回复:]

m_pMainWnd肯定不能关联login,应该关联你的CMainFrame之类的主窗口对象。一般来说这个操作是不需要你自己做的。MFC会自动完成的。
所以你的问题肯定不在这。不知道LZ在InitInstance的过程里return的是TRUE还是FALSE。SDI程序应该用TRUE。
请LZ贴一下InitInstance的代码。
[/Quote]
BOOL CNewsqlApp::InitInstance()
{
AfxEnableControlContainer();
// 初始化COM,创建ADO连接等操作
AfxOleInit();
m_pConnection.CreateInstance(__uuidof(Connection));
// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
// 因为它有时会经常出现一些想不到的错误。jingzhou xu
try
{
// 打开本地Access库Demo.mdb
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=bs.mdb","","",adModeUnknown);

}
catch(_com_error& e)
{
//调用在CAdoRWAccessDlg中打印错误信息的静态函数
CNewsqlDlg::dump_com_error(e);
return FALSE;
}
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.

#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
login login1;
m_pMainWnd = &login1;
int ifok =login1.DoModal();
if (ifok==IDOK)
{
login::OnOK();

}
else if (ifok==IDCANCEL)
{

}
/* CNewsqlDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}*/

// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
plusyes 2011-04-21
  • 打赏
  • 举报
回复
能否这样:

1. userdlg *userdlg1; 定义成 login 对话框成员。
2. 在userdlg的析构函数下断点,查Debug调用堆栈, 看下userdlg生存时间。
辰岡墨竹 2011-04-21
  • 打赏
  • 举报
回复
m_pMainWnd肯定不能关联login,应该关联你的CMainFrame之类的主窗口对象。一般来说这个操作是不需要你自己做的。MFC会自动完成的。
所以你的问题肯定不在这。不知道LZ在InitInstance的过程里return的是TRUE还是FALSE。SDI程序应该用TRUE。
请LZ贴一下InitInstance的代码。
Eleven 2011-04-21
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 wujunshinc 的回复:]
恩,发现这个问题后,我改掉了,把InitInstance()添加为
login login1;
m_pMainWnd = &login1;//新加的一条
int ifok =login1.DoModal();
if (ifok==IDOK)
{

}
else if (ifok==IDCANCEL)
{

}
情况一样,不过闪的更快了。
[/Quote]
你的m_pMainWnd关联的是login对话框,login完了,你的程序也就退出了
wujunshinc 2011-04-21
  • 打赏
  • 举报
回复
先谢谢大家,明天上午我再上,马上要熄灯了
wujunshinc 2011-04-21
  • 打赏
  • 举报
回复
恩,发现这个问题后,我改掉了,把InitInstance()添加为
login login1;
m_pMainWnd = &login1;//新加的一条
int ifok =login1.DoModal();
if (ifok==IDOK)
{

}
else if (ifok==IDCANCEL)
{

}
情况一样,不过闪的更快了。
Eleven 2011-04-21
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 wujunshinc 的回复:]
引用 10 楼 visualeleven 的回复:

被我注释掉了,没有了
[/Quote]
囧,没有这个,DoModal()以后,后面的都是一闪而过。。。程序会退出。
DoModal()出来的模态对话框不会一闪而过是因为模态对话框有自己的消息循环,会阻塞当前的消息循环,DoModal()以后返回原来的消息处理。
看看MSDN上的解释,看看m_pMainWnd有多大的魅力

The Microsoft Foundation Class Library will automatically terminate your thread when the window referred to by m_pMainWnd is closed. If this thread is the primary thread for an application, the application will also be terminated. If this data member is NULL, the main window for the application's CWinApp object will be used to determine when to terminate the thread. m_pMainWnd is a public variable of type CWnd*.
wujunshinc 2011-04-21
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 visualeleven 的回复:]
[/Quote]
被我注释掉了,没有了
williamsong997 2011-04-21
  • 打赏
  • 举报
回复
不要去找窗口初始化的问题了,
问题应该不在哪,应该是你的程序调用了其它的DLL之类的东西.而这些DLL所依赖的条件不具备.

要试的话新建一个工程,把你这段代码单独放进去一试不就知道了?
Eleven 2011-04-21
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 wujunshinc 的回复:]
引用 8 楼 visualeleven 的回复:

错倒是没有,但是对话框只是闪现,有些无奈。
试过用模式对话框,会出现winocc.cpp的运行错误。谢谢大家帮忙了
---------------------------------------------------------
只是闪了一下?你的主窗口还在吗?

额,我不是很懂您的意思,我是在APP中设定启动登录窗口,判定登陆者……
[/Quote]
你的主窗口类是哪个?即你在App类的InitInstance函数中m_pMainWnd = 。。。这边的这个是哪个窗口类的指针
wujunshinc 2011-04-21
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 visualeleven 的回复:]

错倒是没有,但是对话框只是闪现,有些无奈。
试过用模式对话框,会出现winocc.cpp的运行错误。谢谢大家帮忙了
---------------------------------------------------------
只是闪了一下?你的主窗口还在吗?
[/Quote]
额,我不是很懂您的意思,我是在APP中设定启动登录窗口,判定登陆者来选择弹出窗口,登录窗口在输入正确按确定之后消失。弹出的窗口出现了几毫秒就消失了,整个程序运行结束
Eleven 2011-04-21
  • 打赏
  • 举报
回复
错倒是没有,但是对话框只是闪现,有些无奈。
试过用模式对话框,会出现winocc.cpp的运行错误。谢谢大家帮忙了
---------------------------------------------------------
只是闪了一下?你的主窗口还在吗?
wujunshinc 2011-04-21
  • 打赏
  • 举报
回复
void login::OnOK() 
{
// TODO: Add extra validation here
_variant_t var1,var2,var3,var4,var5,var6,var7;
CDialog::OnOK();
// AfxMessageBox(m_user);
// AfxMessageBox(m_password);
if (allcanused::ifuser==1)
{try
{m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open("SELECT * FROM owner",
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error& e)
{
dump_com_error(e);
}

m_pRecordset->MoveFirst();
while(!m_pRecordset->adoEOF)
{
var6=m_pRecordset->GetCollect ("TEL");
if(var6.vt != VT_NULL)
allcanused::OTEL =(LPCSTR) _bstr_t(var6);
if (allcanused::OTEL==m_user)
break;
m_pRecordset->MoveNext();
}
if (m_pRecordset->adoEOF)
{
AfxMessageBox("用户不在数据表中,请联系管理员注册账号") ;
login login1;
login1.DoModal();
}
else
{
var7=m_pRecordset->GetCollect ("password");
if(var7.vt != VT_NULL)
allcanused::Opassword =(LPCSTR) _bstr_t(var7);
if (allcanused::Opassword ==m_password)
{
AfxMessageBox("尊敬的车主您好,为了更好的方便管理,除了密码,您的其他的资料信息无法修改,如发现资料不符可以带相关证明找管理员修改");
var1=m_pRecordset->GetCollect ("name");
if(var1.vt != VT_NULL)
allcanused::Oname =(LPCSTR) _bstr_t(var1);
var4=m_pRecordset->GetCollect ("ID");
if(var4.vt != VT_NULL)
allcanused::OID= (LPCSTR)_bstr_t(var4);
var5=m_pRecordset->GetCollect ("DID");
if(var5.vt != VT_NULL)
allcanused::ODID= (LPCSTR)_bstr_t(var5);
var6=m_pRecordset->GetCollect ("TEL");
if(var6.vt != VT_NULL)
allcanused::OTEL= (LPCSTR)_bstr_t(var6);
userdlg *userdlg1;
userdlg1=new userdlg(this);
userdlg1->Create(IDD_USERDLG);
userdlg1->SetDlgItemText(IDC_EDIT1,allcanused::Oname);
userdlg1->SetDlgItemText(IDC_EDIT3,allcanused::OID);
userdlg1->SetDlgItemText(IDC_EDIT2,allcanused::ODID);
userdlg1->SetDlgItemText(IDC_EDIT4,allcanused::OTEL);
userdlg1->ShowWindow(SW_RESTORE);

}
else
{
AfxMessageBox("密码用户错误");
login login1;
login1.DoModal();
}
}

}
else if(allcanused::ifuser==0)
{
try
{m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open("SELECT * FROM Administrator",
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error& e)
{
dump_com_error(e);
}
m_pRecordset->MoveFirst();
while(!m_pRecordset->adoEOF)
{
var6=m_pRecordset->GetCollect ("account");
if(var6.vt != VT_NULL)
allcanused::Aaccount =(LPCSTR) _bstr_t(var6);
if (allcanused::Aaccount==m_user)
break;
m_pRecordset->MoveNext();
}
if (m_pRecordset->adoEOF)
{
AfxMessageBox("用户不在数据表中,确定您是管理员?") ;
login login1;
login1.DoModal();
}
else
{
var7=m_pRecordset->GetCollect ("password");
if(var7.vt != VT_NULL)
allcanused::Apassword =(LPCSTR) _bstr_t(var7);
if (allcanused::Apassword ==m_password)
{
CNewsqlDlg dlg;
// m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
}
else
AfxMessageBox("密码用户错误");
}
}
}

login是一个登陆对话框类
allcanused是我设置全局变量的类
错倒是没有,但是对话框只是闪现,有些无奈。
试过用模式对话框,会出现winocc.cpp的运行错误。谢谢大家帮忙了
  • 打赏
  • 举报
回复
貌似没有问题啊
你把
userdlg *userdlg1;
userdlg1=new userdlg(this);
userdlg1->Create(IDD_USERDLG);
/*userdlg1->SetDlgItemText(IDC_EDIT1,allcanused::Oname);
userdlg1->SetDlgItemText(IDC_EDIT3,allcanused::OID);
userdlg1->SetDlgItemText(IDC_EDIT2,allcanused::ODID);
userdlg1->SetDlgItemText(IDC_EDIT4,allcanused::OTEL); */
userdlg1->ShowWindow(SW_RESTORE);
放到其他地方试试
加载更多回复(5)

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧