Click here to Skip to main content
15,896,207 members
Articles / Desktop Programming / WTL

TDXML: XML-Based Task Dialogs with a Visual Task Dialog Editor

Rate me:
Please Sign up or sign in to vote.
4.92/5 (67 votes)
19 Mar 200713 min read 100.7K   1.4K   90  
A library and a visual editor that make it easy to build task dialogs and use them in your C++ applications
#ifndef BUTTONSTOOLSPAGE_H_INCLUDED
#define BUTTONSTOOLSPAGE_H_INCLUDED

/////////////////////////////////////////////////////////////////////////////

class CButtonsToolsPage : public CDialogImpl<CButtonsToolsPage>,
                          public CWinDataExchange<CButtonsToolsPage>
{
public:
    enum { IDD = IDD_BUTTONS_TOOLS };

    // Construction
    CButtonsToolsPage();
    ~CButtonsToolsPage();

    // Maps
    BEGIN_MSG_MAP(CButtonsToolsPage)
        MSG_WM_INITDIALOG(OnInitDialog)
        COMMAND_ID_HANDLER_EX(IDC_ADD, OnAdd)
        COMMAND_ID_HANDLER_EX(IDC_EDIT, OnEdit)
        COMMAND_ID_HANDLER_EX(IDC_DELETE, OnDelete)
        COMMAND_ID_HANDLER_EX(IDC_CLEAR_ALL, OnClearAll)
        COMMAND_ID_HANDLER_EX(IDC_MOVE_UP, OnMoveUp)
        COMMAND_ID_HANDLER_EX(IDC_MOVE_DOWN, OnMoveDown)
        COMMAND_ID_HANDLER_EX(IDC_RESET_IDS, OnResetIDs)
        COMMAND_RANGE_CODE_HANDLER_EX(IDC_OK_BTN, IDC_NO_BUTTON_ICONS,
                                      BN_CLICKED, OnCheckboxClicked)
        COMMAND_CODE_HANDLER_EX(CBN_SELCHANGE, OnComboboxSelchanged)
        NOTIFY_CODE_HANDLER_EX(LVN_DELETEITEM, OnListDeleteitem)
        NOTIFY_CODE_HANDLER_EX(LVN_KEYDOWN, OnListKeydown)
        NOTIFY_CODE_HANDLER_EX(NM_DBLCLK, OnListDblclk)
    END_MSG_MAP()

    BEGIN_DDX_MAP(CButtonsToolsPage)
        DDX_CHECK(IDC_OK_BTN, m_bOK)
        DDX_CHECK(IDC_YES_BTN, m_bYes)
        DDX_CHECK(IDC_NO_BTN, m_bNo)
        DDX_CHECK(IDC_CANCEL_BTN, m_bCancel)
        DDX_CHECK(IDC_RETRY_BTN, m_bRetry)
        DDX_CHECK(IDC_CLOSE_BTN, m_bClose)
        DDX_CHECK(IDC_USE_COMMAND_LINKS, m_bUseCommandLinks)
        DDX_CHECK(IDC_NO_BUTTON_ICONS, m_bNoIcons)
        DDX_CONTROL_HANDLE(IDC_CUSTOM_BTNS, m_wndList)
        DDX_CONTROL_HANDLE(IDC_DEFAULT_BUTTON, m_wndDefaultBtnCombo)
    END_DDX_MAP()

    // Message handlers
    BOOL    OnInitDialog ( HWND hwndFocus, LPARAM lParam );

    // Command handlers
    void    OnAdd ( UINT uCode, int nID, HWND hwndCtrl );
    void    OnEdit ( UINT uCode, int nID, HWND hwndCtrl );
    void    OnDelete ( UINT uCode, int nID, HWND hwndCtrl );
    void    OnClearAll ( UINT uCode, int nID, HWND hwndCtrl );
    void    OnMoveUp ( UINT uCode, int nID, HWND hwndCtrl );
    void    OnMoveDown ( UINT uCode, int nID, HWND hwndCtrl );
    void    OnResetIDs ( UINT uCode, int nID, HWND hwndCtrl );

    // Notification handlers
    void    OnCheckboxClicked ( UINT uCode, int nID, HWND hwndCtrl );
    void    OnComboboxSelchanged ( UINT uCode, int nID, HWND hwndCtrl );
    LRESULT OnListDeleteitem ( NMHDR* phdr );
    LRESULT OnListKeydown ( NMHDR* phdr );
    LRESULT OnListDblclk ( NMHDR* phdr );

    // Data
    CWindow m_wndTD;

    // Operations
    bool FillInTDConfig ( TASKDIALOGCONFIG& tdc );
    void OnTDNavigated();
    bool SaveToXML ( IXMLDOMDocumentPtr& pDoc, DWORD& dwFlags );

protected:
    // DDX vars
    bool m_bOK, m_bYes, m_bNo, m_bCancel, m_bRetry, m_bClose,
         m_bUseCommandLinks, m_bNoIcons;
    CListViewCtrl m_wndList;
    CComboBox m_wndDefaultBtnCombo;

    // Data
    CImageList m_iml;
    int m_nNextButtonID;
    std::vector<TASKDIALOG_BUTTON> m_vecButtons;
    std::list<CString> m_lsButtonText;

    void MoveListCtrlItem ( int nOldIdx, int nNewIdx );
    void AddButtonToComboBox ( int id, LPCTSTR szButtonName );
    void DeleteButtonFromComboBox ( int id );
};

#endif  // ndef BUTTONSTOOLSPAGE_H_INCLUDED

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) VMware
United States United States
Michael lives in sunny Mountain View, California. He started programming with an Apple //e in 4th grade, graduated from UCLA with a math degree in 1994, and immediately landed a job as a QA engineer at Symantec, working on the Norton AntiVirus team. He pretty much taught himself Windows and MFC programming, and in 1999 he designed and coded a new interface for Norton AntiVirus 2000.
Mike has been a a developer at Napster and at his own lil' startup, Zabersoft, a development company he co-founded with offices in Los Angeles and Odense, Denmark. Mike is now a senior engineer at VMware.

He also enjoys his hobbies of playing pinball, bike riding, photography, and Domion on Friday nights (current favorite combo: Village + double Pirate Ship). He would get his own snooker table too if they weren't so darn big! He is also sad that he's forgotten the languages he's studied: French, Mandarin Chinese, and Japanese.

Mike was a VC MVP from 2005 to 2009.

Comments and Discussions