Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef GUI
- #include <windows.h>
- #include "gui.hpp"
- #include "eoserver.hpp"
- #include "world.hpp"
- #include "character.hpp"
- #include "util.hpp"
- extern EOServer *server_source;
- /** Windows */
- HWND gui_main_window;
- HWND gui_console_window;
- /** Dialog */
- HWND gui_about_dialog;
- HWND gui_plist_dialog;
- /** MSG */
- MSG Msg;
- namespace Gui
- {
- MSG GetMsg()
- {
- return Msg;
- }
- bool GuiStartup(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- WNDCLASSEX wc;
- //Step 1: Registering the Window Class
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = 0;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)(2);
- wc.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU); // resource
- wc.lpszClassName = g_szClassName;
- wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
- if(!RegisterClassEx(&wc))
- {
- MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- // Step 2: Creating the Window
- gui_main_window = CreateWindowEx(
- WS_EX_CLIENTEDGE,
- g_szClassName,
- "EODelta",
- WS_OVERLAPPEDWINDOW, // WS Stuff
- CW_USEDEFAULT, CW_USEDEFAULT, 677, 343,
- NULL, NULL, hInstance, NULL);
- if(gui_main_window == NULL)
- {
- MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- ShowWindow(gui_main_window, nCmdShow);
- UpdateWindow(gui_main_window);
- }
- void CheckQueue()
- {
- while(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE) > 0)
- {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- }
- // Step 4: the Window Procedure
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch(msg)
- {
- case WM_CREATE:
- {
- //HFONT hfDefault;
- HGDIOBJ hfDefault;
- gui_console_window = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
- WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_AUTOHSCROLL | WS_TABSTOP,
- 0, 0, 100, 100, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
- if(gui_console_window == NULL)
- MessageBox(hwnd, "Could not create console box.", "Error", MB_OK | MB_ICONERROR);
- hfDefault = GetStockObject(DEFAULT_GUI_FONT);
- SendMessage(gui_console_window, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
- }
- break;
- case WM_SIZE:
- {
- HWND hEdit;
- RECT rcClient;
- GetClientRect(hwnd, &rcClient);
- hEdit = GetDlgItem(hwnd, IDC_MAIN_EDIT);
- SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
- }
- break;
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case ID_HELP_ABOUT:
- {
- gui_about_dialog = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
- if(gui_about_dialog != NULL) ShowWindow(gui_about_dialog, SW_SHOW);
- else MessageBox(hwnd, "CreateDialog returned NULL", "Warning!", MB_OK | MB_ICONINFORMATION);
- }
- break;
- case ID_SERVER_EXIT:
- server_source->world->ShutdownSequence(5);
- break;
- case ID_SERVER_PLIST:
- {
- gui_plist_dialog = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_PLIST), hwnd, PlayerListDlgProc);
- if(gui_plist_dialog != NULL) ShowWindow(gui_plist_dialog, SW_SHOW);
- else MessageBox(hwnd, "CreateDialog returned NULL", "Warning!", MB_OK | MB_ICONINFORMATION);
- }
- }
- break;
- case WM_CLOSE: // Shutting down the server by clicking x.
- DestroyWindow(hwnd);
- server_source->world->ShutdownSequence(0);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
- {
- switch(Message)
- {
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDOK:
- DestroyWindow(hwnd);
- PostQuitMessage(0);
- break;
- }
- break;
- case WM_CLOSE:
- DestroyWindow(hwnd);
- break;
- case WM_DESTROY:
- DestroyWindow(hwnd);
- PostQuitMessage(0);
- break;
- default:
- return FALSE;
- }
- return TRUE;
- }
- BOOL CALLBACK PlayerListDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
- {
- switch(Message)
- {
- case WM_INITDIALOG:
- case WM_CREATE:
- UpdatePlayerList();
- break;
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDC_BUTTON1:
- gui_plist_dialog = hwnd;
- UpdatePlayerList();
- break;
- }
- break;
- case WM_CLOSE:
- DestroyWindow(hwnd);
- break;
- case WM_DESTROY:
- DestroyWindow(hwnd);
- PostQuitMessage(0);
- break;
- default:
- return FALSE;
- }
- return TRUE;
- }
- bool List_AddStr(std::string str, HWND pwindow, int ccontrol)
- {
- HWND hEdit = GetDlgItem(pwindow, ccontrol);
- if(pwindow == NULL)
- MessageBox(pwindow, "pwindow returned NULL", "Warning!", MB_OK | MB_ICONINFORMATION);
- if(hEdit == NULL)
- MessageBox(pwindow, "GetDlgItem returned NULL", "Warning!", MB_OK | MB_ICONINFORMATION);
- SendMessage(hEdit, LB_ADDSTRING, 0, (LPARAM)str.c_str());
- return true;
- }
- void UpdatePlayerList()
- {
- //UTIL_FOREACH(server_source->world->characters, character)
- //{
- //}
- List_AddStr("TEST", gui_plist_dialog, IDC_LIST1);
- //ShowWindow(gui_plist_dialog, SW_SHOW);
- //UpdateWindow(gui_plist_dialog);
- }
- }
- #endif // GUI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement