System tray icon gets disappear when explorer is killed

Discussion in 'Win32' started by gugaliashashank, Jun 13, 2007.

  1. gugaliashashank

    gugaliashashank New Member

    Joined:
    Jun 13, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hi All

    I am using a win32 API

    Code:
    BOOL Shell_NotifyIcon(      
        DWORD dwMessage,
        PNOTIFYICONDATA lpdata
    );
    
    to create the icon in system tray. When i kill the explorer and restart it again my icon disappears from the system tray but the application is running which i can see in task manager.How i can prevent the icon from disappearing.

    I am creating the icon in WM_CREATE Message of my window procedure

    Code:
    static NOTIFYICONDATA ni;
    
    WM_CREATE:
    {
                   hIcon =(HICON) LoadImage( NULL, "pcclient.ico",IMAGE_ICON, 0, 0, LR_LOADFROMFILE) ;
                   (void) memset(&ni, 0, sizeof(ni));
                   ni.cbSize = sizeof(ni);
                   ni.uID = 106;
                   ni.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
                   ni.hIcon = hIcon;
                   ni.hWnd = hwnd;
                   strcpy(ni.szTip,"PC Client");
                   ni.uCallbackMessage = WM_APP ;
                   Shell_NotifyIcon( NIM_ADD , &ni);
                   return true;
    }
    
    WM_CLOSE:
    {      
              Shell_NotifyIcon(NIM_DELETE, &ni);
              return true;
    }
     
    Last edited by a moderator: Jun 13, 2007
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    See what message you get when the explorer is killed and when again its restarted and have similar thing in that messages to have the icon in the tray.
     
  3. gugaliashashank

    gugaliashashank New Member

    Joined:
    Jun 13, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Thanks Shabbir for your suggestion but i too tried to catch the message but i am not able to catch that which message is being called when the explorer is being killed from the task manager
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    How you are trying to catch? Are you using the SPY?
     
  5. gugaliashashank

    gugaliashashank New Member

    Joined:
    Jun 13, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    no i am not using spy what i am doing is that i was trying to print the message number when i killed the exe from the explorer but my wndproc is not even called when this case occur

    Can u plese tell me how to catch the event thru the spy.
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    With the Spy you find the Window and see what are messages passed. Remember to see out the Mouse messages or you will see all the messages being shown and you may loose the messages.

    I am not sure if you will be able to see the window because when you close the Explorer your SPY window may also get closed but you can try.

    As far as I can think off it should be something like WM_QUIT or something similar message.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice