source: Main/trunk/Server/gui.c@ 251

Last change on this file since 251 was 249, checked in by Nishi, on Oct 4, 2024 at 5:59:55 AM

fix vc6

  • Property svn:keywords set to Id
File size: 6.4 KB
Line 
1/* $Id: gui.c 249 2024-10-03 20:59:55Z nishi $ */
2
3#include "../config.h"
4
5#include "gui.h"
6
7#include <windows.h>
8#include <commctrl.h>
9
10HINSTANCE hInst;
11HBRUSH pbtewi_brush;
12HWND logarea;
13HWND button_start;
14HWND button_stop;
15HWND button_about;
16HWND status;
17BOOL tewi_alive;
18BOOL was_starting;
19BOOL exiting;
20
21#define WINWIDTH(rc) (rc.right - rc.left)
22#define WINHEIGHT(rc) (rc.bottom - rc.top)
23
24#define DIALOG_X(n) (HIWORD(GetDialogBaseUnits()) * n)
25#define DIALOG_Y(n) (LOWORD(GetDialogBaseUnits()) * n)
26
27void ShowBitmapSize(HWND hWnd, HDC hdc, const char* name, int x, int y, int w, int h){
28 HBITMAP hBitmap = LoadBitmap(hInst, name);
29 BITMAP bmp;
30 HDC hmdc;
31 GetObject(hBitmap, sizeof(bmp), &bmp);
32 hmdc = CreateCompatibleDC(hdc);
33 SelectObject(hmdc, hBitmap);
34 if(w == 0 && h == 0){
35 StretchBlt(hdc, x, y, bmp.bmWidth, bmp.bmHeight, hmdc, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
36 }else{
37 StretchBlt(hdc, x, y, w, h, hmdc, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
38 }
39 DeleteDC(hmdc);
40 DeleteObject(hBitmap);
41}
42
43void ShowBitmap(HWND hWnd, HDC hdc, const char* name, int x, int y){
44 ShowBitmapSize(hWnd, hdc, name, x, y, 0, 0);
45}
46
47LRESULT CALLBACK VersionDialog(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp){
48 if(msg == WM_COMMAND){
49 if(LOWORD(wp) == IDOK) EndDialog(hWnd, IDOK);
50 }else if(msg == WM_PAINT){
51 HDC hdc;
52 PAINTSTRUCT ps;
53 RECT size;
54
55 size.left = size.top = 5;
56 size.right = size.bottom = 32 + 5;
57 MapDialogRect(hWnd, &size);
58
59 hdc = BeginPaint(hWnd, &ps);
60 ShowBitmapSize(hWnd, hdc, "TEWILOGO", size.left, size.top, WINWIDTH(size), WINWIDTH(size));
61 EndPaint(hWnd, &ps);
62 }else if(msg == WM_CTLCOLORDLG || msg == WM_CTLCOLORSTATIC){
63 HDC dc = (HDC)wp;
64 SetBkMode(dc, TRANSPARENT);
65 return GetSysColorBrush(COLOR_MENU);
66 }else{
67 return FALSE;
68 }
69 return TRUE;
70}
71
72void StartTewi(void){
73 was_starting = TRUE;
74}
75
76void StopTewi(void){
77 was_starting = TRUE;
78}
79
80LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp){
81 if(msg == WM_COMMAND){
82 int trig = LOWORD(wp);
83 int ev = HIWORD(wp);
84 if(trig == GUI_BUTTON_ABOUT){
85 if(ev == BN_CLICKED){
86 DialogBox(hInst, "VERSIONDLG", hWnd, (DLGPROC)VersionDialog);
87 }
88 }else if(trig == GUI_BUTTON_START){
89 if(ev == BN_CLICKED){
90 SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Starting Tewi HTTPd");
91 StartTewi();
92 }
93 }else if(trig == GUI_BUTTON_STOP){
94 if(ev == BN_CLICKED){
95 SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Stopping Tewi HTTPd");
96 StopTewi();
97 }
98 }else if(trig == GUI_BUTTON_EXIT){
99 if(ev == BN_CLICKED){
100 if(tewi_alive){
101 SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Stopping Tewi HTTPd");
102 StopTewi();
103 exiting = TRUE;
104 }else{
105 SendMessage(hWnd, WM_CLOSE, 0, 0);
106 }
107 }
108 }else if(trig == GUI_LOG){
109 }
110 }else if(msg == WM_CLOSE){
111 DestroyWindow(hWnd);
112 }else if(msg == WM_DESTROY){
113 DeleteObject(pbtewi_brush);
114 PostQuitMessage(0);
115 }else if(msg == WM_CREATE){
116 RECT rc, src;
117 GetClientRect(hWnd, &rc);
118
119 InitCommonControls();
120
121 status = CreateStatusWindow(WS_CHILD | WS_VISIBLE | CCS_BOTTOM, NULL, hWnd, GUI_STATUS);
122 SendMessage(status, SB_SIMPLE, 0, 0);
123 SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Welcome to Tewi HTTPd");
124 SendMessage(status, SB_GETRECT, 0, (LPARAM)&src);
125
126 pbtewi_brush = CreateSolidBrush(RGB(0xf7, 0xc9, 0xf3));
127 button_start = CreateWindow("BUTTON", "&Start", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, WINWIDTH(rc) - 100, 20 * 0, 100, 20, hWnd, (HMENU)GUI_BUTTON_START, hInst, NULL);
128 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);
129 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);
130 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);
131 logarea = CreateWindow("LISTBOX", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL, 0, 40, WINWIDTH(rc) - 100, WINHEIGHT(rc) - 40 - WINHEIGHT(src), hWnd, (HMENU)GUI_LOG, hInst, NULL);
132 SetTimer(hWnd, TIMER_WATCH_TEWI, 100, NULL);
133 }else if(msg == WM_TIMER){
134 if(wp == TIMER_WATCH_TEWI){
135 if(tewi_alive){
136 if(was_starting){
137 was_starting = FALSE;
138 SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Started Tewi HTTPd");
139 }
140 EnableWindow(button_start, FALSE);
141 EnableWindow(button_stop, TRUE);
142 }else{
143 if(was_starting){
144 was_starting = FALSE;
145 SendMessage(status, SB_SETTEXT, 0, (LPARAM)"Stopped Tewi HTTPd");
146 }
147 EnableWindow(button_start, TRUE);
148 EnableWindow(button_stop, FALSE);
149 if(exiting){
150 KillTimer(hWnd, TIMER_WATCH_TEWI);
151 SendMessage(hWnd, WM_CLOSE, 0, 0);
152 }
153 }
154 }
155 }else if(msg == WM_PAINT){
156 HDC hdc;
157 PAINTSTRUCT ps;
158 RECT rc;
159 RECT fill;
160
161 GetClientRect(hWnd, &rc);
162 hdc = BeginPaint(hWnd, &ps);
163 SetRect(&fill, 0, 0, WINWIDTH(rc), 40);
164 FillRect(hdc, &fill, pbtewi_brush);
165 ShowBitmap(hWnd, hdc, "PBTEWI", 0, 0);
166 EndPaint(hWnd, &ps);
167 }else{
168 return DefWindowProc(hWnd, msg, wp, lp);
169 }
170 return 0;
171}
172
173BOOL InitApp(void){
174 WNDCLASS wc;
175 wc.style = CS_HREDRAW | CS_VREDRAW;
176 wc.lpfnWndProc = WndProc;
177 wc.cbClsExtra = 0;
178 wc.cbWndExtra = 0;
179 wc.hInstance = hInst;
180 wc.hIcon = LoadIcon(hInst, "TEWI");
181 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
182 wc.hbrBackground = GetSysColorBrush(COLOR_MENU);
183 wc.lpszMenuName = NULL;
184 wc.lpszClassName = "tewihttpd";
185 return RegisterClass(&wc);
186}
187
188BOOL InitWindow(int nCmdShow){
189 HWND hWnd;
190 RECT deskrc, rc;
191 HWND hDeskWnd = GetDesktopWindow();
192 GetWindowRect(hDeskWnd, &deskrc);
193 hWnd = CreateWindow("tewihttpd", "Tewi HTTPd", (WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME) ^ WS_MAXIMIZEBOX, 0, 0, 600, 200, NULL, 0, hInst, NULL);
194
195 if(!hWnd){
196 return FALSE;
197 }
198 GetWindowRect(hWnd, &rc);
199 SetWindowPos(hWnd, HWND_TOP, (deskrc.right - (rc.right - rc.left)) / 2, (deskrc.bottom - (rc.bottom - rc.top)) / 2, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW);
200 ShowWindow(hWnd, nCmdShow);
201 UpdateWindow(hWnd);
202 return TRUE;
203}
204
205int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPSTR lpsCmdLine, int nCmdShow){
206 MSG msg;
207 BOOL bret;
208 hInst = hCurInst;
209 tewi_alive = FALSE;
210 was_starting = FALSE;
211 exiting = FALSE;
212 if(!InitApp()){
213 return FALSE;
214 }
215 if(!InitWindow(nCmdShow)){
216 return FALSE;
217 }
218
219 while((bret = GetMessage(&msg, NULL, 0, 0)) != 0){
220 if(bret == -1) {
221 break;
222 } else {
223 TranslateMessage(&msg);
224 DispatchMessage(&msg);
225 }
226 }
227 return (int)msg.wParam;
228}
Note: See TracBrowser for help on using the repository browser.