Minimize-to-SysTray for Dialog-Based Applications

Minimize-to-systray is a common UI idiom these days, but Windows doesn't make this task easy.

Another article here at CodeGuru by Dominik Filipp explains one way to implement this. That technique uses the "make your main window owned by an invisible window" trick, and also involves messing with the WS_EX_APPWINDOW style bit. This comes straight out of the MSDN docs, so you'd think it'd work right. Heh.

A minor problem with Filipp's article is that the code relies on CWnd::PreCreateWindow() being called to set up a critical window ownership relation, but this doesn't get called for CDialog-based windows. You can set this relation up another way, but then you hit another problem: when you minimize, the taskbar button disappears, but then you get an MDI-like "minimized window" icon on your desktop just above the taskbar.

I have no doubt that Filipp's code works fine if your main window is derived from CWnd, but it fails for CDialog-based windows. Small utility apps are the most likely to use this idiom, and such apps are usually easiest to build as a dialog-based program. You could use CFormView, as it is derived from CWnd yet lets you use a dialog template. But, that's a lot harder than a true dialog-based app. What we need instead is a technique that works with CDialog-based apps without a lot of trickery.

My technique works with dialog-based applications, and presumably also with regular CWnd-based apps, though I haven't tested it. Instead of all that trickery with invisible "owner" windows and twiddling style bits, we just hide the main dialog when we get minimized. Windows sees that we're invisible and minimized, so it removes our button from the taskbar. We show the window again when we get restored.

The code accompanying this article also illustrates how to integrate this technique with a systray icon. It follows the usual pattern: you minimize the main window, it disappears from the taskbar and puts an icon in the systray. Then when you double-click on the systray icon, the icon disappears and the main dialog window is restored.

The sample project (16 KB) is a basic AppWizard-generated dialog-based app with a few modifications. This list will tell you what you need to cut-and-paste out of the sample project to add this feature to your own apps:

  1. Add a handler for WM_SYSCOMMAND, for handling the "you're being minimized" event. You may just be able to copy CTBHideDlg's OnSysCommand() handler and the SetupTaskBarButton() and SetupTrayIcon() functions into your CDialog class.

  2. I use Chris Maunder's CSystemTray class (included in the zip file) to handle the systray icon. You may need to #include <afxdisp.h> in your stdafx.h file in order to get CSystemTray to compile. Alternatively, you can yank out all the animated icon stuff, which is what I do in my own projects. (I can't distribute that version, though, due to the license CSystemTray is distributed under.)

  3. Create a simple popup menu for attaching to the systray icon, and add command handlers for the menu items. (E.g. Restore, About, Exit, etc.)

  4. Override DestroyWindow(). In it, manually get rid of the systray icon since Windows won't do it for you.

  5. You may want to add code to handle the case where the user wants to start the app minimized. MFC won't handle this case for CDialog-based apps, so you have to do it yourself. Note that this only works right if the dialog you want to minimize has the WS_VISIBLE style set when you create it. If not, Windows ignores you when you say ShowWindow(SW_HIDE) in the minimize handler, and you get a systray icon and a taskbar button.


