XMLCustomizableDialogs.h
上传用户:kj0090
上传日期:2007-03-02
资源大小:39k
文件大小:4k
源码类别:
xml/soap/webservice
开发平台:
C/C++
- /***********************************************************************
- *
- * This module is part of the XMLGUI system
- *
- * File name: XMLCustomizableDialogs.h
- *
- * Creation date: [21 AUGUST 2002]
- *
- * Author(s): [Kolosenko Ruslan]
- *
- * Description: Declares class CXMLCustomizableDialog - template class
- * for various kinds of customizable dialogs
- *
- **********************************************************************/
- #ifndef AFX_XML_CUSTOMIZABLE_DIALOGS_H_RKOL_8_21_2002_
- #define AFX_XML_CUSTOMIZABLE_DIALOGS_H_RKOL_8_21_2002_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #include "DlgTemplate.h"
- #include "xmlgui_resource.h"
- // exported global function declaration, implemented in XMLCustomizable.cpp
- void XMLGUI_EXT_CLASS CXMLCustomizable_CustomizeXML(LPCTSTR szXMLFile);
- template <class DialogClass> class CXMLCustomizableDialog : public DialogClass
- {
- public:
- // one version of constructor accepts resource ID as a reserve
- // for dialog creation if the XML file is not valid
- CXMLCustomizableDialog(LPCTSTR szXMLFile, UINT nResourceID = 0, CWnd* pParent = NULL)
- {
- // store full name of XML file
- m_szXMLFile = szXMLFile;
- // first, try to read dialog template from the XML file
- if ( !m_szXMLFile.IsEmpty() && m_Template.SerializeFrom(m_szXMLFile) )
- {
- // if the XML file with dialog template is valid
- // we initialize our dialog with template read from XML
- InitModalIndirect((LPDLGTEMPLATE)m_Template,pParent,
- m_Template.GetInitData());
- }
- else
- {
- // otherwise we switch to resource dialog's definition
- m_lpszTemplateName = MAKEINTRESOURCE(nResourceID);
- m_nIDHelp = nResourceID;
- m_pParentWnd = pParent;
- }
- }
- // another version of constructor accepts resource name as a reserve
- // for dialog creation if the XML file is not valid
- CXMLCustomizableDialog(LPCTSTR szXMLFile, LPCTSTR szTemplateName, CWnd* pParent = NULL)
- {
- m_szXMLFile = szXMLFile;
- // try to parse XML file with dialog template
- if ( !m_szXMLFile.IsEmpty() && m_Template.SerializeFrom(m_szXMLFile) )
- {
- // if XML parsing successful - initialize dialog from XML
- InitModalIndirect((LPDLGTEMPLATE)m_Template,pParent,
- m_Template.GetInitData());
- }
- else
- {
- // otherwize initialize dialog from the resource file
- m_lpszTemplateName = szTemplateName;
- if (HIWORD(m_lpszTemplateName) == 0)
- {
- m_nIDHelp = LOWORD((DWORD)m_lpszTemplateName);
- }
- m_pParentWnd = pParent;
- }
- }
- virtual ~CXMLCustomizableDialog() {};
- protected:
- // Windows messages handler for the dialog
- virtual BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
- {
- if ( message == WM_CONTEXTMENU )
- {
- // show context menu with "Customize" option
- CMenu menu;
- menu.LoadMenu(IDR_XMLGUI_CUSTOMIZING);
- CMenu* pPopup = menu.GetSubMenu(0);
- pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,MAKEPOINTS(lParam).x,
- MAKEPOINTS(lParam).y,this);
- }
- if ( message == WM_COMMAND && wParam == ID_XMLGUI_CUSTOMIZE )
- {
- // handle "Customize" command from the popup menu
- // global function CXMLCustomizable_CustomizeXML does this
- CXMLCustomizable_CustomizeXML(m_szXMLFile);
- }
- // pass the message to the base class dialog box procedure
- return DialogClass::OnWndMsg(message,wParam,lParam,pResult);
- }
- CDlgTemplate m_Template; // dialog template object holding the Win32 DLGTEMPLATE
- CString m_szXMLFile; // full name of the file with XML-style dialog template
- };
- // instantiation of CXMLCustomizableDialog for MFC class CDialog
- typedef CXMLCustomizableDialog<CDialog> CXMLGUIDialog;
- #endif // AFX_XML_CUSTOMIZABLE_DIALOGS_H_RKOL_8_21_2002_