Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7065293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:56:20+00:00 2026-05-28T04:56:20+00:00

I like to write a modeless dialog based app, but I have a problem.

  • 0

I like to write a modeless dialog based app, but I have a problem. When the program starts, the window close immediately.

The same code works fine when I make a modal dialog. (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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:56:20+00:00Added an answer on May 28, 2026 at 4:56 am

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

    Change that like to return TRUE; and everything should work fine.

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

    The reason that it works with a modal dialog (shown by calling the DoModal method) is because a modal dialog creates its own message loop, which runs until you close the dialog. That means that execution effectively “blocks” at the DoModal call without returning control to your InitInstance method, so it doesn’t return FALSE and MFC doesn’t quit. At least not until you close the dialog, in which case you want it to quit, so everything appears the work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to write a small program in C# which goes through my
I'd like to write a Silverlight app that has 2 or more browser windows
I like to write linux newlines, under windows, but QT automatically convert \n to
I'd like write cues (i.e. time-based markers, not ID3-like tags) to a WAV file
You can write like this: int test[] = {1,2,3,4}; but what if you want
I would like to write a program on iPad to connect network share drive
If I write like this: form action=Images method=post enctype=multipart/form-data it works. But in Razor
I'd like to write a parser for hashtags. I have been reading the blog
I'd like write a layout manager for j2me. I already have widgets and panels
I'd like to write a game for the Nintendo Wii. How do I go

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.