ChgPwd.cpp
上传用户:cydong117
上传日期:2009-11-10
资源大小:638k
文件大小:7k
源码类别:

模拟服务器

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #define LOGIN_BUTTON_COUNT 3
  3. #define LOGIN_INPUT_COUNT 2
  4. #define LOGIN_IMAGE_COUNT 4
  5. CLogin::CLogin()
  6. {
  7. }
  8. CLogin::~CLogin()
  9. {
  10. }
  11. VOID CLogin::Create(CWHWilImageData* pxImage)
  12. {
  13. INT nLoop;
  14. // Buttons
  15. BUTTONINFO LoginProcBtnInfo[] = {
  16. { IMG_IDX_BTN_NEW, POS_BTN_NEW_X, POS_BTN_NEW_Y, LOGBTN_WIDTH, LOGBTN_HEIGHT}, // OK Button
  17. { IMG_IDX_BTN_CHGPASS, POS_BTN_CHG_X, POS_BTN_CHG_Y, LOGBTN_WIDTH, LOGBTN_HEIGHT}, // New Account
  18. { IMG_IDX_BTN_OK, POS_BTN_OK_X, POS_BTN_OK_Y, LOGBTN_WIDTH, LOGBTN_HEIGHT} // Change Password
  19. };
  20. // EditBox State
  21. INPUTSTATE LoginInputState[] =  {
  22. { LGM_INPUT_ID, POS_ID_INS_X, POS_ID_INS_Y, 126, 15, 0, 10, ""}, // Input ID in Login
  23. { LGM_INPUT_PASSWORD, POS_PASS_INS_X, POS_PASS_INS_Y, 126, 15, 0, 10, ""} // Input Password In Login
  24. };
  25. _LOGINIMAGEINFO LoginImageInfo[] = {
  26. {IMG_IDX_ID, POS_ID_TITLE_X, POS_ID_TITLE_Y},
  27. {IMG_IDX_PASS, POS_PASS_TITLE_X, POS_PASS_TITLE_Y},
  28. {IMG_IDX_ID_INS, POS_ID_INS_X, POS_ID_INS_Y},
  29. {IMG_IDX_PASS_INS, POS_PASS_INS_X, POS_PASS_INS_Y}
  30. };
  31. m_pxImage = pxImage;
  32. for(nLoop = 0 ; nLoop < LOGIN_INPUT_COUNT ; nLoop ++)
  33. memcpy(&m_xInputState[nLoop],&LoginInputState[nLoop],sizeof(INPUTSTATE));
  34. for(nLoop = 0 ; nLoop < LOGIN_BUTTON_COUNT ; nLoop ++)
  35. m_xButtons[nLoop].SetBtn(&LoginProcBtnInfo[nLoop]);
  36. for(nLoop = 0 ; nLoop < LOGIN_IMAGE_COUNT ; nLoop ++)
  37. m_xInputImg[nLoop] = LoginImageInfo[nLoop];
  38. }
  39. HRESULT CLogin::OnKeyDown(WPARAM wParam, LPARAM lParam)
  40. {
  41. if (wParam == VK_RETURN || wParam == VK_TAB)
  42. { SetFocusBefore();
  43. switch(m_nUserState)
  44. { case  LGM_INPUT_ID:
  45. { m_nUserState = LGM_INPUT_PASSWORD;
  46. break;
  47. }
  48. case LGM_INPUT_PASSWORD:
  49. { if( ( lstrlen( m_xInputState[LGM_INPUT_ID-1].szData) >= LIMIT_USERID ) 
  50. && lstrlen( m_xInputState[LGM_INPUT_PASSWORD-1].szData ) )
  51. {
  52. g_xClientSocket.OnLogin(m_xInputState[LGM_INPUT_ID-1].szData,m_xInputState[LGM_INPUT_PASSWORD-1].szData);
  53. return 0L;
  54. }
  55. m_nUserState = LGM_INPUT_ID;
  56. break;
  57. }
  58. }
  59. SetFocusAfter();
  60. }
  61. return 0;
  62. }
  63. HRESULT CLogin::OnButtonDown(WPARAM wParam, LPARAM lParam)
  64. {
  65. INT i;
  66. RECT tRect;
  67. m_fIsButtonDown = TRUE;
  68. for( i = LGM_INPUT_ID-1 ; i < LGM_INPUT_PASSWORD; i ++)
  69. { SetRect(&tRect
  70. ,m_xInputState[i].Left,m_xInputState[i].Top
  71. ,m_xInputState[i].Left+m_xInputState[i].Width,m_xInputState[i].Top+m_xInputState[i].Height);
  72. if( IsInRect( tRect, LOWORD( lParam ), HIWORD( lParam ) ) )
  73. { SetFocusBefore();
  74. m_nUserState = i+1;
  75. SetFocusAfter();
  76. }
  77. }
  78. // Image Button Down Check
  79. for ( i = BTN_NEW_ID; i <= BTN_OK_ID ; i++)
  80. { if (m_xButtons[i].CheckMouseOn( LOWORD( lParam ), HIWORD( lParam ) ) )
  81. m_xButtons[i].m_nState = BUTTON_STATE_DOWN;
  82. else
  83. m_xButtons[i].m_nState = BUTTON_STATE_UP;
  84. }
  85. return 0;
  86. }
  87. HRESULT CLogin::OnButtonDown(POINT ptMouse)
  88. {
  89. m_fIsButtonDown = TRUE;
  90. return 0;
  91. }
  92. HRESULT CLogin::OnButtonUp(WPARAM wParam, LPARAM lParam)
  93. {
  94. INT i;
  95. m_fIsButtonDown = FALSE;
  96. for(i = BTN_NEW_ID; i <= BTN_OK_ID; i++)
  97. { m_xButtons[i].m_nState = BUTTON_STATE_UP;
  98. if( m_xButtons[i].CheckMouseOn( LOWORD( lParam ), HIWORD( lParam ) ) )
  99. { switch(m_xButtons[i].m_nButtonID)
  100. { case IMG_IDX_BTN_NEW:
  101. {
  102. //m_nProgress = PRG_NEW_ACCOUNT; - > New Account肺 逞扁绰 窃荐
  103. SetFocusBefore();
  104. SetWindowText(g_xChatEditBox.GetSafehWnd(),NULL);
  105. m_nUserState = LGM_INPUT_USER_ID;
  106. SetFocusAfter();
  107. break;
  108. }
  109. case IMG_IDX_BTN_CHGPASS:
  110. { // 烙矫肺 辆丰滚瓢栏肺 捞侩
  111. // Avi 包访 窃荐 辆丰 窍绰 内靛
  112. // break; 
  113. }
  114. // case BTN_EXIT:
  115. {
  116. SendMessage(g_xMainWnd.GetSafehWnd(), WM_DESTROY, NULL, NULL);
  117. return 0L;break;
  118. }
  119. case IMG_IDX_BTN_OK:
  120. {
  121. SendMessage(g_xChatEditBox.GetSafehWnd(),WM_CHAR,VK_RETURN,0);
  122. g_xClientSocket.OnLogin(m_xInputState[LGM_INPUT_ID-1].szData,m_xInputState[LGM_INPUT_PASSWORD-1].szData);
  123. break;
  124. }
  125. }// switch
  126. }// if
  127. }// for
  128. return 0;
  129. }
  130. HRESULT CLogin::OnButtonUp(POINT ptMouse)
  131. {
  132. return 0;
  133. }
  134. LRESULT CLogin::OnMouseMove(WPARAM wParam, LPARAM lParam)
  135. {
  136. INT i;
  137. if(!m_fIsButtonDown)
  138. {
  139. for( i = BTN_NEW_ID ; i <= BTN_OK_ID ; i ++)
  140. {
  141. if (m_xButtons[i].CheckMouseOn(LOWORD(lParam), HIWORD(lParam)))
  142. m_xButtons[i].m_nState = BUTTON_STATE_ON;
  143. else
  144. m_xButtons[i].m_nState = BUTTON_STATE_UP;
  145. }
  146. }
  147. return 0;
  148. }
  149. VOID CLogin::Render(INT nLoopTime)
  150. {
  151. if(m_fIsActive)
  152. {
  153. int i;
  154. char Pass[16]="";
  155. MoveWindow(g_xChatEditBox.GetSafehWnd(), 
  156. g_xMainWnd.m_rcWindow.left + m_xInputState[m_nUserState-1].Left +5,
  157. g_xMainWnd.m_rcWindow.top + m_xInputState[m_nUserState-1].Top + 5 , m_xInputState[m_nUserState-1].Width, m_xInputState[m_nUserState-1].Height, TRUE);
  158. // Draw ID & Pass Image
  159. for( i = IMG_IDX_ID-1 ; i < IMG_IDX_PASS_INS ; i ++)
  160. {
  161. m_pxImage->NewSetIndex(m_xInputImg[i].nImgIdx);
  162. g_xMainWnd.DrawWithImageForComp(m_xInputImg[i].Left , m_xInputImg[i].Top,
  163. m_pxImage->m_lpstNewCurrWilImageInfo->shWidth,
  164. m_pxImage->m_lpstNewCurrWilImageInfo->shHeight,
  165. (WORD*)(m_pxImage->m_pbCurrImage));
  166. }
  167. // Draw Button Image
  168. for ( i = BTN_NEW_ID ; i <=  BTN_OK_ID ; i++)
  169. {
  170. m_pxImage->NewSetIndex(m_xButtons[i].m_nButtonID + m_xButtons[i].m_nState - 1 );
  171. g_xMainWnd.DrawWithImageForComp(m_xButtons[i].m_Rect.left, m_xButtons[i].m_Rect.top, 
  172. m_xButtons[i].m_Rect.right - m_xButtons[i].m_Rect.left, 
  173. m_xButtons[i].m_Rect.bottom - m_xButtons[i].m_Rect.top, (WORD*)(m_pxImage->m_pbCurrImage));
  174. }
  175. // Write ID & Password
  176. memset(Pass,'*',strlen(m_xInputState[1].szData));
  177. g_xMainWnd.PutsHan(NULL, m_xInputState[0].Left+7, m_xInputState[0].Top+6, RGB(5,5,5), RGB(0,0,0), m_xInputState[0].szData);
  178. g_xMainWnd.PutsHan(NULL, m_xInputState[1].Left+7, m_xInputState[1].Top+6, RGB(5,5,5), RGB(0,0,0), Pass);
  179. }
  180. }
  181. VOID CLogin::SetFocusBefore(VOID)
  182. {
  183. INT nTemp;
  184. nTemp =  m_nUserState - 1;
  185. if(g_xChatEditBox.m_szInputMsg[0]!=NULL)
  186. lstrcpy(m_xInputState[nTemp].szData , g_xChatEditBox.m_szInputMsg);
  187. else
  188. GetWindowText(g_xChatEditBox.GetSafehWnd(),m_xInputState[nTemp].szData ,m_xInputState[nTemp].nSize);
  189. ZeroMemory(g_xChatEditBox.m_szInputMsg,sizeof(g_xChatEditBox.m_szInputMsg));
  190. ShowWindow(g_xChatEditBox.GetSafehWnd(), SW_HIDE);
  191. g_xChatEditBox.SetSelectAll();
  192. }
  193. VOID CLogin::SetFocusAfter(VOID)
  194. {
  195. CHAR cChr;
  196. INT nTemp;
  197. ShowWindow(g_xChatEditBox.GetSafehWnd(), SW_SHOW);
  198. nTemp = m_nUserState - 1;
  199. g_xChatEditBox.SetLimitText(m_xInputState[nTemp].nSize);
  200. if( m_nUserState != LGM_INPUT_PASSWORD )
  201. cChr = NULL;
  202. else
  203. cChr = '*';
  204. SendMessage(g_xChatEditBox.GetSafehWnd(),EM_SETPASSWORDCHAR,(WPARAM)cChr,0);
  205. SetWindowText(g_xChatEditBox.GetSafehWnd(), m_xInputState[nTemp].szData);
  206. SetFocus(g_xChatEditBox.GetSafehWnd());
  207. g_xChatEditBox.SetSelectAll();
  208. }