S3AccClientSampleDlg.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:6k
源码类别:

模拟服务器

开发平台:

C/C++

  1. // S3AccClientSampleDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "S3AccClientSample.h"
  5. #include "S3AccClientSampleDlg.h"
  6. #include "Sample.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  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. // CS3AccClientSampleDlg dialog
  51. CS3AccClientSampleDlg::CS3AccClientSampleDlg(CWnd* pParent /*=NULL*/)
  52. : CDialog(CS3AccClientSampleDlg::IDD, pParent),
  53. m_pSample( NULL )
  54. {
  55. //{{AFX_DATA_INIT(CS3AccClientSampleDlg)
  56. // NOTE: the ClassWizard will add member initialization here
  57. //}}AFX_DATA_INIT
  58. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  59. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  60. }
  61. void CS3AccClientSampleDlg::DoDataExchange(CDataExchange* pDX)
  62. {
  63. CDialog::DoDataExchange(pDX);
  64. //{{AFX_DATA_MAP(CS3AccClientSampleDlg)
  65. DDX_Control(pDX, IDC_PARAM, m_paramCtrl);
  66. //}}AFX_DATA_MAP
  67. }
  68. BEGIN_MESSAGE_MAP(CS3AccClientSampleDlg, CDialog)
  69. //{{AFX_MSG_MAP(CS3AccClientSampleDlg)
  70. ON_WM_SYSCOMMAND()
  71. ON_WM_PAINT()
  72. ON_WM_QUERYDRAGICON()
  73. ON_CBN_EDITCHANGE(IDC_PARAM, OnEditchangeParam)
  74. ON_BN_CLICKED(IDC_SEND, OnSend)
  75. //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CS3AccClientSampleDlg message handlers
  79. BOOL CS3AccClientSampleDlg::OnInitDialog()
  80. {
  81. CDialog::OnInitDialog();
  82. // Add "About..." menu item to system menu.
  83. // IDM_ABOUTBOX must be in the system command range.
  84. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  85. ASSERT(IDM_ABOUTBOX < 0xF000);
  86. CMenu* pSysMenu = GetSystemMenu(FALSE);
  87. if (pSysMenu != NULL)
  88. {
  89. CString strAboutMenu;
  90. strAboutMenu.LoadString(IDS_ABOUTBOX);
  91. if (!strAboutMenu.IsEmpty())
  92. {
  93. pSysMenu->AppendMenu(MF_SEPARATOR);
  94. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  95. }
  96. }
  97. // Set the icon for this dialog.  The framework does this automatically
  98. //  when the application's main window is not a dialog
  99. SetIcon(m_hIcon, TRUE); // Set big icon
  100. SetIcon(m_hIcon, FALSE); // Set small icon
  101. // TODO: Add extra initialization here
  102. m_paramCtrl.SetCurSel( 0 );
  103. // 初始化客户端套接字
  104. //------>BEGIN
  105. m_pSample = CSample::Instance();
  106. ASSERT(NULL!=m_pSample);
  107. ASSERT(m_pSample->Connect( "192.168.26.211", 8200 ));
  108. ASSERT(m_pSample->Start());
  109. //<------END
  110. return TRUE;  // return TRUE  unless you set the focus to a control
  111. }
  112. void CS3AccClientSampleDlg::OnSysCommand(UINT nID, LPARAM lParam)
  113. {
  114. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  115. {
  116. CAboutDlg dlgAbout;
  117. dlgAbout.DoModal();
  118. }
  119. else
  120. {
  121. CDialog::OnSysCommand(nID, lParam);
  122. }
  123. }
  124. // If you add a minimize button to your dialog, you will need the code below
  125. //  to draw the icon.  For MFC applications using the document/view model,
  126. //  this is automatically done for you by the framework.
  127. void CS3AccClientSampleDlg::OnPaint() 
  128. {
  129. if (IsIconic())
  130. {
  131. CPaintDC dc(this); // device context for painting
  132. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  133. // Center icon in client rectangle
  134. int cxIcon = GetSystemMetrics(SM_CXICON);
  135. int cyIcon = GetSystemMetrics(SM_CYICON);
  136. CRect rect;
  137. GetClientRect(&rect);
  138. int x = (rect.Width() - cxIcon + 1) / 2;
  139. int y = (rect.Height() - cyIcon + 1) / 2;
  140. // Draw the icon
  141. dc.DrawIcon(x, y, m_hIcon);
  142. }
  143. else
  144. {
  145. CDialog::OnPaint();
  146. }
  147. }
  148. // The system calls this to obtain the cursor to display while the user drags
  149. //  the minimized window.
  150. HCURSOR CS3AccClientSampleDlg::OnQueryDragIcon()
  151. {
  152. return (HCURSOR) m_hIcon;
  153. }
  154. void CS3AccClientSampleDlg::OnOK() 
  155. {
  156. // TODO: Add extra validation here
  157. CDialog::OnOK();
  158. }
  159. void CS3AccClientSampleDlg::OnCancel() 
  160. {
  161. // TODO: Add extra cleanup here
  162. CDialog::OnCancel();
  163. }
  164. void CS3AccClientSampleDlg::OnEditchangeParam() 
  165. {
  166. // TODO: Add your control notification handler code here
  167. UpdateData( TRUE );
  168. }
  169. void CS3AccClientSampleDlg::OnSend() 
  170. {
  171. // TODO: Add your control notification handler code here
  172. int iSel = m_paramCtrl.GetCurSel();
  173. if ( ( iSel < 0 ) || ( iSel > 3 ) )
  174. {
  175. return;
  176. }
  177. const DWORD params[] =
  178. {
  179. LOGIN_A_SERVERLIST,
  180. LOGIN_A_LOGIN,
  181. LOGIN_A_DECACCOUNTDEPOSIT,
  182. LOGIN_A_LOGOUT
  183. };
  184. ASSERT(NULL!=m_pSample);
  185. switch( params[iSel] )
  186. {
  187. case LOGIN_A_SERVERLIST:
  188. m_pSample->QueryGSList();
  189. break;
  190. case LOGIN_A_LOGIN:
  191. m_pSample->Login( "test0", "888888", 78221 );
  192. break;
  193. case LOGIN_A_DECACCOUNTDEPOSIT:
  194. m_pSample->DecAccountDeposit( 78221, 78221, 60 );
  195. break;
  196. case LOGIN_A_LOGOUT:
  197. m_pSample->Logout( 78221, 78221 );
  198. break;
  199. default:
  200. break;
  201. }
  202. }