Today's tutorial will guide you through the process of creating filter settings page for the Reverse filter we created in last article. The page will be displayed as a part of the regular system dialog after clicking the "Advanced" button for our sample XPS driver and will be very simple as it will contain just one checkbox (for enabling/disabling the reverse function).
The settings, however, will have no effect yet - the filter will be always active. Connecting the settings to the filter will be discussed in some future article.
Unlike the previous article, today's all work will be done only in [sample root]\src\ui directory.
- Open [sample root]\src\ui\xdsmpldlg.rc resource file for edit (in MSVC).
- Right-click the Dialog tree item, choose "Add resource..." and create new dialog. In Properties set this dialog's ID to IDD_REVERSE. Then also make following changes:
- set 3D look to true
- set Border to none
- set Style to Child
- set System menu to false
- set Disabled to true
- Now add a checkbox control to the dialog. Call it IDC_CHECK_REVERSE and let its caption be "Revert page order".
- Go back to resources tree and double click the String table [English (U.S.)] to open it. Choose "New string" on right click to add new string into table. Call it IDS_REVERSE and let its caption be "Reverse". This string will represent the title of our new settings page.
- That's all for visual design. Now let's move to the second part - coding. To follow the style of coding of the other filters, we now have to create 4 new files in current ui directory:
- revctrls.h
- revctrls.cpp
- revppg.h
- revppg.cpp
- Every control class must contain: constructor, virtual destructor, private static string. If the control need some initialisation (e.g. setting default value), the class must also contain an overriden OnInit method.
- Every page class must contain constructor, virtual destructor and overriden method InitDlgBox (which will set the dialog UI template and title).
- Open xdsmplui.cpp for edit and add the #include "revppg.h" line to the beginning (right after the line 31 where the ftrppg.h file is included). Go to line 920 inside the CreatePropertyPages function and add the following CReversePropPage class instance creating:
if (SUCCEEDED(hr))
{
pPropPage = new CReversePropPage();
if (SUCCEEDED(hr = CHECK_POINTER(pPropPage, E_OUTOFMEMORY)))
{
m_vectPropPages.push_back(pPropPage);
}
}
This code snippet creates a new instance of our setting page and adds it in the pages vector if successful. When user opens the "Advanced" dialog of our XPS printer (in Windows Control Panel), the system calls DocumentPropertySheets function where the content of this vector is processed (PropPageInit function is then called on every page which invokes the provided InitDlgBox function of each page). - We are almost done here. Now open the sources file and add revctrls.cpp and revppg.cpp to SOURCES variable for these files to get compiled.
- Run x86 build environment (for Vista or later), type build -cZ, hit enter.
- Reinstall the driver of our XPS sample printer.
- Open any document and call print dialog. After selecting our sample XPS printer, click "Advanced" button and see the new tab with your brand new settings page :)
No comments:
Post a Comment