English 中文(简体)
MFC模式 方言
原标题:MFC modeless dialog close immediately

我想写的是模拟方言,但我有问题。 当方案启动时,窗口立即关闭。

当我做示范方言时(DoModal()。

Csetkliens.h

#pragma once

#ifndef __AFXWIN_H__
    #error "include  stdafx.h  before including this file for PCH"
#endif

#include "resource.h"       // main symbols
#include "CsetkliensDlg.h"

class CCsetkliensApp : public CWinApp
{
public:
    CCsetkliensApp();
    virtual BOOL InitInstance();
    DECLARE_MESSAGE_MAP()

private:
    CCsetkliensDlg* dlg;
};

extern CCsetkliensApp theApp;

<>Csetkliens.cpp

#include "stdafx.h"
#include "Csetkliens.h"
#include "CsetkliensDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

BEGIN_MESSAGE_MAP(CCsetkliensApp, CWinApp)
    ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()

CCsetkliensApp::CCsetkliensApp()
{
    dlg = NULL;
}

CCsetkliensApp theApp;

BOOL CCsetkliensApp::InitInstance()
{
    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&InitCtrls);

    CWinApp::InitInstance();

    if (!AfxSocketInit())
    {
        AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
        return FALSE;
    }

    CShellManager *pShellManager = new CShellManager;

    dlg = new CCsetkliensDlg();
    m_pMainWnd = dlg;
    dlg->Create(CCsetkliensDlg::IDD);
    dlg->ShowWindow(SW_SHOW);


    if (pShellManager != NULL)
    {
        delete pShellManager;
    }

    return FALSE;
}

CsetkliensDlg.h

#pragma once
#include "ConnectDlg.h"

class CCsetkliensDlg : public CDialogEx
{

public:
    CCsetkliensDlg(CWnd* pParent = NULL);
    enum { IDD = IDD_CSETKLIENS_DIALOG };
protected:
    virtual BOOL OnInitDialog();
    DECLARE_MESSAGE_MAP()
};

<>CsetkliensDlg.cpp

#include "stdafx.h"
#include "Csetkliens.h"
#include "CsetkliensDlg.h"
#include "afxdialogex.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

CCsetkliensDlg::CCsetkliensDlg(CWnd* pParent /*=NULL*/)
    : CDialogEx(CCsetkliensDlg::IDD, pParent)
{
}

BEGIN_MESSAGE_MAP(CCsetkliensDlg, CDialogEx)
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
END_MESSAGE_MAP()

BOOL CCsetkliensDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
    return TRUE;
}
最佳回答

Returning FALSE from your application class s InitInstance method tells MFC that initialization failed and the application should terminate.

改写成<条码>;,一切都应做罚款。

BOOL CCsetkliensApp::InitInstance()
{
    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&InitCtrls);

    CWinApp::InitInstance();

    if (!AfxSocketInit())
    {
        AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
        return FALSE;
    }

    CShellManager *pShellManager = new CShellManager;

    dlg = new CCsetkliensDlg();
    m_pMainWnd = dlg;
    dlg->Create(CCsetkliensDlg::IDD);
    dlg->ShowWindow(SW_SHOW); // this is not a blocking call!


    if (pShellManager != NULL)
    {
        delete pShellManager;
    }

    return TRUE; // change this one!
}

之所以与模式方言(用DoModal方法标明)合作,是因为模式方言形成自己的信息循环,直到你结束方言。 这意味着,在<代码>Doudal上的有效“锁”执行,无须再回控制<代码>Intstance方法,因此它没有回旋余地。 至少直到你结束辩词为止,在这种情形下,你必须放弃。

问题回答

我看不出任何东西可以说明在打开模型窗后继续活下去的申请。 你们至少需要一个模式窗口,或控制申请的终止。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签