|
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionRecently we came across a problem where we needed to have multiple dialogs within a single property page or dialog. This article will explain how we did it. From the internal thread that went around the company, this feature was the source of endless confusion and rewrites. The various sample on the Internet did not help matters much as they required custom derivations for both the This article documents the steps required to provide an embedded dialog(s) within a dialog using MFC. There are no extension classes provided as this provides the technical insight to modify your code to support embedded dialogs. BackgroundEmbedding a dialog within a property sheet or another dialog appears to be the source of much confusion and various attempts over the years. Sadly I was unable to find a solution that worked transparently and cleanly. There are various flavour of solutions on the net, but not one that had the look and feel of a correct solution. I then came across article “Q131283 - PRB: Cannot Use TAB to Move from Standard Controls to Custom” on Microsoft’s website and it all became clear. The solution we required was to be simple (it was only on one dialog), easy to use (For end users), simple to maintain (not everyone in the company is a guru). The solution chosen was to have a tab strip and then Whilst this appears to be simple enough to document, implementing it proved to be more of a challenge, especially with regards to using the keyboard to tab which is an integral feature of the product. Users need to be able to tab in and out of the dialog and the dialog should at the same time look integral to the main window. This type of design also allows the developer to set the tab control at compile time and runtime by specifying options such as images and tab name, using the common controls API. Using the codeIn the code section I have given an example that shows how a programmer would go about implementing the two embedded dialogs within a new dialog. These dialogs are selectable by clicking or navigating onto the tab control. Note that you can set the focus to the tab control and then use the left and right arrows to select the appropriate tab, then using the tab key, tab into and out of the dialog. The first thing to do is to create the dialogs that will be embedded in the main dialog. These are just two straight forward It is recommended that the Frame type be set to Dialog Frame. Additionally you can set the X and Y positions of the dialog relative to its parent. The dialog to be embedded should be offset so that the dialog frame top appears as the tab frame bottom. This is of course a matter of personal preference and aesthetics. In the sample there are two dialogs that have been created. Now we have built the two dialogs to be embedded in the main dialog, we can create the main dialog. We create a new Dialog class called Having created the dialogs, we need to add includes for the two public:
CDialog2 m_dlg2;
CDialog1 m_dlg1;
Next, we insert a new tab control resource into the dialog resource for the The only function we need in the The final piece of the jigsaw is the The first step in this method is to create the two tabs that we will be using. m_ctlTab1.InsertItem(TCIF_TEXT, 0, _T("Dialog1"), 0,0,0,0); m_ctlTab1.InsertItem(TCIF_TEXT, 1, _T("Dialog2"), 0,0,0,0); Next, we create modeless instances of the two dialogs as indicated below. m_dlg1.Create(CDialog1::IDD, this); m_dlg2.Create(CDialog2::IDD, this); Note that we make the two dialog instances' parents the Now, if you call m_dlg2.SetWindowPos(GetDlgItem(IDC_TAB1), 0, 0, 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE); m_dlg1.SetWindowPos(GetDlgItem(IDC_TAB1), 0, 0, 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE); To do this we use the SetWindowPos function and tell the window where it should be in the tab order. Note that we have reversed the order of the One final point to note that even though it is not in the code, from within Points of InterestI was amazed at how easy it was to implement embedded dialogs once the HistoryFollowing the discussion on the thread I have shown how to add support for XP Themes. To add theme support is a two step operation. The first step is to create a manifest file either embedded as a resource or a separate file with a yourapp.exe.manifest filename. If either are present and you are running XP then the application will take on the theme of the current XP theme. The second step is to make the tabs appear the same color as the background. This is achieved by calling I have added two additional configurations in the .dsp file, one called Win32 XP Debug and Win32 XP Release. For a good article on theming see Using Windows XP Visual Styles on the Microsoft web site.
|
||||||||||||||||||||||||||||||