Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

How to show a dialog box when double clicking on the system tray icon?

I have a program that add an icon to the system tray. I want to show a dialog when i double clicking on my dialog, but i failled. I use the "DialogBox" macro to generate dialog under the WM_LBUTTONDBLCLK of the system tray message. No matter how i try it wouldn't show me the dialog. Is there anything else i miss before using this "DialogBox" macro?
Currently, i'm using C to write this program.. Please help...
Thanks in Advance!!!!
  • 2
1 Solution
Can you post your code here ?
Try this one:


#define STRICT
#include <windows.h>
#include <shellapi.h>
#include "resource.h" // defines IDI_ICON & IDD_DIALOG

#define APP_NAME        "DblClk"

static LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
static BOOL CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

static HINSTANCE g_hInstance;


// Main routine
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    NOTIFYICONDATA  nid     = { sizeof(NOTIFYICONDATA) };
    WNDCLASS        wc      = { 0 };

    HWND            hwnd;
    MSG             msg;

    g_hInstance = hInstance;

    // Register the window class for the application main window         = CS_HREDRAW | CS_VREDRAW; // Class style(s)
    wc.lpfnWndProc   = (WNDPROC) WindowProc;    // Window Procedure
    wc.hInstance     = hInstance;               // Owner of this class
    wc.lpszClassName = APP_NAME;                // Name to register as


    // Create a main window for this application instance.
                        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
                        NULL, NULL, hInstance, NULL);

    // Link with tray icon
    nid.hWnd = hwnd;
    nid.uID = IDI_ICON;
    nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
    nid.uCallbackMessage = MYWM_NOTIFYICON;
    nid.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));
    lstrcpy(nid.szTip, APP_NAME);

    Shell_NotifyIcon(NIM_ADD, &nid);

    // Acquire and dispatch messages until a WM_QUIT message is received.
    while (GetMessage(&msg, NULL, 0, 0))
        TranslateMessage(&msg);  // Translates virtual key codes
        DispatchMessage(&msg);   // Dispatches message to window

    // Delete tray icon
    Shell_NotifyIcon(NIM_DELETE, &nid);

    return 1;


// Main window message processing procedure
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    switch (msg)
        // Tray icon notification message
        case MYWM_NOTIFYICON:
            // Button event is single click?
            if (lParam == WM_LBUTTONDBLCLK)
                DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, DlgProc);

            return DefWindowProc(hwnd, msg, wParam, lParam);

    return 0;


// Dialog message processing procedure
static BOOL CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    switch (msg)
        case WM_COMMAND:
            EndDialog(hwnd, TRUE);
            return TRUE;

    return FALSE;


softyanAuthor Commented:
Thanks alexo!
Have fun!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now