vc如何退出程序

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;
}


你可能感兴趣的:(VC)