vc如何退出程序

1、OnOK()OnCancel()//只对窗口程序有用

2、PostQuitMessage(0);//最常用

3、ExitProcess(0);

4、

void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
if (MessageBox("确定要退出吗?","提示",MB_YESNO|MB_DEFBUTTON2)==IDYES)
{
  CFrameWnd::OnClose();
}
}

如:

void CCsView::OnShutdown() //自定义
{
// TODO: Add your command handler code here
if (MessageBox("确定要退出吗?","提示",MB_YESNO|MB_DEFBUTTON2)==IDYES)
{
  PostQuitMessage(0);
}
}

 

 

举个例子,我要做一个软件,所以新建一个单文档的应用程序,但是想让用户先进行登陆,所以添加了一个登陆对话框(双击对话框添加新类等就不提了),然后,在APP类中的适当位置进行对话框的显示,并判断(不进行具体的实现了,只是检验一下单击了确定还是取消按钮),如果点击了"确定"就进入主界面,如果点击了取消就立即终止程序.

 

 

 CLgnDlg lgndlg;
 if(IDOK==lgndlg.DoModal())
 {
 
 }
 else
 {
 //PostQuitMessage(0);
 //((CMainFrame*)AfxGetMainWnd())->SendMessage(WM_CLOSE);
 ExitProcess(0);
 }

 CSingleDocTemplate* pDocTemplate;
 pDocTemplate = new CSingleDocTemplate(
  IDR_MAINFRAME,
  RUNTIME_CLASS(CTestBDoc),
  RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  RUNTIME_CLASS(CTestBView));
 AddDocTemplate(pDocTemplate);

 // Parse command line for standard shell commands, DDE, file open
 CCommandLineInfo cmdInfo;
 ParseCommandLine(cmdInfo);

 // Dispatch commands specified on the command line
 if (!ProcessShellCommand(cmdInfo))
  return FALSE;

 // The one and only window has been initialized, so show and update it.
 m_pMainWnd->ShowWindow(SW_SHOW);
 m_pMainWnd->UpdateWindow();

 return TRUE;
}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值