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

模拟服务器

开发平台:

C/C++

  1. // -------------------------------------------------------------------------
  2. // 文件名 : UiGetString.cpp
  3. // 创建者 : Wooy(Wu yue)
  4. // 创建时间 : 2003-3-18
  5. // 功能描述 : 获得字符串界面
  6. // -------------------------------------------------------------------------
  7. #include "KWin32.h"
  8. #include "KIniFile.h"
  9. #include "../Elem/AutoLocateWnd.h"
  10. #include "../Elem/WndMessage.h"
  11. #include "../Elem/Wnds.h"
  12. #include "../UiBase.h"
  13. #include "UiTongGetString.h"
  14. #include "UiInformation.h"
  15. #include "../UiSoundSetting.h"
  16. #define SCHEME_INI  "输入字串界面2.ini"
  17. KUiTongGetString* KUiTongGetString::m_pSelf = NULL;
  18. KUiTongGetString::KUiTongGetString()
  19. {
  20. m_pRequester = NULL;
  21. }
  22. //--------------------------------------------------------------------------
  23. // 功能:打开窗口,返回唯一的一个类对象实例
  24. //--------------------------------------------------------------------------
  25. KUiTongGetString* KUiTongGetString::OpenWindow(const char* pszTitle,
  26. const char* pszInitString,
  27. KWndWindow* pRequester, unsigned int uParam,
  28.   int nMinLen, int nMaxLen)
  29. {
  30. if (m_pSelf == NULL)
  31. {
  32. m_pSelf = new KUiTongGetString;
  33. if (m_pSelf)
  34. m_pSelf->Initialize();
  35. }
  36. if (m_pSelf)
  37. {
  38. UiSoundPlay(UI_SI_WND_OPENCLOSE);
  39. m_pSelf->m_nMinLen = nMinLen;
  40. m_pSelf->m_nMaxLen = nMaxLen;
  41. m_pSelf->m_pRequester = pRequester;
  42. m_pSelf->m_uRequesterParam = uParam;
  43. if (pszTitle)
  44. m_pSelf->m_Title.SetText(pszTitle);
  45. else
  46. m_pSelf->m_Title.SetText("");
  47. if (pszInitString)
  48. m_pSelf->m_StringEdit.SetText(pszInitString);
  49. else
  50. m_pSelf->m_StringEdit.SetText("");
  51. m_pSelf->BringToTop();
  52. m_pSelf->Show();
  53. }
  54. return m_pSelf;
  55. }
  56. //--------------------------------------------------------------------------
  57. // 功能:关闭销毁窗口
  58. //--------------------------------------------------------------------------
  59. void KUiTongGetString::CloseWindow(bool bDestroy)
  60. {
  61. if (m_pSelf)
  62. {
  63. m_pSelf->m_pRequester = NULL;
  64. if (bDestroy)
  65. {
  66. m_pSelf->Destroy();
  67. m_pSelf = NULL;
  68. }
  69. else
  70. m_pSelf->Hide();
  71. }
  72. }
  73. KUiTongGetString* KUiTongGetString::GetIfVisible()
  74. {
  75. if (m_pSelf && m_pSelf->IsVisible())
  76. return m_pSelf;
  77. return NULL;
  78. }
  79. //显示窗口
  80. void KUiTongGetString::Show()
  81. {
  82. int Left, Top;
  83. ALW_GetWndPosition(Left, Top, m_Width, m_Height);
  84. SetPosition(Left, Top);
  85. KWndImage::Show();
  86. Wnd_SetFocusWnd(&m_StringEdit);
  87. Wnd_SetExclusive((KWndWindow*)this);
  88. }
  89. //隐藏窗口
  90. void KUiTongGetString::Hide()
  91. {
  92. Wnd_SetFocusWnd(NULL);
  93. Wnd_ReleaseExclusive((KWndWindow*)this);
  94. KWndImage::Hide();
  95. }
  96. //--------------------------------------------------------------------------
  97. // 功能:初始化
  98. //--------------------------------------------------------------------------
  99. void KUiTongGetString::Initialize()
  100. {
  101. AddChild(&m_Title);
  102. AddChild(&m_StringEdit);
  103. AddChild(&m_OkBtn);
  104. AddChild(&m_CancelBtn);
  105. char Scheme[256];
  106. g_UiBase.GetCurSchemePath(Scheme, 256);
  107. LoadScheme(Scheme);
  108. Wnd_AddWindow(this);
  109. }
  110. //--------------------------------------------------------------------------
  111. // 功能:载入窗口的界面方案
  112. //--------------------------------------------------------------------------
  113. void KUiTongGetString::LoadScheme(const char* pScheme)
  114. {
  115. if (m_pSelf)
  116. {
  117. char Buff[128];
  118. KIniFile Ini;
  119. sprintf(Buff, "%s\%s", pScheme, SCHEME_INI);
  120. if (Ini.Load(Buff))
  121. {
  122. m_pSelf->Init(&Ini, "Main");
  123. m_pSelf->m_Title.Init(&Ini, "Title");
  124. m_pSelf->m_StringEdit.Init(&Ini, "StringInput");
  125. m_pSelf->m_OkBtn.Init(&Ini, "OkBtn");
  126. m_pSelf->m_CancelBtn.Init(&Ini, "CancelBtn");
  127. }
  128. }
  129. }
  130. //--------------------------------------------------------------------------
  131. // 功能:窗口消息函数
  132. //--------------------------------------------------------------------------
  133. int KUiTongGetString::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  134. {
  135. int nRet = 0;
  136. switch(uMsg)
  137. {
  138. case WND_N_BUTTON_CLICK:
  139. if (uParam == (unsigned int)(KWndWindow*)&m_OkBtn)
  140. OnOk();
  141. else if (uParam == (unsigned int)(KWndWindow*)&m_CancelBtn)
  142. OnCancel();
  143. break;
  144. case WM_KEYDOWN:
  145. if (uParam == VK_RETURN)
  146. {
  147. OnOk();
  148. nRet = 1;
  149. }
  150. else if (uParam == VK_ESCAPE)
  151. {
  152. OnCancel();
  153. nRet = 1;
  154. }
  155. break;
  156. /* case WND_N_EDIT_SPECIAL_KEY_DOWN:
  157. if (nParam == VK_RETURN &&
  158. uParam == (unsigned int)(KWndWindow*)&m_StringEdit)
  159. {
  160. OnOk();
  161. return 1;
  162. }
  163. break;*/
  164. default:
  165. return KWndImage::WndProc(uMsg, uParam, nParam);
  166. }
  167. return 0;
  168. }
  169. //--------------------------------------------------------------------------
  170. // 功能:响应点击确认按钮
  171. //--------------------------------------------------------------------------
  172. void KUiTongGetString::OnOk()
  173. {
  174. char szString[32];
  175. int nLen = m_StringEdit.GetText(szString, sizeof(szString));
  176. if (nLen >= m_nMinLen && nLen <= m_nMaxLen)
  177. {
  178. if (m_pRequester)
  179. m_pRequester->WndProc(WND_M_OTHER_WORK_RESULT, m_uRequesterParam, (int)&szString);
  180. CloseWindow(true);
  181. }
  182. else
  183. {
  184. UIMessageBox(((nLen < m_nMinLen) ?
  185. "输入的字串太少!" : "输入的字数超过允许的最大长度!"));
  186. }
  187. }
  188. void KUiTongGetString::OnCancel()
  189. {
  190. if (m_pRequester)
  191. m_pRequester->WndProc(WND_M_OTHER_WORK_RESULT, m_uRequesterParam, 0);
  192. CloseWindow(true);
  193. }