How do you make your MDI MFC app show one instance

2019-07-04 04:17发布

问题:

I have an MDI app and when I click new document, it opens up a separate tab. This creates another instance of the icon in the taskbar within Windows. Is there any way I can change this behavior so that only one icon instance is shown the taskbar?

I know one way is to use SDI and use tabs for my views, but I want to keep it an MDI. Is this even possible.

I'm trying to mimic the view of this particular application called 'Dameware NT Utilities': http://www.dameware.com/v3-dameware/media/DameWare/DW%20NTU/Carousel/DRS-Primary-medium.png?width=490&height=276&ext=.png

回答1:

I found the solution after a day of digging around. Gosh, that feels good to finally figure this out. Anyway here is the solution.

I just had to override the childframe's CanShowOnTaskBarTabs() method to return FALSE. Here's the class method:

first, in the childframe.h file, put the following code in the class declaration

public:
     virtual BOOL CanShowOnTaskBarTabs();

Then in your childframe.cpp file, put the following code at the very bottom:

BOOL CChildFrame::CanShowOnTaskBarTabs()
{
    return FALSE;
}

Here's more information on the subject: http://msdn.microsoft.com/en-us/library/ee256255(v=vs.100).aspx