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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:06:05+00:00 2026-06-02T08:06:05+00:00

[EDITED to add: It turns out that the answer is very boring and has

  • 0

[EDITED to add: It turns out that the answer is very boring and has nothing to do with Win32, dialog boxes, etc. I just had an idiotic bug in my code. Thanks to Hans Passant for spotting it.]

(This is kinda long. Executive summary: I have a simple Win32 application which creates an icon in the notification area, never shows its main window, and has an “about” box that can be displayed via a right-click on the notification-area icon. For no reason I can fathom, when the “about” box is shown and then closed, the application’s main message loop gets a quit message and it exits. What could I have done wrong to cause this?)


I’m writing a little program that sits in the notification area (“system tray”) and does various not-relevant-here bits of processing in the background. Its UI is almost trivial: you can right-click on the notification-area icon to get a menu, with options “Exit” and “About”; the former quits, the latter pops up a little about-this-program modal dialog.

The application is written in C++ and uses Win32 directly (no MFC or anything). My apologies for being stuck in the stone age.

The only problem is this: when the “About” dialog is closed, the program exits! What could be causing this?

I’m not sure what further information is most useful in figuring this out. Here are a few observations.

  • The sequence of Windows messages at the end of the application’s life, after the dialog’s “OK” button is clicked, is as follows.
    • Dialog box’s proc gets WM_CTLCOLORBTN
    • Application’s (invisible) main window gets WM_ENABLE(TRUE).
    • Dialog box gets WM_CTLCOLORBTN, WM_IMESETCONTEXT, WM_SETFOCUS, WM_WINDOWPOSCHANGING, WM_WINDOWPOSCHANGED, 3xWM_GETICON, WM_NCACTIVATE, 2xWM_GETICON, WM_ACTIVATE, WM_WINDOWPOSCHANGING.
    • Application’s window ges WM_WINDOWPOSCHANGING, WM_NCACTIVATE, messages 0x93, 0x93, 0x91, 0x92, 0x92 (what are these?), WM_ACTIVATE.
    • Dialog box gets WM_KILLFOCUS, WM_IME_SETCONTEXT.
    • Application’s window gets WM_IME_SETCONTEXT.
    • Dialog box gets WM_IME_NOTIFY; so does application’s main window.
    • Application’s window gets WM_SETFOCUS.
    • Dialog box gets message 0x90, WM_DESTROY, WM_NCDESTROY.
  • No further messages after these to either the dialog window’s proc or the main application window’s.
  • Then GetMessage returns 0 in the main message loop (the message is WM_QUIT) and it’s all over.
  • The only call to PostQuitMessage in my code is in the main window’s WndProc, it occurs when the main window gets WM_DESTROY, and it is not in fact called in this scenario.

Perhaps there’s something crazy, or something missing, in my code. Here are some extracts (with a few details, which may not be relevant, elided for brevity).

The rough structure of my WinMain is as follows:

WNDCLASSEX wc;
// fill in fields of wc
RegisterClassEx(&wc);

HWND w = CreateWindow(...);

NOTIFYICONDATA nid;
memset(&nid, 0, sizeof(nid));
// fill in fields of nid
Shell_NotifyIcon(NIM_ADD, &nid);

// (start a background thread to do the real work,
// which is of no interest here)

MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
  if (TranslateAccelerator(msg,hwnd, accel, &msg)) continue;
  TranslateMesage(&msg);
  DispatchMessage(&msg);
}

Shell_NotifyIcon(NUM_DELETE, &nid);
return (int)msg.wParam;

The main window’s WndProc looks like this:

switch (message) {
  case WM_USER_SHELLICON: // my own, attached to the icon's menu
    if (LOWORD(lParam) == WM_RBUTTONDOWN) // ... create menu and return TRUE
    break;
  case WM_COMMAND:
    // menu item
    switch (LOWORD(wParam)) {
      case IDM_ABOUT:
        DialogBox(the_instance, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, AboutProc);
        break;
      case IDM_EXIT:
        DestroyWindow(hWnd);
        break;
      default: return DefWindowProc(hWnd, message, wParam, lParam);
    }
  case WM_DESTROY:
    PostQuitMessage(0);
    break;
  default: return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;

and the dialog box’s proc looks like this:

switch (message) {
  case WM_INITDIALOG:
    // fill in a version string
    return (INT_PTR)TRUE;
  case WM_COMMAND:
    if (LOWORD(wParam)==IDOK || LOWORD(wParam)==IDCANCEL) {
      EndDialog(hDlg, LOWORD(wParam));
      return (INT_PTR)TRUE;
    }
    break;
}
return (INT_PTR)FALSE;
  • 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-06-02T08:06:07+00:00Added an answer on June 2, 2026 at 8:06 am

    There’s a bug in your WndProc() function. The WM_COMMAND case is missing a break. So when it executes, say, IDM_ABOUT then it falls through into the WM_DESTROY case. Sayonara.

    I recommend PC-lint.

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

Sidebar

Related Questions

Edited to Add * I haven't found a solution for this one yet, can
NOTE: Edited to add the Model The Problem: a querystring guid value is giving
I'm using Wamp 2.2, edited conf/extra/httpd-vhosts.conf edited this file to add VirtualHosts , but
Edited: SOLUTION FOUND. This is strange and not the best solution, but I just
--edited for clarity (hopefully) I have an XML file that looks something like this:
To my understanding, the CSS specificity rules indicate that a pseudo class has the
Edited to add: Drat it! I didn't have the latest version of the code.
Edited to add more details: (originally asked nearly two months ago...still haven't found a
(Edited to add an example and hopefully make it a bit clearer) I'm mainly
I'm trying to make a very simple asp.net page that binds a GridView using

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.