Advertisement
Guest User

gui.cpp

a guest
Jun 11th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.65 KB | None | 0 0
  1. #ifdef GUI
  2.  
  3. #include <windows.h>
  4. #include "gui.hpp"
  5. #include "eoserver.hpp"
  6. #include "world.hpp"
  7. #include "character.hpp"
  8. #include "util.hpp"
  9.  
  10. extern EOServer *server_source;
  11.  
  12. /** Windows */
  13. HWND gui_main_window;
  14. HWND gui_console_window;
  15. /** Dialog */
  16. HWND gui_about_dialog;
  17. HWND gui_plist_dialog;
  18. /** MSG */
  19. MSG Msg;
  20.  
  21. namespace Gui
  22. {
  23.  
  24. MSG GetMsg()
  25. {
  26. return Msg;
  27. }
  28.  
  29. bool GuiStartup(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  30. {
  31. WNDCLASSEX wc;
  32.  
  33. //Step 1: Registering the Window Class
  34. wc.cbSize = sizeof(WNDCLASSEX);
  35. wc.style = 0;
  36. wc.lpfnWndProc = WndProc;
  37. wc.cbClsExtra = 0;
  38. wc.cbWndExtra = 0;
  39. wc.hInstance = hInstance;
  40. wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
  41. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  42. wc.hbrBackground = (HBRUSH)(2);
  43. wc.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU); // resource
  44. wc.lpszClassName = g_szClassName;
  45. wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
  46.  
  47. if(!RegisterClassEx(&wc))
  48. {
  49. MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
  50. return 0;
  51. }
  52.  
  53. // Step 2: Creating the Window
  54. gui_main_window = CreateWindowEx(
  55. WS_EX_CLIENTEDGE,
  56. g_szClassName,
  57. "EODelta",
  58. WS_OVERLAPPEDWINDOW, // WS Stuff
  59. CW_USEDEFAULT, CW_USEDEFAULT, 677, 343,
  60. NULL, NULL, hInstance, NULL);
  61.  
  62. if(gui_main_window == NULL)
  63. {
  64. MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
  65. return 0;
  66. }
  67.  
  68. ShowWindow(gui_main_window, nCmdShow);
  69. UpdateWindow(gui_main_window);
  70. }
  71.  
  72. void CheckQueue()
  73. {
  74. while(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE) > 0)
  75. {
  76. TranslateMessage(&Msg);
  77. DispatchMessage(&Msg);
  78. }
  79. }
  80.  
  81. // Step 4: the Window Procedure
  82. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  83. {
  84. switch(msg)
  85. {
  86. case WM_CREATE:
  87. {
  88. //HFONT hfDefault;
  89. HGDIOBJ hfDefault;
  90.  
  91. gui_console_window = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
  92. WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_AUTOHSCROLL | WS_TABSTOP,
  93. 0, 0, 100, 100, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
  94. if(gui_console_window == NULL)
  95. MessageBox(hwnd, "Could not create console box.", "Error", MB_OK | MB_ICONERROR);
  96.  
  97. hfDefault = GetStockObject(DEFAULT_GUI_FONT);
  98. SendMessage(gui_console_window, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
  99. }
  100. break;
  101. case WM_SIZE:
  102. {
  103. HWND hEdit;
  104. RECT rcClient;
  105.  
  106. GetClientRect(hwnd, &rcClient);
  107.  
  108. hEdit = GetDlgItem(hwnd, IDC_MAIN_EDIT);
  109. SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
  110. }
  111. break;
  112. case WM_COMMAND:
  113. switch(LOWORD(wParam))
  114. {
  115. case ID_HELP_ABOUT:
  116. {
  117. gui_about_dialog = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
  118. if(gui_about_dialog != NULL) ShowWindow(gui_about_dialog, SW_SHOW);
  119. else MessageBox(hwnd, "CreateDialog returned NULL", "Warning!", MB_OK | MB_ICONINFORMATION);
  120. }
  121. break;
  122. case ID_SERVER_EXIT:
  123. server_source->world->ShutdownSequence(5);
  124. break;
  125. case ID_SERVER_PLIST:
  126. {
  127. gui_plist_dialog = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_PLIST), hwnd, PlayerListDlgProc);
  128. if(gui_plist_dialog != NULL) ShowWindow(gui_plist_dialog, SW_SHOW);
  129. else MessageBox(hwnd, "CreateDialog returned NULL", "Warning!", MB_OK | MB_ICONINFORMATION);
  130. }
  131. }
  132. break;
  133. case WM_CLOSE: // Shutting down the server by clicking x.
  134. DestroyWindow(hwnd);
  135. server_source->world->ShutdownSequence(0);
  136. break;
  137. case WM_DESTROY:
  138. PostQuitMessage(0);
  139. break;
  140. default:
  141. return DefWindowProc(hwnd, msg, wParam, lParam);
  142. }
  143. return 0;
  144. }
  145.  
  146. BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
  147. {
  148. switch(Message)
  149. {
  150. case WM_COMMAND:
  151. switch(LOWORD(wParam))
  152. {
  153. case IDOK:
  154. DestroyWindow(hwnd);
  155. PostQuitMessage(0);
  156. break;
  157. }
  158. break;
  159. case WM_CLOSE:
  160. DestroyWindow(hwnd);
  161. break;
  162. case WM_DESTROY:
  163. DestroyWindow(hwnd);
  164. PostQuitMessage(0);
  165. break;
  166. default:
  167. return FALSE;
  168. }
  169. return TRUE;
  170. }
  171.  
  172. BOOL CALLBACK PlayerListDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
  173. {
  174. switch(Message)
  175. {
  176. case WM_INITDIALOG:
  177. case WM_CREATE:
  178. UpdatePlayerList();
  179. break;
  180. case WM_COMMAND:
  181. switch(LOWORD(wParam))
  182. {
  183. case IDC_BUTTON1:
  184. gui_plist_dialog = hwnd;
  185. UpdatePlayerList();
  186. break;
  187. }
  188. break;
  189. case WM_CLOSE:
  190. DestroyWindow(hwnd);
  191. break;
  192. case WM_DESTROY:
  193. DestroyWindow(hwnd);
  194. PostQuitMessage(0);
  195. break;
  196. default:
  197. return FALSE;
  198. }
  199. return TRUE;
  200. }
  201.  
  202. bool List_AddStr(std::string str, HWND pwindow, int ccontrol)
  203. {
  204. HWND hEdit = GetDlgItem(pwindow, ccontrol);
  205.  
  206. if(pwindow == NULL)
  207. MessageBox(pwindow, "pwindow returned NULL", "Warning!", MB_OK | MB_ICONINFORMATION);
  208. if(hEdit == NULL)
  209. MessageBox(pwindow, "GetDlgItem returned NULL", "Warning!", MB_OK | MB_ICONINFORMATION);
  210.  
  211. SendMessage(hEdit, LB_ADDSTRING, 0, (LPARAM)str.c_str());
  212. return true;
  213. }
  214.  
  215. void UpdatePlayerList()
  216. {
  217. //UTIL_FOREACH(server_source->world->characters, character)
  218. //{
  219.  
  220. //}
  221.  
  222. List_AddStr("TEST", gui_plist_dialog, IDC_LIST1);
  223.  
  224. //ShowWindow(gui_plist_dialog, SW_SHOW);
  225. //UpdateWindow(gui_plist_dialog);
  226. }
  227.  
  228. }
  229.  
  230. #endif // GUI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement