estdlg.cpp
上传用户:hy11688
上传日期:2007-01-08
资源大小:81k
文件大小:3k
源码类别:

棋牌游戏

开发平台:

Visual C++

  1. // estdlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "resource.h"
  5. #include "winsock.h"
  6. #include "ts.h"
  7. #include "estdlg.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char BASED_CODE THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CEstDlg dialog
  14. CEstDlg::CEstDlg(CTCPSocket *ptsEst,LPCSTR pszON,CWnd* pParent /*=NULL*/,SOCKET sockEst)
  15. : CDialog(IDD_ESTDLG, pParent)
  16. {
  17. m_ptsEst=ptsEst;
  18. m_szON=pszON;
  19. ASSERT(m_ptsEst);
  20. m_sockEst=sockEst;
  21. m_iTimer=0;
  22. }
  23. void CEstDlg::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialog::DoDataExchange(pDX);
  26. //{{AFX_DATA_MAP(CEstDlg)
  27. DDX_Control(pDX, IDC_ONE, m_staOne);
  28. DDX_Control(pDX, IDC_CONNECT, m_raConnect);
  29. DDX_Control(pDX, IDC_OTHERNAME, m_edOtherName);
  30. //}}AFX_DATA_MAP
  31. }
  32. BEGIN_MESSAGE_MAP(CEstDlg, CDialog)
  33. ON_MESSAGE(WSA_ACCEPT, OnWSAAccept)
  34. //{{AFX_MSG_MAP(CEstDlg)
  35. ON_BN_CLICKED(IDC_EFFECT, OnEffect)
  36. ON_WM_TIMER()
  37. ON_BN_CLICKED(IDC_CONNECT, OnConnect)
  38. ON_BN_CLICKED(IDC_LISTEN, OnListen)
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CEstDlg message handlers
  43. void CEstDlg::OnEffect() 
  44. {
  45. BOOL fConnect=(1==m_raConnect.GetCheck());
  46. CString szOtherName;
  47. m_edOtherName.GetWindowText(szOtherName);
  48. HWND hwndParent=GetSafeHwnd();
  49. if(fConnect&&(0==szOtherName.GetLength()))
  50.     {
  51.    AfxMessageBox("You need input the other PC's name!",MB_OK);
  52.    return;
  53. }
  54. GetDlgItem(IDC_EFFECT)->EnableWindow(FALSE);
  55. m_ptsEst->InitData(hwndParent,ESTSOCKET,
  56.                          !fConnect,WSA_NOTIFY);
  57. if(m_ptsEst->Establish(szOtherName))
  58. {
  59. if(fConnect)
  60. CDialog::OnOK();
  61. else
  62. {
  63. SetTimer(1,500,NULL);
  64. m_iTimer=1;
  65. }
  66.     }
  67. else
  68. AfxMessageBox("Connect Fail",MB_OK);
  69. if(fConnect)
  70. GetDlgItem(IDC_EFFECT)->EnableWindow(TRUE);
  71. }
  72. LONG CEstDlg::OnWSAAccept(UINT uP,LONG lP)
  73. {
  74. if(m_iTimer)
  75.    KillTimer(1);
  76. GetDlgItem(IDC_EFFECT)->EnableWindow(TRUE);
  77. if(WSAGETSELECTERROR(lP)==0)
  78. {
  79.        m_ptsEst->WSAAccept();
  80.        CDialog::OnOK();
  81. }
  82. else
  83. {
  84. m_ptsEst->CancelListen();
  85.     AfxMessageBox("Connect Failed !",MB_OK);
  86. }
  87. return 0L;
  88. }
  89. void CEstDlg::OnCancel()
  90. {
  91. if(m_iTimer)
  92. {
  93.    KillTimer(1);
  94.    m_iTimer=0;
  95.    m_ptsEst->CancelListen();
  96.    GetDlgItem(IDC_EFFECT)->EnableWindow(TRUE);
  97. }
  98. else
  99. CDialog::OnCancel();
  100. }
  101. BOOL CEstDlg::OnInitDialog() 
  102. {
  103. CDialog::OnInitDialog();
  104. m_edOtherName.SetWindowText(m_szON);
  105. if(m_fInitListen)
  106. {
  107. ((CButton*)GetDlgItem(IDC_LISTEN))->SetCheck(1);
  108. m_raConnect.SetCheck(0);
  109. }
  110. else
  111. {
  112. ((CButton*)GetDlgItem(IDC_LISTEN))->SetCheck(0);
  113. m_raConnect.SetCheck(1);
  114. }
  115. m_edOtherName.EnableWindow(m_raConnect.GetCheck());
  116. HICON hIcon=AfxGetApp()->LoadIcon(IDI_ONE);
  117. m_staOne.SetIcon(hIcon);
  118. return TRUE;  // return TRUE unless you set the focus to a control
  119.               // EXCEPTION: OCX Property Pages should return FALSE
  120. }
  121. void CEstDlg::OnTimer(UINT nIDEvent) 
  122. {
  123.     static BOOL bOne=TRUE;
  124. bOne=!bOne;
  125. //m_staOne.ShowWindow((bOne)?SW_SHOW:SW_HIDE);
  126. //m_staTwo.ShowWindow((bOne)?SW_HIDE:SW_SHOW);
  127. HICON hIcon=AfxGetApp()->LoadIcon((bOne)?
  128.   IDI_ONE:IDI_TWO);
  129. m_staOne.SetIcon(hIcon);
  130. UpdateWindow();
  131. CDialog::OnTimer(nIDEvent);
  132. }
  133. void CEstDlg::OnConnect() 
  134. {
  135. m_edOtherName.EnableWindow(m_raConnect.GetCheck());
  136. }
  137. void CEstDlg::OnListen() 
  138. {
  139. m_edOtherName.EnableWindow(m_raConnect.GetCheck());
  140. }