Solved

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

Posted on 1998-09-14
4
263 Views
Last Modified: 2010-04-15
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!!!!
0
Comment
Question by:softyan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:agreen
ID: 1252717
Can you post your code here ?
0
 
LVL 11

Accepted Solution

by:
alexo earned 50 total points
ID: 1252718
Try this one:

////////////////////////////////////////////////////////////////////////////////

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

#define APP_NAME        "DblClk"
#define MYWM_NOTIFYICON (WM_USER + 1)

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
    wc.style         = 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

    RegisterClass(&wc);

    // Create a main window for this application instance.
    hwnd = CreateWindow(APP_NAME, APP_NAME, WS_OVERLAPPEDWINDOW,
                        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);
                break;
            }

        default:
            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;
}

////////////////////////////////////////////////////////////////////////////////

0
 

Author Comment

by:softyan
ID: 1252719
Thanks alexo!
0
 
LVL 11

Expert Comment

by:alexo
ID: 1252720
Have fun!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Read file descriptor 3 in C 14 126
why "." vs "->" 23 124
Passing a array as parameter - C 2 109
Is it possible to delete files one by one rather than the whole? 15 64
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question