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 6702425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:03:08+00:00 2026-05-26T07:03:08+00:00

To preface we have a strange requirement that all dialogs must be modeless for

  • 0

To preface we have a strange requirement that all dialogs must be modeless for an MFC application. There is a particular dialog using region drawing and some custom controls to select dates and times for viewing past and future data per view. I need to be able to close this window when it loses focus, the main app gets a system command, etc.

I figured the easiest way to do this would be to register the class like so:

    // for CWnd::FindWindow
    WNDCLASS wndcls;
    SecureZeroMemory(&wndcls, sizeof(WNDCLASS));
    wndcls.lpszClassName    = L"CTransactionDialog";
    wndcls.style            = CS_HREDRAW | CS_VREDRAW;
    wndcls.lpfnWndProc      = AfxWndProc;
    wndcls.cbClsExtra       = wndcls.cbWndExtra = 0;
    wndcls.hInstance        = AfxGetInstanceHandle();
    wndcls.hIcon            = NULL;
#ifndef _WIN32_WCE_NO_CURSOR
    wndcls.hCursor          = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
#else
    wndcls.hCursor          = 0;
#endif
    wndcls.hbrBackground    = (HBRUSH) (COLOR_BACKGROUND + 1);
    wndcls.lpszMenuName     = NULL;

    BOOL retVal = AfxRegisterClass(&wndcls);
    if (!retVal)
        AfxMessageBox(L"AfxRegisterClass(CTransactionDialog) Failed");

Then later in response to various event handlers and messages where I would want these modeless window or windows to be closed to do something simple like this:

CWnd* pFound = NULL;
while ((pFound = CWnd::FindWindow(L"CTransactionDialog", NULL)) != NULL)
    pFound->DestroyWindow();

However despite the registration of the class succeeding and looking at GetRuntimeClass of the dialog in question in debug and seeing that is matches up as expected the FindWindow never seems to find or close these modeless dialogs as expected.

What am I doing wrong or is there a better way to go about this?

Update: This is how the dialog is created via a static method on the dialog class. The dialog resource for the id specified in create has the Popup property set which should resolve to WS_POPUP style under the MFC covers. The dialog shouldn’t and doesn’t have a parent as far as I knew.

CTransactionDialog* CTransactionDialog::ShowTransactionDialog(const CRect& crCtrlToFloatAbove, UINT dialogID, Itime defaultTime, Itime initialTime)
{
    CTransactionDialog* pCTDialog = new CTransactionDialog(crCtrlToFloatAbove, dialogID, defaultTime, initialTime);
    pCTDialog->Create(CTransactionDialog::IDD);
    pCTDialog->ShowWindow(SW_SHOW);

    return pCTDialog;
}

Update: Doh! FindWindowEx isn’t finding anything either.

CWnd::FindWindowEx(AfxGetMainWnd()->GetSafeHwnd(), NULL, L"CTransactionDialog", NULL);

However I have a new plan. I’m just going to make my own window message and handle it on the main frame. I think I can get away with passing a pointer to the dialog as the lParam of the message and then casting it to a CWnd* then calling DestroyWindow. It will work for most cases in a very round about way. I may run into trouble with minimizing and maximizing of the main frame window for dialogs that nothing is holding a pointer too but we’ll see.

  • 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-26T07:03:09+00:00Added an answer on May 26, 2026 at 7:03 am

    Below is the simplest and cleanest solution I could come up with:

    BOOL CTransactionDialog::OnNcActivate(BOOL bActive)
    {
        if (!bActive)
            PostMessage(WM_CLOSE);
    
        return CDialog::OnNcActivate(bActive);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to preface this with the fact that I love jQuery as a
Let me preface by saying I have no Flash/AS knowledge really at all. My
I'll preface this with the fact that I'm new to RoR. I have a
Let me preface this by saying that I'm pretty new to Java. I have
I'll preface this question with the note that I have looked at this similar
Let me preface this by saying that perhaps there's a better way to do
Preface For some time now I've been using the readonly modifier for nearly all
Preface: I have looked all over stackoverflow.com and google for this. I have found
To preface, I'm aware (as should you!) that using SELECT * in production is
Preface: I have two entities defined as a one-to-many relationship: A <<-------> B. B's

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.