XMLCustomizableForms.h
上传用户:kj0090
上传日期:2007-03-02
资源大小:39k
文件大小:6k
源码类别:
xml/soap/webservice
开发平台:
C/C++
- /***********************************************************************
- *
- * This module is part of the XMLGUI system
- *
- * File name: XMLCustomizableForms.h
- *
- * Creation date: [21 AUGUST 2002]
- *
- * Author(s): [Kolosenko Ruslan]
- *
- * Description: Declares class CXMLCustomizableForm - template class
- * for various kinds of customizable form views
- *
- **********************************************************************/
- #ifndef AFX_XML_CUSTOMIZABLE_FORMS_H_RKOL_8_21_2002_
- #define AFX_XML_CUSTOMIZABLE_FORMS_H_RKOL_8_21_2002_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #include "DlgTemplate.h"
- #include "xmlgui_resource.h"
- // exported global functions declaration, implemented in XMLCustomizable.cpp
- void XMLGUI_EXT_CLASS CXMLCustomizable_CustomizeXML(LPCTSTR szXMLFile);
- #ifndef _AFX_NO_OCC_SUPPORT
- void XMLGUI_EXT_CLASS CXMLCustomizable_InitializeForm(CFormView* pFormView,
- _AFX_OCC_DIALOG_INFO* pOccDialogInfo, CDlgTemplate* pDlgTemplate,
- LPCTSTR szTemplateName);
- #endif /* _AFX_NO_OCC_SUPPORT */
- template <class FormClass> class CXMLCustomizableForm : public FormClass
- {
- public:
- // one version of constructor accepts resource ID as a reserve
- // for form creation if the XML file is not valid
- CXMLCustomizableForm(LPCTSTR szXMLFile, UINT nDlgResourceID = 0)
- :FormClass(nDlgResourceID)
- {
- // store the name of the XML file for later use in the Create method
- m_szXMLFile = szXMLFile;
- }
- // another version of constructor accepts resource name as a reserve
- // for dialog creation if the XML file is not valid
- CXMLCustomizableForm(LPCTSTR szXMLFile, LPCTSTR szTemplateName)
- :FormClass(szTemplateName)
- {
- // store the name of the XML file for later use in the Create method
- m_szXMLFile = szXMLFile;
- }
- virtual ~CXMLCustomizableForm() {};
- // Create method is similar to MFC class CFormView::Create
- // only functionality to load dialog template from XML is added
- virtual BOOL Create(LPCTSTR /*lpszClassName*/, LPCTSTR /*lpszWindowName*/,
- DWORD dwRequestedStyle, const RECT& rect, CWnd* pParentWnd, UINT nID,
- CCreateContext* pContext)
- {
- m_pCreateContext = pContext; // save state for later OnCreate
- // call PreCreateWindow to get prefered extended style
- CREATESTRUCT cs;
- memset(&cs, 0, sizeof(CREATESTRUCT));
- if ( dwRequestedStyle == 0 )
- {
- dwRequestedStyle = AFX_WS_DEFAULT_VIEW;
- }
- cs.style = dwRequestedStyle;
- if ( !PreCreateWindow(cs) )
- {
- // form view creation is aborted in the overriden PreCreateWindow
- return FALSE;
- }
- // try to parse XML file with dialog template
- if ( !m_szXMLFile.IsEmpty() && m_Template.SerializeFrom(m_szXMLFile) )
- {
- // it is necessary to set WS_CHILD style bit for a Form View
- m_Template.style |= WS_CHILD;
- // if XML file is valid - create form using the read template
- CreateDlgIndirect((LPDLGTEMPLATE)m_Template,pParentWnd);
- }
- else
- {
- // otherwise switch to the template contained in the resource file
- CreateDlg(m_lpszTemplateName,pParentWnd);
- }
- m_pCreateContext = NULL;
- // we use the style from the template - but make sure that
- // the WS_BORDER bit is correct
- // the WS_BORDER bit will be whatever is in dwRequestedStyle
- ModifyStyle(WS_BORDER|WS_CAPTION, cs.style & (WS_BORDER|WS_CAPTION));
- ModifyStyleEx(WS_EX_CLIENTEDGE, cs.dwExStyle & WS_EX_CLIENTEDGE);
- // set view's child window ID
- SetDlgCtrlID(nID);
- // adjust scrolling characteristics
- CRect rectTemplate;
- GetWindowRect(rectTemplate);
- SetScrollSizes(MM_TEXT, rectTemplate.Size());
- // initialize OLE controls on the form view
- ExecuteDlgInit((LPVOID)NULL);
- // adjust window position of the form view
- SetWindowPos(NULL, rect.left, rect.top, rect.right - rect.left,
- rect.bottom - rect.top, SWP_NOZORDER|SWP_NOACTIVATE);
- // make visible if requested
- if ( dwRequestedStyle & WS_VISIBLE )
- {
- ShowWindow(SW_NORMAL);
- }
- return TRUE; // creation of the form view is done successfully
- }
- protected:
- // Windows messages handler for the form view
- virtual BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
- {
- if ( message == WM_INITDIALOG ) // OLE controls initialization
- {
- Default(); // allow default to initialize first (common dialogs/etc)
- // create OLE controls
- #ifndef _AFX_NO_OCC_SUPPORT
- CXMLCustomizable_InitializeForm(this,m_pOccDialogInfo,
- &m_Template,m_lpszTemplateName);
- #endif /* _AFX_NO_OCC_SUPPORT */
- return FALSE; // do not call parent's initialization routine
- }
- 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 window procedure
- return FormClass::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 CXMLCustomizableForm for MFC class CFormView
- typedef CXMLCustomizableForm<CFormView> CXMLGUIFormView;
- #endif // AFX_XML_CUSTOMIZABLE_FORMS_H_RKOL_8_21_2002_