Test_SaxDlg.cpp
上传用户:quanyou
上传日期:2022-06-07
资源大小:39k
文件大小:4k
源码类别:

xml/soap/webservice

开发平台:

Visual C++

  1. // Test_SaxDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Test_Sax.h"
  5. #include "Test_SaxDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. #define CHR(err) { hr = (err) ; if (hr != S_OK && hr != S_ABORT_WANTED){ AtlTrace("nError %08lxnn", err); return hr;} }
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CAboutDlg dialog used for App About
  14. class CAboutDlg : public CDialog
  15. {
  16. public:
  17. CAboutDlg();
  18. // Dialog Data
  19. //{{AFX_DATA(CAboutDlg)
  20. enum { IDD = IDD_ABOUTBOX };
  21. //}}AFX_DATA
  22. // ClassWizard generated virtual function overrides
  23. //{{AFX_VIRTUAL(CAboutDlg)
  24. protected:
  25. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  26. //}}AFX_VIRTUAL
  27. // Implementation
  28. protected:
  29. //{{AFX_MSG(CAboutDlg)
  30. //}}AFX_MSG
  31. DECLARE_MESSAGE_MAP()
  32. };
  33. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  34. {
  35. //{{AFX_DATA_INIT(CAboutDlg)
  36. //}}AFX_DATA_INIT
  37. }
  38. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CAboutDlg)
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  45. //{{AFX_MSG_MAP(CAboutDlg)
  46. // No message handlers
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CTest_SaxDlg dialog
  51. CTest_SaxDlg::CTest_SaxDlg(CWnd* pParent /*=NULL*/)
  52. : CDialog(CTest_SaxDlg::IDD, pParent)
  53. {
  54. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  55. }
  56. void CTest_SaxDlg::DoDataExchange(CDataExchange* pDX)
  57. {
  58. CDialog::DoDataExchange(pDX);
  59. //{{AFX_DATA_MAP(CTest_SaxDlg)
  60. //}}AFX_DATA_MAP
  61. }
  62. BEGIN_MESSAGE_MAP(CTest_SaxDlg, CDialog)
  63. //{{AFX_MSG_MAP(CTest_SaxDlg)
  64. ON_WM_SYSCOMMAND()
  65. ON_WM_PAINT()
  66. ON_WM_QUERYDRAGICON()
  67. //}}AFX_MSG_MAP
  68. END_MESSAGE_MAP()
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CTest_SaxDlg message handlers
  71. BOOL CTest_SaxDlg::OnInitDialog()
  72. {
  73. CDialog::OnInitDialog();
  74. // Add "About..." menu item to system menu.
  75. // IDM_ABOUTBOX must be in the system command range.
  76. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  77. ASSERT(IDM_ABOUTBOX < 0xF000);
  78. CMenu* pSysMenu = GetSystemMenu(FALSE);
  79. if (pSysMenu != NULL)
  80. {
  81. CString strAboutMenu;
  82. strAboutMenu.LoadString(IDS_ABOUTBOX);
  83. if (!strAboutMenu.IsEmpty())
  84. {
  85. pSysMenu->AppendMenu(MF_SEPARATOR);
  86. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  87. }
  88. }
  89. // Set the icon for this dialog.  The framework does this automatically
  90. //  when the application's main window is not a dialog
  91. SetIcon(m_hIcon, TRUE); // Set big icon
  92. SetIcon(m_hIcon, FALSE);
  93. CString str;
  94. // Set small icon
  95. CoInitialize(NULL); 
  96. HERO_XMLContentHandler* pHero_XML;
  97. ISAXXMLReaderPtr pReader = NULL;
  98. HRESULT hr;
  99. CHR(pReader.CreateInstance(__uuidof(SAXXMLReader)));
  100. //Only one content handler can be registered at a time.
  101. pHero_XML=HERO_XMLContentHandler::CreateInstance();
  102. CHR(pReader->putContentHandler(pHero_XML));
  103. CHR(pReader->parseURL(L"hero.xml"));
  104. CHR(pReader->putContentHandler(NULL));
  105. return TRUE;  // return TRUE  unless you set the focus to a control
  106. }
  107. void CTest_SaxDlg::OnSysCommand(UINT nID, LPARAM lParam)
  108. {
  109. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  110. {
  111. CAboutDlg dlgAbout;
  112. dlgAbout.DoModal();
  113. }
  114. else
  115. {
  116. CDialog::OnSysCommand(nID, lParam);
  117. }
  118. }
  119. // If you add a minimize button to your dialog, you will need the code below
  120. //  to draw the icon.  For MFC applications using the document/view model,
  121. //  this is automatically done for you by the framework.
  122. void CTest_SaxDlg::OnPaint() 
  123. {
  124. if (IsIconic())
  125. {
  126. CPaintDC dc(this); // device context for painting
  127. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  128. // Center icon in client rectangle
  129. int cxIcon = GetSystemMetrics(SM_CXICON);
  130. int cyIcon = GetSystemMetrics(SM_CYICON);
  131. CRect rect;
  132. GetClientRect(&rect);
  133. int x = (rect.Width() - cxIcon + 1) / 2;
  134. int y = (rect.Height() - cyIcon + 1) / 2;
  135. // Draw the icon
  136. dc.DrawIcon(x, y, m_hIcon);
  137. }
  138. else
  139. {
  140. CDialog::OnPaint();
  141. }
  142. }
  143. // The system calls this to obtain the cursor to display while the user drags
  144. //  the minimized window.
  145. HCURSOR CTest_SaxDlg::OnQueryDragIcon()
  146. {
  147. return (HCURSOR) m_hIcon;
  148. }