CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Faltering Windows support
  • Internet Explorer 8 Click Clever Click Safe
  • Release Candidate 2 for ASP.NET MVC 2
  • Learn How to Create Dual Mode Windows Services

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 9th, 2009, 01:51 AM
    mrtndimitrov mrtndimitrov is offline
    Junior Member
     
    Join Date: Sep 2007
    Posts: 19
    mrtndimitrov is an unknown quantity at this point (<10)
    Shell_NotifyIcon( NIM_DELETE, ... ) fails on app exit

    Hello all,

    I have quite a strange problem. My program is based on MFC dialog but modeless. It starts hidden and creates a tray icon. The user can exit it in two ways: if the program is visible the user can press the exit button; if the program is not visible the user can right click on the tray icon and press exit. Both of these message handle routines call CWnd:estryWindow which calls my OnDestroy which calls Shell_NotifyIcon( NIM_DELETE, ... ). On XP and 7 everything works fine but on Vista when the app is exiting through the tray icon message handler the call to Shell_NotifyIcon( NIM_DELETE, ... ) returns FALSE with GetLastError() returning 0. The result is that the icon does not disappear with the exiting of the app but only when the tray bar is refreshed (the mouse goes over it).

    Any ideas will be highly appreciated.
    Reply With Quote
      #2    
    Old November 9th, 2009, 08:25 AM
    hoxsiew hoxsiew is offline
    Senior Member
     
    Join Date: Feb 2005
    Posts: 1,475
    hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+)
    Re: Shell_NotifyIcon( NIM_DELETE, ... ) fails on app exit

    I don't know about vista, but typically in a tray app, I use PostQuitMessage(); rather than DestroyWindow().
    Reply With Quote
      #3    
    Old November 9th, 2009, 08:34 AM
    VictorN's Avatar
    VictorN VictorN is offline
    Elite Member
    Power Poster
     
    Join Date: Jan 2003
    Location: Wallisellen (Zürich), Switzerland
    Posts: 10,221
    VictorN has a reputation beyond repute (3000+) VictorN has a reputation beyond repute (3000+) VictorN has a reputation beyond repute (3000+) VictorN has a reputation beyond repute (3000+) VictorN has a reputation beyond repute (3000+) VictorN has a reputation beyond repute (3000+) VictorN has a reputation beyond repute (3000+) VictorN has a reputation beyond repute (3000+) VictorN has a reputation beyond repute (3000+) VictorN has a reputation beyond repute (3000+) VictorN has a reputation beyond repute (3000+)
    Re: Shell_NotifyIcon( NIM_DELETE, ... ) fails on app exit

    Quote:
    Originally Posted by hoxsiew View Post
    I don't know about vista, but typically in a tray app, I use PostQuitMessage(); rather than DestroyWindow().
    Why not a WM_CLOSE?
    __________________
    Victor Nijegorodov
    Reply With Quote
      #4    
    Old November 9th, 2009, 09:19 AM
    hoxsiew hoxsiew is offline
    Senior Member
     
    Join Date: Feb 2005
    Posts: 1,475
    hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+)
    Re: Shell_NotifyIcon( NIM_DELETE, ... ) fails on app exit

    Why not? Beats me. I just looked at some working code and I used PostQuitMessage() in that case.
    Reply With Quote
      #5    
    Old November 9th, 2009, 11:00 AM
    mrtndimitrov mrtndimitrov is offline
    Junior Member
     
    Join Date: Sep 2007
    Posts: 19
    mrtndimitrov is an unknown quantity at this point (<10)
    Re: Shell_NotifyIcon( NIM_DELETE, ... ) fails on app exit

    To my opinion it really doesn't matter which route you take to exit the app. CWnd :: DestryWindow eventually calls PostQuitMessage which generates WM_QUIT message and the app exits. With modeless dialogs we should not call EndDialog. WM_CLOSE message is sent even before and it calls DestroyWindow. So, this is really not the issue.
    Reply With Quote
      #6    
    Old November 9th, 2009, 11:08 AM
    egawtry's Avatar
    egawtry egawtry is offline
    Member +
     
    Join Date: Oct 2005
    Location: Minnesota, U.S.A.
    Posts: 566
    egawtry has a spectacular aura about (125+) egawtry has a spectacular aura about (125+)
    Re: Shell_NotifyIcon( NIM_DELETE, ... ) fails on app exit

    I don't know about Vista, but I have discovered (back with W2K) that the Message Loop needs to still be going for the Shell_NotifyIcon() calls to work. Make sure you are calling it early enough before the ExitInstance().

    -Erik
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 10:51 AM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.