ITeye博客

webservice系列教学(4)

primer_2004 · 2007-11-05 23:16 · JSP&Servlet · Markdown

  1. <MClientDlg.h>
  2. // MClientDlg.h : header file
  3. //
  4. #if !defined(AFX_MCLIENTDLG_H__C2D8DBC4_30FE_40DD_848C_78D5834CAD07__INCLUDED_)
  5. #define AFX_MCLIENTDLG_H__C2D8DBC4_30FE_40DD_848C_78D5834CAD07__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. /////////////////////////////////////////////////////////////////////////////
  10. // CMClientDlg dialog
  11. class CMClientDlg : public CDialog
  12. {
  13. // Construction
  14. public:
  15. void EnableButtons();
  16. void DisableButtons();
  17. void AssignpRef(VARIANT *var1, VARIANT *var2);
  18. void assignItem(LVITEM *item, UINT mask, int iItem, int iSubItem, LPTSTR pszText, int cchTextMax);
  19. int UpdateList();
  20. bool DestroyTree();
  21. int CheckforURL();
  22. int ModifyDialog();
  23. void Execute();
  24. int nCountParameter();
  25. HTREEITEM AddtoTree(HTREEITEM hParent, HTREEITEM hInsertAfter, LPTSTR pszData, UINT mask, IUnknown * theInterface);
  26. CMClientDlg(CWnd* pParent = NULL);    // standard constructor
  27. // Dialog Data
  28. //{{AFX_DATA(CMClientDlg)
  29. enum { IDD = IDD_MCLIENT_DIALOG };
  30. CTreeCtrl    m_TreeCtrl;
  31. CListCtrl    m_Parameters;
  32. CString    m_strParameter;
  33. CString    m_strURL;
  34. //}}AFX_DATA
  35. // ClassWizard generated virtual function overrides
  36. //{{AFX_VIRTUAL(CMClientDlg)
  37. protected:
  38. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  39. //}}AFX_VIRTUAL
  40. // Implementation
  41. protected:
  42. HICON m_hIcon;
  43. // Generated message map functions
  44. //{{AFX_MSG(CMClientDlg)
  45. virtual BOOL OnInitDialog();
  46. afx_msg void OnPaint();
  47. afx_msg HCURSOR OnQueryDragIcon();
  48. afx_msg void OnBrowse();
  49. afx_msg void OnClose();
  50. afx_msg void OnEdit();
  51. afx_msg void OnExecute();
  52. afx_msg void OnDeleteitemListparam(NMHDR* pNMHDR, LRESULT* pResult);
  53. afx_msg void OnDeleteitemTree(NMHDR* pNMHDR, LRESULT* pResult);
  54. afx_msg void OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult);
  55. afx_msg void OnLoad();
  56. //}}AFX_MSG
  57. DECLARE_MESSAGE_MAP()
  58. };
  59. //{{AFX_INSERT_LOCATION}}
  60. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  61. #endif // !defined(AFX_MCLIENTDLG_H__C2D8DBC4_30FE_40DD_848C_78D5834CAD07__INCLUDED_)
  62. < resource.h>
  63. //{{NO_DEPENDENCIES}}
  64. // Microsoft Developer Studio generated include file.
  65. // Used by MClient.rc
  66. //
  67. #define IDD_MCLIENT_DIALOG              102
  68. #define IDR_MAINFRAME                   128
  69. #define IDC_URL                         1000
  70. #define IDLOAD                          1001
  71. #define IDBROWSE                        1002
  72. #define IDC_TREE                        1003
  73. #define IDC_LISTPARAM                   1004
  74. #define IDC_PARAMETER                   1005
  75. #define IDC_EDIT                        1006
  76. #define IDC_EXECUTE                     1007
  77. #define IDC_CLOSE                       1008
  78. // Next default values for new objects
  79. //
  80. #ifdef APSTUDIO_INVOKED
  81. #ifndef APSTUDIO_READONLY_SYMBOLS
  82. #define _APS_NEXT_RESOURCE_VALUE        129
  83. #define _APS_NEXT_COMMAND_VALUE         32771
  84. #define _APS_NEXT_CONTROL_VALUE         1009
  85. #define _APS_NEXT_SYMED_VALUE           101
  86. #endif
  87. #endif
  88. <StdAfx.cpp>
  89. // stdafx.cpp : source file that includes just the standard includes
  90. //    MClient.pch will be the pre-compiled header
  91. //    stdafx.obj will contain the pre-compiled type information
  92. #include "stdafx.h"
  93. < MClient.cpp>
  94. // MClient.cpp : Defines the class behaviors for the application.
  95. //
  96. #include "stdafx.h"
  97. #include "MClient.h"
  98. #include "MClientDlg.h"
  99. #ifdef _DEBUG
  100. #define new DEBUG_NEW
  101. #undef THIS_FILE
  102. static char THIS_FILE[] = __FILE__;
  103. #endif
  104. /////////////////////////////////////////////////////////////////////////////
  105. // CMClientApp
  106. BEGIN_MESSAGE_MAP(CMClientApp, CWinApp)
  107. //{{AFX_MSG_MAP(CMClientApp)
  108. // NOTE - the ClassWizard will add and remove mapping macros here.
  109. //    DO NOT EDIT what you see in these blocks of generated code!
  110. //}}AFX_MSG
  111. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  112. END_MESSAGE_MAP()
  113. /////////////////////////////////////////////////////////////////////////////
  114. // CMClientApp construction
  115. CMClientApp::CMClientApp()
  116. {
  117. // TODO: add construction code here,
  118. // Place all significant initialization in InitInstance
  119. }
  120. /////////////////////////////////////////////////////////////////////////////
  121. // The one and only CMClientApp object
  122. CMClientApp theApp;
  123. /////////////////////////////////////////////////////////////////////////////
  124. // CMClientApp initialization
  125. BOOL CMClientApp::InitInstance()
  126. {
  127. if (FAILED(::CoInitialize(NULL)))
  128. {
  129. return FALSE;
  130. }
  131. AfxEnableControlContainer();
  132. // Standard initialization
  133. // If you are not using these features and wish to reduce the size
  134. //  of your final executable, you should remove from the following
  135. //  the specific initialization routines you do not need.
  136. #ifdef _AFXDLL
  137. Enable3dControls();            // Call this when using MFC in a shared DLL
  138. #else
  139. Enable3dControlsStatic();    // Call this when linking to MFC statically
  140. #endif
  141. CMClientDlg dlg;
  142. m_pMainWnd = &dlg;
  143. int nResponse = dlg.DoModal();
  144. if (nResponse == IDOK)
  145. {
  146. // TODO: Place code here to handle when the dialog is
  147. //  dismissed with OK
  148. }
  149. else if (nResponse == IDCANCEL)
  150. {
  151. // TODO: Place code here to handle when the dialog is
  152. //  dismissed with Cancel
  153. }
  154. ::CoUninitialize();
  155. // Since the dialog has been closed, return FALSE so that we exit the
  156. //  application, rather than start the application's message pump.
  157. return FALSE;
  158. }
  1. < MClientDlg.cpp>
  2. // MClientDlg.cpp : implementation file
  3. //
  4. #include "stdafx.h"
  5. #include "MClient.h"
  6. #include "MClientDlg.h"
  7. #include "Atlbase.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CMClientDlg dialog
  15. CMClientDlg::CMClientDlg(CWnd* pParent /*=NULL*/)
  16. : CDialog(CMClientDlg::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CMClientDlg)
  19. m_strParameter = _T("");
  20. m_strURL = _T("");
  21. //}}AFX_DATA_INIT
  22. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  23. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  24. }
  25. void CMClientDlg::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange(pDX);
  28. //{{AFX_DATA_MAP(CMClientDlg)
  29. DDX_Control(pDX, IDC_TREE, m_TreeCtrl);
  30. DDX_Control(pDX, IDC_LISTPARAM, m_Parameters);
  31. DDX_Text(pDX, IDC_PARAMETER, m_strParameter);
  32. DDX_Text(pDX, IDC_URL, m_strURL);
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(CMClientDlg, CDialog)
  36. //{{AFX_MSG_MAP(CMClientDlg)
  37. ON_WM_PAINT()
  38. ON_WM_QUERYDRAGICON()
  39. ON_BN_CLICKED(IDBROWSE, OnBrowse)
  40. ON_BN_CLICKED(IDC_CLOSE, OnClose)
  41. ON_BN_CLICKED(IDC_EDIT, OnEdit)
  42. ON_BN_CLICKED(IDC_EXECUTE, OnExecute)
  43. ON_NOTIFY(LVN_DELETEITEM, IDC_LISTPARAM, OnDeleteitemListparam)
  44. ON_NOTIFY(TVN_DELETEITEM, IDC_TREE, OnDeleteitemTree)
  45. ON_NOTIFY(TVN_SELCHANGED, IDC_TREE, OnSelchangedTree)
  46. ON_BN_CLICKED(IDLOAD, OnLoad)
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CMClientDlg message handlers
  51. BOOL CMClientDlg::OnInitDialog()
  52. {
  53. CDialog::OnInitDialog();
  54. if (ModifyDialog() == -1)
  55. return FALSE;
  56. // Set the icon for this dialog.  The framework does this automatically
  57. //  when the application's main window is not a dialog
  58. SetIcon(m_hIcon, TRUE);            // Set big icon
  59. SetIcon(m_hIcon, FALSE);        // Set small icon
  60. // TODO: Add extra initialization here
  61. return TRUE;  // return TRUE  unless you set the focus to a control
  62. }
  63. // If you add a minimize button to your dialog, you will need the code below
  64. //  to draw the icon.  For MFC applications using the document/view model,
  65. //  this is automatically done for you by the framework.
  66. void CMClientDlg::OnPaint()
  67. {
  68. if (IsIconic())
  69. {
  70. CPaintDC dc(this); // device context for painting
  71. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  72. // Center icon in client rectangle
  73. int cxIcon = GetSystemMetrics(SM_CXICON);
  74. int cyIcon = GetSystemMetrics(SM_CYICON);
  75. CRect rect;
  76. GetClientRect(&rect);
  77. int x = (rect.Width() - cxIcon + 1) / 2;
  78. int y = (rect.Height() - cyIcon + 1) / 2;
  79. // Draw the icon
  80. dc.DrawIcon(x, y, m_hIcon);
  81. }
  82. else
  83. {
  84. CDialog::OnPaint();
  85. }
  86. }
  87. // The system calls this to obtain the cursor to display while the user drags
  88. //  the minimized window.
  89. HCURSOR CMClientDlg::OnQueryDragIcon()
  90. {
  91. return (HCURSOR) m_hIcon;
  92. }
  93. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  94. //  function: CMClientDlg::OnBrowse()
  95. //
  96. //  parameters: No Parameters
  97. //
  98. //  description:  selection of wsdl file
  99. //
  100. //  returns: void
  101. //
  102. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  103. void CMClientDlg::OnBrowse()
  104. {
  105. // browse dialog will open and get the selected file
  106. CFileDialog browse(TRUE, _T("wsdl"), NULL, 0, _T("WSDL Files (*.wsdl)|*.wsdl|All files|*.*||"));
  107. if (browse.DoModal() == IDOK)
  108. {
  109. m_strURL = browse.GetPathName();
  110. if (m_strURL.IsEmpty())
  111. return;
  112. UpdateData(FALSE);
  113. OnLoad();
  114. }
  115. return;
  116. }
  117. //////////////////////////////////////////////////////////////////////////////////////////////////
  118. //  function: CMClientDlg::OnClose()
  119. //
  120. //  parameters: No Parameter
  121. //
  122. //  description: called when dialog is being closed, but before close the dialog, tree should be destroyed.
  123. //  returns: void
  124. //
  125. //////////////////////////////////////////////////////////////////////////////////////////////////
  126. void CMClientDlg::OnClose()
  127. {
  128. if (!DestroyTree())
  129. return;
  130. CMClientDlg::DestroyWindow();
  131. }
  132. //////////////////////////////////////////////////////////////////////////////////////////////////
  133. //  function: CMClientDlg::OnEdit()
  134. //
  135. //  parameters: No Parameters
  136. //
  137. //  description: Edits parameters of the operation
  138. //
  139. //  returns: void
  140. //
  141. //////////////////////////////////////////////////////////////////////////////////////////////////
  142. void CMClientDlg::OnEdit()
  143. {
  144. // get selected row, insert the user input in 3 column of that row
  145. // assign -1 to the selection mark  , so next time user has to select a row to insert data
  146. int                nSelectedRow ;
  147. LVITEM            LVitem;
  148. UpdateData();
  149. if (m_Parameters.GetItemCount() == 0)
  150. return;
  151. nSelectedRow = m_Parameters.GetSelectionMark();
  152. if (nSelectedRow == -1)
  153. return;
  154. assignItem (&LVitem, LVIF_TEXT, nSelectedRow, 2, (LPSTR)(LPCTSTR)m_strParameter, ::SysStringLen((LPWSTR)(LPCTSTR)m_strParameter));
  155. if (m_Parameters.SetItem(&LVitem) == 0)
  156. MSG("Data could not be inserted !");
  157. cleanup :
  158. m_strParameter.Empty();
  159. m_Parameters.SetSelectionMark(-1);
  160. UpdateData(false);
  161. UpdateData();
  162. return;
  163. }
  164. //////////////////////////////////////////////////////////////////////////////////////////////////
  165. //  function: CMClientDlg::OnExecute()
  166. //
  167. //  parameters: No Parameters
  168. //
  169. //  description: pressing Execute button calls this function
  170. //  returns: void
  171. //
  172. //////////////////////////////////////////////////////////////////////////////////////////////////
  173. void CMClientDlg::OnExecute()
  174. {
  175. UpdateData();
  176. UpdateData(false);
  177. if (CheckforURL() == -1)
  178. return;
  179. Execute();
  180. return;
  181. }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。