Changeset 255 in Main for trunk/Server/gui.c
- Timestamp:
- Oct 4, 2024, 1:08:58 PM (6 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Server/gui.c
r253 r255 19 19 HWND button_stop; 20 20 HWND button_about; 21 HWND button_reset; 22 HWND button_exit; 21 23 HWND status; 22 24 HFONT monospace; … … 33 35 int startup(int argc, char** argv); 34 36 35 void ShowBitmapSize(HWND hWnd, HDC hdc, const char* name, int x, int y, int w, int h) {37 void ShowBitmapSize(HWND hWnd, HDC hdc, const char* name, int x, int y, int w, int h) { 36 38 HBITMAP hBitmap = LoadBitmap(hInst, name); 37 39 BITMAP bmp; … … 40 42 hmdc = CreateCompatibleDC(hdc); 41 43 SelectObject(hmdc, hBitmap); 42 if(w == 0 && h == 0) {44 if(w == 0 && h == 0) { 43 45 StretchBlt(hdc, x, y, bmp.bmWidth, bmp.bmHeight, hmdc, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY); 44 } else{46 } else { 45 47 StretchBlt(hdc, x, y, w, h, hmdc, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY); 46 48 } … … 49 51 } 50 52 51 void ShowBitmap(HWND hWnd, HDC hdc, const char* name, int x, int y){ 52 ShowBitmapSize(hWnd, hdc, name, x, y, 0, 0); 53 } 53 void ShowBitmap(HWND hWnd, HDC hdc, const char* name, int x, int y) { ShowBitmapSize(hWnd, hdc, name, x, y, 0, 0); } 54 54 55 55 int max = 0; 56 void AddLog(const char* str) {56 void AddLog(const char* str) { 57 57 HDC hdc; 58 58 PAINTSTRUCT ps; … … 65 65 GetTextExtentPoint32(hdc, str, strlen(str), &sz); 66 66 DeleteDC(hdc); 67 68 if(max < sz.cx) {67 68 if(max < sz.cx) { 69 69 max = sz.cx; 70 70 SendMessage(logarea, LB_SETHORIZONTALEXTENT, max, 0); … … 72 72 } 73 73 74 LRESULT CALLBACK VersionDialog(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {75 if(msg == WM_COMMAND) {74 LRESULT CALLBACK VersionDialog(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { 75 if(msg == WM_COMMAND) { 76 76 if(LOWORD(wp) == IDOK) EndDialog(hWnd, IDOK); 77 } else if(msg == WM_PAINT){77 } else if(msg == WM_PAINT) { 78 78 HDC hdc; 79 79 PAINTSTRUCT ps; … … 87 87 ShowBitmapSize(hWnd, hdc, "TEWILOGO", size.left, size.top, WINWIDTH(size), WINWIDTH(size)); 88 88 EndPaint(hWnd, &ps); 89 } else if(msg == WM_CTLCOLORDLG || msg == WM_CTLCOLORSTATIC){89 } else if(msg == WM_CTLCOLORDLG || msg == WM_CTLCOLORSTATIC) { 90 90 HDC dc = (HDC)wp; 91 91 SetBkMode(dc, TRANSPARENT); 92 92 return (LRESULT)GetSysColorBrush(COLOR_MENU); 93 } else{93 } else { 94 94 return FALSE; 95 95 } … … 97 97 } 98 98 99 void tewi_thread(void* ptr) {99 void tewi_thread(void* ptr) { 100 100 int st = startup(0, NULL); 101 101 was_starting = TRUE; 102 if(st == -1) {102 if(st == -1) { 103 103 tewi_alive = TRUE; 104 104 idle = FALSE; 105 } else{105 } else { 106 106 cm_force_log("Config error"); 107 107 idle = FALSE; … … 116 116 } 117 117 118 void StartTewi(void) {118 void StartTewi(void) { 119 119 EnableWindow(button_start, FALSE); 120 120 EnableWindow(button_stop, FALSE); … … 122 122 } 123 123 124 void StopTewi(void) {124 void StopTewi(void) { 125 125 EnableWindow(button_start, FALSE); 126 126 EnableWindow(button_stop, FALSE); … … 128 128 } 129 129 130 LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) {131 if(msg == WM_COMMAND) {130 LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { 131 if(msg == WM_COMMAND) { 132 132 int trig = LOWORD(wp); 133 133 int ev = HIWORD(wp); 134 if(trig == GUI_BUTTON_ABOUT) {135 if(ev == BN_CLICKED) {134 if(trig == GUI_BUTTON_ABOUT) { 135 if(ev == BN_CLICKED) { 136 136 DialogBox(hInst, "VERSIONDLG", hWnd, (DLGPROC)VersionDialog); 137 137 } 138 } else if(trig == GUI_BUTTON_START){139 if(ev == BN_CLICKED) {140 SendMessage(status, SB_SETTEXT, 0, (LPARAM) "Starting Tewi HTTPd");138 } else if(trig == GUI_BUTTON_START) { 139 if(ev == BN_CLICKED) { 140 SendMessage(status, SB_SETTEXT, 0, (LPARAM) "Starting Tewi HTTPd"); 141 141 StartTewi(); 142 142 } 143 } else if(trig == GUI_BUTTON_STOP){144 if(ev == BN_CLICKED) {145 SendMessage(status, SB_SETTEXT, 0, (LPARAM) "Stopping Tewi HTTPd");143 } else if(trig == GUI_BUTTON_STOP) { 144 if(ev == BN_CLICKED) { 145 SendMessage(status, SB_SETTEXT, 0, (LPARAM) "Stopping Tewi HTTPd"); 146 146 StopTewi(); 147 147 } 148 }else if(trig == GUI_BUTTON_EXIT){ 149 if(ev == BN_CLICKED){ 150 if(tewi_alive){ 151 SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Stopping Tewi HTTPd"); 148 } else if(trig == GUI_BUTTON_RESET) { 149 if(ev == BN_CLICKED) { 150 SendMessage(logarea, LB_RESETCONTENT, 0, 0); 151 max = 0; 152 SendMessage(logarea, LB_SETHORIZONTALEXTENT, max, 0); 153 } 154 } else if(trig == GUI_BUTTON_EXIT) { 155 if(ev == BN_CLICKED) { 156 if(tewi_alive) { 157 SendMessage(status, SB_SETTEXT, 0, (LPARAM) "Stopping Tewi HTTPd"); 152 158 StopTewi(); 153 159 exiting = TRUE; 154 } else{160 } else { 155 161 SendMessage(hWnd, WM_CLOSE, 0, 0); 156 162 } 157 163 } 158 } else if(trig == GUI_LOG){164 } else if(trig == GUI_LOG) { 159 165 } 160 } else if(msg == WM_CLOSE){166 } else if(msg == WM_CLOSE) { 161 167 DestroyWindow(hWnd); 162 } else if(msg == WM_DESTROY){168 } else if(msg == WM_DESTROY) { 163 169 DeleteObject(pbtewi_brush); 164 170 PostQuitMessage(0); 165 } else if(msg == WM_CREATE){171 } else if(msg == WM_CREATE) { 166 172 RECT rc, src; 167 173 GetClientRect(hWnd, &rc); … … 173 179 status = CreateStatusWindow(WS_CHILD | WS_VISIBLE | CCS_BOTTOM, NULL, hWnd, GUI_STATUS); 174 180 SendMessage(status, SB_SIMPLE, 0, 0); 175 SendMessage(status, SB_SETTEXT, 0, (LPARAM) "Welcome to Tewi HTTPd");181 SendMessage(status, SB_SETTEXT, 0, (LPARAM) "Welcome to Tewi HTTPd"); 176 182 SendMessage(status, SB_GETRECT, 0, (LPARAM)&src); 177 183 … … 180 186 button_stop = CreateWindow("BUTTON", "S&top", WS_CHILD | WS_VISIBLE | WS_DISABLED | BS_PUSHBUTTON, WINWIDTH(rc) - 100, 20 * 1, 100, 20, hWnd, (HMENU)GUI_BUTTON_STOP, hInst, NULL); 181 187 button_about = CreateWindow("BUTTON", "&About", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, WINWIDTH(rc) - 100, 20 * 2, 100, 20, hWnd, (HMENU)GUI_BUTTON_ABOUT, hInst, NULL); 182 button_about = CreateWindow("BUTTON", "E&xit", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, WINWIDTH(rc) - 100, WINHEIGHT(rc) - WINHEIGHT(src) - 20, 100, 20, hWnd, (HMENU)GUI_BUTTON_EXIT, hInst, NULL); 188 button_reset = CreateWindow("BUTTON", "&Reset", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, WINWIDTH(rc) - 100, WINHEIGHT(rc) - WINHEIGHT(src) - 20 - 20, 100, 20, hWnd, (HMENU)GUI_BUTTON_RESET, hInst, NULL); 189 button_exit = CreateWindow("BUTTON", "E&xit", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, WINWIDTH(rc) - 100, WINHEIGHT(rc) - WINHEIGHT(src) - 20, 100, 20, hWnd, (HMENU)GUI_BUTTON_EXIT, hInst, NULL); 183 190 logarea = CreateWindow("LISTBOX", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | LBS_NOINTEGRALHEIGHT | LBS_NOSEL, 0, 40, WINWIDTH(rc) - 100, WINHEIGHT(rc) - 40 - WINHEIGHT(src), hWnd, (HMENU)GUI_LOG, hInst, NULL); 184 191 … … 186 193 187 194 SetTimer(hWnd, TIMER_WATCH_TEWI, 100, NULL); 188 } else if(msg == WM_TIMER){189 if(wp == TIMER_WATCH_TEWI) {190 if(idle) {191 } else if(tewi_alive){192 if(was_starting) {195 } else if(msg == WM_TIMER) { 196 if(wp == TIMER_WATCH_TEWI) { 197 if(idle) { 198 } else if(tewi_alive) { 199 if(was_starting) { 193 200 was_starting = FALSE; 194 SendMessage(status, SB_SETTEXT, 0, (LPARAM) "Started Tewi HTTPd");201 SendMessage(status, SB_SETTEXT, 0, (LPARAM) "Started Tewi HTTPd"); 195 202 } 196 203 EnableWindow(button_start, FALSE); 197 204 EnableWindow(button_stop, TRUE); 198 205 idle = TRUE; 199 } else{200 if(was_starting) {206 } else { 207 if(was_starting) { 201 208 was_starting = FALSE; 202 SendMessage(status, SB_SETTEXT, 0, (LPARAM) "Stopped Tewi HTTPd");209 SendMessage(status, SB_SETTEXT, 0, (LPARAM) "Stopped Tewi HTTPd"); 203 210 } 204 211 EnableWindow(button_start, TRUE); 205 212 EnableWindow(button_stop, FALSE); 206 if(exiting) {213 if(exiting) { 207 214 KillTimer(hWnd, TIMER_WATCH_TEWI); 208 215 SendMessage(hWnd, WM_CLOSE, 0, 0); … … 211 218 } 212 219 } 213 } else if(msg == WM_PAINT){220 } else if(msg == WM_PAINT) { 214 221 HDC hdc; 215 222 PAINTSTRUCT ps; … … 223 230 ShowBitmap(hWnd, hdc, "PBTEWI", 0, 0); 224 231 EndPaint(hWnd, &ps); 225 } else{232 } else { 226 233 return DefWindowProc(hWnd, msg, wp, lp); 227 234 } … … 229 236 } 230 237 231 BOOL InitApp(void) {238 BOOL InitApp(void) { 232 239 WNDCLASSEX wc; 233 240 wc.cbSize = sizeof(WNDCLASSEX); … … 246 253 } 247 254 248 BOOL InitWindow(int nCmdShow) {255 BOOL InitWindow(int nCmdShow) { 249 256 HWND hWnd; 250 257 RECT deskrc, rc; … … 253 260 hWnd = CreateWindow("tewihttpd", "Tewi HTTPd", (WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME) ^ WS_MAXIMIZEBOX, 0, 0, 600, 400, NULL, 0, hInst, NULL); 254 261 255 if(!hWnd) {262 if(!hWnd) { 256 263 return FALSE; 257 264 } … … 263 270 } 264 271 265 int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPSTR lpsCmdLine, int nCmdShow) {272 int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPSTR lpsCmdLine, int nCmdShow) { 266 273 MSG msg; 267 274 BOOL bret; … … 272 279 idle = TRUE; 273 280 logfile = stderr; 274 if(!InitApp()) {275 return FALSE; 276 } 277 if(!InitWindow(nCmdShow)) {278 return FALSE; 279 } 280 281 while((bret = GetMessage(&msg, NULL, 0, 0)) != 0) {281 if(!InitApp()) { 282 return FALSE; 283 } 284 if(!InitWindow(nCmdShow)) { 285 return FALSE; 286 } 287 288 while((bret = GetMessage(&msg, NULL, 0, 0)) != 0) { 282 289 if(bret == -1) { 283 290 break;
Note:
See TracChangeset
for help on using the changeset viewer.