Download demo project - 15 Kb


  • What are the NBA superstars and American singers desire utilization Studio

    Posted by motherdhmm on 06/04/2013 12:50pm

    [url=]Beats headphones shop[/url] A lot of make believe, Hellishness Beats Studio, online blow the whistle on buy like basis penalty to charm more people to buy their products, their prices are very cheap. But you obligated to not exclusive prefer to steal because they are low-cost, in besides to price, should learn more in Eyesore¡¯s quality. When you¡¯re ready to buy a Hellishness Beats Stud, online, you ought to open to to a few online shop to conceive of and set off, and for ever fill out a pick is recommended. [url=]monster beats Australia[/url] The headset almost never that the smoke of province parameters, which is a petty less than. In details headphones and lamp, but also to withstand the power of the immensity of the balance between 110 volt light bulb connected to 220 volts will light bulb burned, the headset is the same. Users should be eminent that conversion Walkman power parameters, fitting to the limitations of battery-powered Walkman, Walkman produce is generally just a scattering milliwatts, adaptation Walkman feeling is very squiffed, while its power to bear wit is relatively low. Obligated to produce results stuffy publicity to this kidney of headphone pour down the drain or use on a computer on the desktop CD, abundance Ambassador headphones snake, diaphragm deformation, burned [url=]Dre beats solo HD[/url] If that is also not distinctively headset devilry of the harmonious ' sui generis skills, is that when you listen to music if someone looking quest of you, you do not require to take far-off the monster headphones, but can favour down the honourable heed, the ¡°b¡±symbols, the concert was instantly interrupted, and the rumble reduction responsibility determination terminate working, while the judicious of the outside exceptional longing be enlarged. Release the penmanship, everything returned to routine, you¡¯re aid to your circle of music.

  • Third party blog post displays Some all new things of mizuno that noone is talking about.

    Posted by BobHotgloff on 05/22/2013 11:59am

    Concepts of sneakers that it's possible to benefit from starting up today. [url=【ニューバランス】-c-670.html]newbalance[/url] The main reason why the whole thing you've find out about shoes is simply drastically wrong and what you must understand. [url=【ナイキ】-c-634.html]ナイキスニーカー[/url] Quick summary explains the most important details of the shoes and also what you want to try and do right away. [url=]アディダス[/url] Hot shoes Guide Exposes Proven Methods To Dominate The shoes World [url=アディダス-adidas-c-4.html]adidas[/url] The key reason why everything you have discovered about sneakers is truly entirely wrong and what you need to understand. [url=アシックス-asics-c-3.html]asics[/url] The best formula for the shoes you could find out more about right away. [url=ナイキ-nike-c-13.html]ナイキ スニーカー[/url] Cutting edge review unveils the know-how about shoes in addition to the reason why you should take action now. [url=]アシックス[/url] All new shoes Guide Unveil Ideas On How To Rule The shoes Marketplace [url=アディダス-c-74.html]adidas originals[/url] Creative shoes E-book Presents The Way To Rule The shoes Scene [url=ニューバランス-c-13.html]ニューバランス キッズ[/url] What advisors don't seem to be thinking on the subject of shoes and ways it has impact on you. [url=ナイキ-c-78.html]ナイキ[/url] Explanation why so many people are absolute wrong on sneakers and consequently the reasons you must read through this statement. The Actual Easy Methods To Understand shoes And How One Might Join The sneakers Elite [url=]アシックス[/url] Focus and performance in Brooklyn : shoes basically leaves with no adios [url=アディダス-c-64.html]adidas アディダス[/url] The shoes Small business Meaning - Customers who cares about nothing gains all bonuses? [url=ニューバランス-c-21.html]new balance[/url] Interesting queries about shoes replied and consequently why you should really look at every single statement of this post. [url=ナイキ-c-44.html]ナイキ スニーカー[/url] The best way to discover every little thing there is to learn around shoes in nine easy steps. [url=]ベルーナ[/url] The simple way to master all the stuff there is to understand relating to shoes in Six relatively easy steps. [url=【アディダス】-c-1.html]adidas[/url] Recent queries about shoes clarified and in addition the reason why you ought to read carefully every single term within this article. [url=【ニューバランス】-c-206.html]newbalance[/url] The supreme solution for the sneakers you could check out this afternoon. [url=【ナイキ】-c-215.html]ナイキ ランニングシューズ[/url] Some form of double strain on shoes [url=]アディダス[/url] The Arcane secrets For shoes [url=【アディダス】-c-640.html]adidas[/url] The ideal double twist on sneakers

  • Lightweight smart – Nike Let off TR Attack in jump 2013 3 series

    Posted by Tufffruntee on 04/21/2013 04:07pm

    Nike Free TR Suited 3 prominent features is to exploit the additional scheme: Nike On the loose 5 soles improved bending Gouge; supplemental tractor imitate making training more focused when; lighter ballast, the permeability is stronger, and more fashionable shoe designs not only order shoes [url=]air max 90 uk[/url] more pleasant wearing, barefoot training sensible of, but also more fashionable appearance. Nike Free TR Fitting 3 provides supreme lateral solidity, you can be suffering with the legs in the lap boost during training. Diligent vamp majuscule letters breathable webbing, drop foam's one of a kind design can be [url=]nike huarache free[/url] seen by virtue of it. Lightweight, demanding, reduce foam material habituated to at hand entirely some seams, more flexible, advocate is stronger. Requirement more mainstay, part of a training utilize, foam come in more parts of the need for agreeableness, bubbles loose. Say double tongue moisture wicking fake materials, flat on your feet, mitigate living feet tiring and comfortable. Phylite [url=]nike huarache free[/url] midsole offers lightweight stupor unceasing, famous durability and unbroken outsole can do to greatly lower the overall load of the shoe. Qianzhang pods on the outsole and heel-shaped Unripened rubber enhances the shoe multi-directional drag on sundry surfaces.

  • Isabel Marant Sneakers

    Posted by CrengarnexSap on 03/29/2013 04:04am

    Hong Kong Celebrities in [url=]Isabel Marant Sneaker Wedges[/url] Spotted – Kelly Chen, Florinda Ho and Hillary Tsui looking knowledgeable in Isabel Marant pieces from the Spring/Summer 2012 collection. We also spotted Joey Yung at the party IT threw since Isabel while she was in hamlet at Zuma mould week. Isabel Marant Opens Third Hong Kong Store on Ice Dynasty Boulevard, Coming to Borough on May 19 Study on how YOU can win a chance to upon Isabel in Hong Kong! The new, and third in Hong Kong, Isabel Marant store on Ice Dwelling-place Drive in Pre-eminent covers an area of 570sq.ft. with the décor being a collaboration between Isabel Marant and the French construction partnership ciguë. To celebrate the highest chance of the new Ice House High road collection, the together from France has expressly designed a pair of Asian fixed edition morose tie-dye sneakers, simply handy at Isabel Marant Paris, Hong Kong and Beijing. Mind our gallery of the imaginative cumulate in this world and how you can fasten us at an unique cocktail opening as a service to Isabel at Zuma on May 19. And we’re dialect right wrought up to proffer a setting after one of our Butterboom readers and their lover to join us pro a cocktail party with Isabel Marant at Zuma on Saturday May 19 in the evening. You’ll be able to come across her and shoplift photos with her and learn more less her plans here in Hong Kong. All you tease to do is guarantee b make amends for this puzzle in the comments beneath: “What year did Isabel Marant launch her [url=]isabel marant sneaker wedges[/url]? Any stable fan should recognize this and we’ll randomly pick one winner with the reprimand surrejoinder at noon on Thursday, May 17th and email them directly. Western bird's pure and callow and rebellion: Isabel Marant 2012 qiu dong If it weren't representing Isabel Marant on the form of the 2012 qiu dong is based color with darker tones, at in the beginning gleam, leak b feign a child cogitate on this is designed on appear and summer emotionless: the embroidered neckline like classical tablecloth, white bud silk, silk skirt flurry skirt is placed, and nine minutes of pants is decorated with a gold tie frail and soft. But little by little, the whole series ordain appear more elements of qiu dong: the cartel of swart and dark down, rivet elements, cortex and oversize suit jacket... Isabel Marant design with a view this period, with ageless hinterlands fianc‚e in the western United States as the theme, the pure and still in diapers and insubordinate, holiday and sexy so along with the gender nature. Along with the gender constitution with unmanageable unruly and sensuous, lean to be more in the streets is wearing Isabel Marant label consistent characteristics. Conference models this edible makeup is sent along with the gender nature. Each select of get-up, at any mores be able to step them in the main part in the boulevard, and the split between also can marry other look stretch is tasted. Designer Isabel Marant curtain telephone at the completion, it illustrates the tees: the latest embroidery phnom penh another avenue recreational latest thing of pants collocation, rather prosaic T lengthy, also along with the gender you cause it.

  • Works also with regular CWnd-based apps

    Posted by paolor on 01/30/2005 12:20am

    I've used it on an SDI application. Thanks!

  • Win2000 doubleclick problem

    Posted by Legacy on 06/12/2001 12:00am

    Originally posted by: Jay Prall

    This works great, except for one small problem in windows 2000. If you have a dialup networking connection, which is also a systray icon, and you double click your icon in the systray, it will restore the application as well as bring up the properties for the dialup networking session.

    I have produced this problem in the project I added the class to as well as the sample project.

    If I find a solution I will let you know.


  • One question???

    Posted by Legacy on 03/19/2001 12:00am

    Originally posted by: Vivek

    I've one main window which Im not showing and I have one dialog box which is the child window of main window. Since Im not showing main window, so Im not able to see any window in task bar. I want to show my window in taskbar as well as I don't want to show my main window also. any help?


    • answer to "One question???"

      Posted by Cloud Lee on 12/20/2004 03:00am

      If you create child dialog from the main window, the main window must be showed too. But if you create it from systray menu, it will be displayed alone.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date