{"id":4163,"date":"2009-11-23T12:40:00","date_gmt":"2009-11-23T12:40:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2009\/11\/23\/teched-europe-demo-session-face-lifting-mfc-applications-on-windows-7\/"},"modified":"2019-02-18T18:45:43","modified_gmt":"2019-02-18T18:45:43","slug":"teched-europe-demo-session-face-lifting-mfc-applications-on-windows-7","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/teched-europe-demo-session-face-lifting-mfc-applications-on-windows-7\/","title":{"rendered":"TechEd Europe Demo Session &#8211; Face-Lifting MFC Applications on Windows 7"},"content":{"rendered":"<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Hello,<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">My name is Damien Watkins, and I am a Program Manager on the Visual C++ team. Today, I thought I would post the \u201coverview script\u201d for my TechEd Europe session \u2013 so those who could not attend can try it out for themselves at home. My talk was about the new MFC features we have added in Visual Studio 2010.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Just before we get started, I would like to point out that Pat Brenner has been doing some Channel 9 videos on the new MFC functionality too, you can find the first three videos here (and keep your eyes open for more in the future):<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">1.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><a href=\"https:\/\/channel9.msdn.com\/posts\/Charles\/Pat-Brenner-Visual-Studio-2010-MFC-and-Windows-7\/\"><font face=\"Calibri\" size=\"3\">Pat Brenner: Visual Studio 2010 &#8211; MFC and Windows 7<\/font><\/a><font face=\"Calibri\" size=\"3\"> (a 25 minute interview on the rationale for and design of the new MFC features)<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">2.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><a href=\"https:\/\/channel9.msdn.com\/posts\/Charles\/MFC-Implementing-handlers-for-preview-thumbnail-and-search-filtering\/\"><font face=\"Calibri\" color=\"#0000ff\" size=\"3\">MFC: Implementing handlers for preview, thumbnail and search filtering<\/font><\/a><font face=\"Calibri\" size=\"3\"> (a 3 minute \u201cHow To\u201d style video)<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">3.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><a href=\"https:\/\/channel9.msdn.com\/posts\/Charles\/MFC-Integrating-your-application-with-the-Windows-Restart-Manager\/\"><font face=\"Calibri\" color=\"#0000ff\" size=\"3\">MFC: Integrating your application with the Windows Restart Manager<\/font><\/a><font face=\"Calibri\" size=\"3\"> (a 5 minute \u201cHow To\u201d style video)<\/font><\/p>\n<p class=\"MsoNormal\"><b><font size=\"3\"><font face=\"Calibri\">Creating my Solution\/Application<\/font><\/font><\/b><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">To begin, you could run Visual Studio 2010 (VS2010) as an administrator.&nbsp; This is needed to register the \u201cFile Type Handlers\u201d for providing Preview, Search and Thumbnail support for your document type. Alternatively, you could run VS2010 as a normal user and run the command to register the file type handlers in an elevated command prompt.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">After starting VS2010 (and executing it as an Administrator) you will create a new MFC Application (File-&gt;New-&gt;Project or CONTROL+SHIFT+n). In the New Project Wizard you will select MFC Application and enter a name for the Project. In my example below I entered \u201cVCBlogDemo\u201d but you can use anything you like however, if you use the same name as me it will be easier to follow the instructions below when I refer to specific classes, methods, etc. I then click \u201cOK\u201d. As an aside, unless I say otherwise I always select the defaults on any screen.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Now work your way through the MFC Application Wizard dialogs, selecting\/enabling these features as you go:<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">1.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">On the \u201cOverview\u201d page, just click \u201cNext\u201d.<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">2.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">On the \u201cApplication Type\u201d page, set the Project Style to Office (I will show some Ribbon features further on and so I want a Ribbon based UI) and then click \u201cNext\u201d.<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">3.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">On the \u201cCompound Document Support\u201d page, just click \u201cNext\u201d.<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">4.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">On the Document Template Properties page:<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">Add a file extension, I entered demo-ms<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">And I added support for Preview, Thumbnail and Search handler support by clicking the various buttons once they were enabled. <\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">Check the screenshot you have the same settings: <\/font><\/p>\n<p class=\"MsoListParagraph\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/Teched%20talk%201.png\"><\/p>\n<p class=\"MsoListParagraph\"><span><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">Then click \u201cNext\u201d.<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">5.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">On the \u201cDatabase Support\u201d page, just click \u201cNext\u201d.<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">6.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">On the \u201cUser Interface Features\u201d page, just click \u201cNext\u201d.<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">7.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">On the \u201cAdvanced Features\u201d, please note that \u201cSupport Restart Manager\u201d is already selected, and then just click \u201cNext\u201d. <\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">8.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">On the \u201cGenerated Classes\u201d page:<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">Change the Base Class for the CVCBlogDemoView class to CEditView. The reason for doing this is that the default implementation of this class can be used to highlight the Preview, Search and Thumbnail functionality without the need for the developer to write any additional code. Your screen should now look like this:<\/font><\/p>\n<p class=\"MsoListParagraph\"><font face=\"Calibri\" size=\"3\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/teched%20talk%202.png\"><\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font size=\"3\">\u00b7<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">Then click Finish<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Once the Wizard completes, as a quick sanity check, I changed my \u201cSolution Configuration\u201d to be \u201cRelease\u201d, build the solution (F7) and started the application without debugging (CONTROL+F5) \u2013 I essentially just closed it after it I saw it running. Then I returned to VS2010.<\/font><\/p>\n<p class=\"MsoNormal\"><b><font size=\"3\"><font face=\"Calibri\">Configuring Restart Manger and Auto-Save<\/font><\/font><\/b><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">By default, the auto save interval is 5 minutes, but rather than have to wait five minutes after starting the application to demonstrate this functionality I am going to set the interval to 15 seconds. I do this by first finding the command that enables Restart Manger support in the CVCBlogDemoApp constructor and then by adding a line immediately after it. The Constructor will then have these two lines in:<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">m_dwRestartManagerSupportFlags = AFX_RESTARTMANAGER_SUPPORT_ALL_ASPECTS;<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">m_nAutosaveInterval = 15000; \/\/ add this line after the preceding line<\/font><\/p>\n<p class=\"MsoNormal\"><b><font size=\"3\"><font face=\"Calibri\">Editing the Ribbon<\/font><\/font><\/b><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">You can then change to the Resource View and go to the VCBlogDemo project and expand VCBlogDemo.rc. Then expand the Ribbon resources and double click on the IDR_RIBBON resource. Next I dragged a Panel from the Toolbox and plac it on the ribbon. I changed the caption of the panel to \u201cRestart\u201d. I then dragged a Button from the Toolbox to the Restart Panel. I then changed the button\u2019s ID to ID_CRASHME and its Caption to CrashMe. <\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/teched%20talk%203.png\"><\/p>\n<p class=\"MsoNormal\"><b><font size=\"3\"><font face=\"Calibri\">Return of the MFC Class Wizard!<\/font><\/font><\/b><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Now you need to add events handlers for the \u201cCrashMe\u201d button in the ribbon. At this point it becomes time to welcome back an old friend, the Class Wizard. Hit CONTROL-SHIFT-X (different key binding to the original) and the Wizard appears. It is hard to imagine a more commonly requested feature than the return of the Wizard \u2013 we really hope you enjoy using it! <\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Now change the \u201cClass name\u201d field to CVCBlogDemoApp and on the Commands Tab enter ID_CRASHME in the search box. The Class Wizard screen looks like this:<\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/teched%20talk%204.png\"><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Next, selected COMMAND and clicked on \u201cAdd Handler\u201d and then select UPDATE_COMMAND_UI and clicked on \u201cAdd Handler\u201d.&nbsp; The COMMAND handler will crash our application, so we can see the Restart Manager functionality at work. The UPDATE_COMMAND handler will disable the \u201cCrashMe\u201d button until our application has been running for more than 1 minute so Windows Restart Manger machinery is enabled (and so the auto save timeout has expired at least once.) Now use the \u201cEdit Code\u201d button to add the following code (of course, you can add whatever logic you like to enable\/disable the button and terminate the application \u2013 the code below is the simplest and most constrained I could think of \u2013 however it is not an example of good coding practices):<\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" height=\"411\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/teched%20talk%205.png\" width=\"616\"><\/p>\n<p class=\"MsoNormal\"><b><font size=\"3\"><font face=\"Calibri\">Demonstrating our application<\/font><\/font><\/b><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">So now rebuild the Solution and start the application (remember &#8211; it should be built for \u201cRelease\u201d.) When you start the application without debugging (CONTROL+F5) you will notice that the \u201cCrashMe\u201d button is initially disabled. Next I will open two more documents (keying CONTROL-N twice will do). <\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">1.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">In document one I will type \u201cThis document is saved\u201d and click on the save icon and save the documents in the Documents folder.<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">2.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">In document two I will type \u201cThis document is not saved\u201d (and I will NOT save it).<\/font><\/p>\n<p class=\"MsoListParagraph\"><span><span><font face=\"Calibri\" size=\"3\">3.<\/font><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><font face=\"Calibri\" size=\"3\">In document three I will type \u201cThis sentence is saved\u201d and click on the save icon and save the documents in the Documents folder. Next I will type on the second line \u201cThis sentence is not saved\u201d (and I will NOT save it).<\/font><\/p>\n<p class=\"MsoNormal\"><b><font size=\"3\"><font face=\"Calibri\">Windows 7 Taskbar<\/font><\/font><\/b><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">To allow the auto-save functionality time to work, at this point you can hover over the application\u2019s icon in the new Windows 7 Taskbar. Notice how each document has a separate tab (although the writing is very small in this example) and you can see a real time view of the document \u2013 for example notice the flashing cursor in the active document (whichever one that happens to be.)<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/teched%20talk%206.png\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><b><font size=\"3\"><font face=\"Calibri\">Demonstrating the Restart Manager<\/font><\/font><\/b><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Now we can crash the application by clicking on the enabled \u201cCrashMe\u201d button. After taking a few seconds to restart, you get a nice example of our new CTaskDialog and the option to auto-recover our work. <\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/teched%20talk%207.png\"><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">I recover everything by clicking on the \u201cRecover the auto-saved documents\u201d option.&nbsp; Now I hover on the application icon in the task bar and, when the document previews appear, I start closing the documents by clicking on the red X. You will notice how a document that has been saved is just closed, a document that has already been saved&nbsp; but subsequently has been updated will&nbsp; have the \u201cSave\u201d dialog enabled and a document that has never been saved will have the \u201cSave As\u201d dialog enabled.&nbsp; <\/font><\/p>\n<p class=\"MsoNormal\"><b><font size=\"3\"><font face=\"Calibri\">Explorer Interaction<\/font><\/font><\/b><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Finally, I start Explorer in the documents folder, type \u201csaved\u201d in the Search field and select one of the demo-ms files and thus we can see the Icon, Preview and Search functionality.<\/font><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/teched%20talk%208.png\"><\/p>\n<p class=\"MsoNormal\"><b><font size=\"3\"><font face=\"Calibri\">Support for High DPI<\/font><\/font><\/b><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">For those who have a few minutes, at this stage you can change the resolution of your screen and either restart or logoff (depending on your OS requirements) and see how MFC has added support for High DPI displays. <\/font><\/p>\n<p class=\"MsoNormal\"><b><font size=\"3\"><font face=\"Calibri\">Summary<\/font><\/font><\/b><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">As you can see, using the new Windows functionality from MFC is very simple. Add to this the return of the Class Wizard and the addition of the Ribbon Editor and we hope that MFC developers will be excited about the upcoming Visual Studio 2010 release. <\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">One other point, you may notice is that the Ribbon Designer looks a lot like the BCGSoft designer. Again, as with the MFC extensions in VS2008 SP1 (a.k.a. the MFC Feature Pack) we got some assistance from BCGSoft on some of the implementation of the new MFC Features. So that was the overview script of my TechEd Europe talk.<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Thanks,<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">Damien<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">&nbsp;<\/font><\/p>\n<p class=\"MsoNormal\"><font face=\"Calibri\" size=\"3\">&nbsp;<\/font><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello, My name is Damien Watkins, and I am a Program Manager on the Visual C++ team. Today, I thought I would post the \u201coverview script\u201d for my TechEd Europe session \u2013 so those who could not attend can try it out for themselves at home. My talk was about the new MFC features we [&hellip;]<\/p>\n","protected":false},"author":289,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[9,62,10,63,24,16],"class_list":["post-4163","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","tag-channel-9","tag-class-wizard","tag-mfc","tag-restart-manager","tag-ribbon","tag-windows-7"],"acf":[],"blog_post_summary":"<p>Hello, My name is Damien Watkins, and I am a Program Manager on the Visual C++ team. Today, I thought I would post the \u201coverview script\u201d for my TechEd Europe session \u2013 so those who could not attend can try it out for themselves at home. My talk was about the new MFC features we [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/4163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/289"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=4163"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/4163\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=4163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=4163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=4163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}