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

  • Home
  • SEARCH
  • 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 766775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T17:06:10+00:00 2026-05-14T17:06:10+00:00

I need to create a console application that has a main() function and pop

  • 0

I need to create a console application that has a main() function and pop a modeless dialog, so the console can still work in parallel to the modeless dialog (do other work, like communicating with the modeless dialog).

Whatever i tried, i could only pop a modal dialog. (where the console is in hold till the modal dialog close itself).

When switching to modeless dialog using Create() and ShowWindow() the dialog is displayed without its controls and it freeze / block (you can see the hourglass cursor).

1) I tried to pop the modeless dialog from the main() function:

void main()
{
    AfxWinInit(GetModuleHandle(NULL), NULL, GetCommandLine(), SW_SHOW);

    TestGUI * gui;
    gui = new TestGUI();
    gui->Create(TestGUI::IDD);
    gui->ShowWindow(SW_SHOW);

    // just to see if the modeless dialog responses
    Sleep(10000);
}

2) I tried to pop the modeless dialog from the InitInstance() of a CWinApp derived class:

extern int AFXAPI AfxWinMain(HINSTANCE hInstance,
                             HINSTANCE hPrevInstance,
                             LPTSTR lpCmdLine, int nCmdShow);

class MyApp : public CWinApp
{
public:
    virtual BOOL InitInstance()
    {
        gui = new TestGUI();
        gui->Create(TestGUI::IDD);
        gui->ShowWindow(SW_SHOW);

        return TRUE;
    }

private:
    TestGUI * gui;
};

MyApp my_app;

void main()
{
    AfxWinMain(GetModuleHandle(NULL), NULL, GetCommandLine(), SW_SHOW);

    // just to see if the modeless dialog responses
    Sleep(10000);
}

In all cases the modeless dialog freeze.

I believe this is a one line solution.
Please help.

TNX,
Vertilka

  • 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-14T17:06:10+00:00Added an answer on May 14, 2026 at 5:06 pm

    Following code snippet solves the problem:

    #include "stdafx.h"
    #include "TestGUI.h"
    
    DWORD WINAPI ModelessThreadFunc(LPVOID)
    {
      TestGUI gui;
      gui.Create(TestGUI::IDD);
      gui.ShowWindow(SW_SHOW);
    
      HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, L"CloseModelessDialog");
    
      MSG msg;
      while(WaitForSingleObject(hEvent, 0) != WAIT_OBJECT_0)
      {
        while(::GetMessage(&msg, NULL, 0, 0))
        {
          ::TranslateMessage(&msg);
          ::DispatchMessage(&msg);
        }
      }
    
      // event cleanup
      CloseHandle(hEvent);
    
      return 0;
    }
    
    void main()
    {
      // initialize MFC
      AfxWinInit(GetModuleHandle(NULL), NULL, GetCommandLine(), SW_SHOW);
    
      // create thread for the modeless dialog
      CreateThread(NULL, 0, ModelessThreadFunc, NULL, 0, NULL);
    
      // wait for the modeless dialog to close itself
      HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, L"CloseModelessDialog");
      while(WaitForSingleObject(hEvent, 0) != WAIT_OBJECT_0)
      {
        // do other job
      }
    
      // event cleanup
      CloseHandle(hEvent);
    }
    

    Also look at the following link: microsoft newsgroups

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

Sidebar

Ask A Question

Stats

  • Questions 467k
  • Answers 467k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It may be becoz of "Host is not recognized" and… May 16, 2026 at 2:06 am
  • Editorial Team
    Editorial Team added an answer Its called encapsulation and the concept is central to object… May 16, 2026 at 2:06 am
  • Editorial Team
    Editorial Team added an answer Below code should help you SPList myList=SPContext.Current.Web.Lists["YourList"]; if (myList.BaseType ==… May 16, 2026 at 2:06 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.