`
primer_2004
  • 浏览: 124206 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

webservice系列教学(4)

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

相关推荐

Global site tag (gtag.js) - Google Analytics