Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 271 lines (225 sloc) 7.813 kB
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
1 /*
2 ** WinElvis.c -- MS-Windows port of elvis.
3 **
4 ** Copyright 1996, Serge Pirotte.
5 */
6
7 #define CHAR Char
8 #define BOOLEAN Boolean
9 #include "elvis.h"
10 #undef CHAR
11 #undef BOOLEAN
12
13 #if defined (GUI_WIN32)
14
15 #define _WIN32_WINNT 0x400
16 #include <windows.h>
17 #include <commctrl.h>
18 #include "winelvis.h"
19 #include "elvisres.h"
20 #include "wintools.h"
21 #if _MSC_VER <= 900
22 #if defined (USE_CTL3D)
23 #include <ctl3d.h>
24 #endif
25 #endif
26
27 extern void main (int argc, char **argv);
28
29 HINSTANCE hInst;
30 HCURSOR hLeftArrow;
31 HCURSOR hRightArrow;
32 HCURSOR selectedCursor;
33
34 #if _MSC_VER <= 900
35 #if defined (USE_CTL3D)
36 HANDLE ctl3d_handle;
37 #endif
38 #endif
39
40 static int init_application (HINSTANCE hInst);
41 static int init_instance (HINSTANCE hInst);
42 static void exit_instance (HINSTANCE hInst);
43 static LONG APIENTRY FrameWndProc (HWND hwnd, UINT msg,
44 UINT wParam, LONG lParam);
45 static LONG APIENTRY ClientWndProc (HWND hwnd, UINT msg,
46 UINT wParam, LONG lParam);
47
48 /* ---[ WinMain ]------------------------------------------------------ */
49
50 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
51 LPSTR lpCmdLine, int nCmdShow)
52
53 {
54 hInst = hInstance;
55
56 /* register the window classes */
57 if (!hPrevInstance)
58 if (!init_application (hInstance))
59 return FALSE;
60
61 /* instance specific initialization */
62 if (!init_instance (hInstance))
63 return FALSE;
64
65 /* parse the command line */
66 parse_cmd_line (lpCmdLine);
67
68 /* call elvis */
69 main (cmd_line_argc, cmd_line_argv);
70
71 /* instance specific cleanup */
72 exit_instance (hInstance);
73
74 return 0;
75 }
76
77 /* ---[ init_application ]--------------------------------------------- */
78
79 static int init_application (HINSTANCE hInst)
80
81 {
82 WNDCLASS wndclass;
83
84 /* find common controls library */
85 InitCommonControls ();
86
87 /* get cursors */
88 hLeftArrow = LoadCursor (NULL, IDC_ARROW);
89 hRightArrow = LoadCursor (hInst, MAKEINTRESOURCE (IDC_RIGHTARROW));
90 selectedCursor = hLeftArrow;
91
92 /* register frame window */
93 wndclass.style = CS_HREDRAW | CS_VREDRAW;
94 wndclass.lpfnWndProc = (WNDPROC)FrameWndProc;
95 wndclass.cbClsExtra = 0;
96 wndclass.cbWndExtra = 0;
97 wndclass.hInstance = hInst;
98 wndclass.hIcon = LoadIcon (hInst, MAKEINTRESOURCE (IDI_ELVIS));
99 wndclass.hCursor = NULL;
100 wndclass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
101 wndclass.lpszMenuName = MAKEINTRESOURCE (IDM_ELVIS);
102 wndclass.lpszClassName = "ElvisFrameWnd";
103
104 if (!RegisterClass (&wndclass))
105 return FALSE;
106
107 /* register client window */
108 wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
109 wndclass.lpfnWndProc = (WNDPROC)ClientWndProc;
110 wndclass.hbrBackground = NULL;
111 wndclass.lpszMenuName = NULL;
112 wndclass.lpszClassName = "ElvisClientWnd";
113
114 if (!RegisterClass (&wndclass))
115 return FALSE;
116
117 /* indicate success */
118 return TRUE;
119 }
120
121 /* ---[ init_instance ]------------------------------------------------ */
122
123 static int init_instance (HINSTANCE hInstance)
124
125 {
126 #if _MSC_VER < 900
127 #if defined (USE_CTL3D)
128 /* try to register to the 3D controls library */
129 if ((ctl3d_handle = LoadLibrary ("CTL3D32.DLL")) != NULL) {
130 Ctl3dRegister (hInstance);
131 Ctl3dAutoSubclass (hInstance);
132 }
133 #endif
134 #endif
135
136 return TRUE;
137 }
138
139 /* ---[ exit_instance ]------------------------------------------------ */
140
141 static void exit_instance (HINSTANCE hInstance)
142
143 {
144 #if _MSC_VER < 900
145 #if defined (USE_CTL3D)
146 /* try to unregister to the 3D controls library */
147 if (ctl3d_handle != NULL) {
148 Ctl3dUnregister (hInstance);
149 FreeLibrary (ctl3d_handle);
150 }
151 #endif
152 #endif
153 }
154
155 /* ---[ FrameWndProc ]------------------------------------------------- */
156
157 LONG APIENTRY FrameWndProc (HWND hwnd, UINT msg, UINT wParam, LONG lParam)
158
159 {
160 LONG rc = 1;
161
162 switch (msg) {
163 case WM_COMMAND:
164 rc = gwcmd (gw_find_frame (hwnd), wParam);
165 break;
166 case WM_CLOSE:
167 rc = gwcmd (gw_find_frame (hwnd), (UINT)IDM_FILE_EXIT);
168 break;
169 case WM_GETMINMAXINFO:
170 rc = gwframe_WM_GETMINMAXINFO (gw_find_frame (hwnd), wParam, lParam);
171 break;
172 case WM_INITMENU:
173 rc = gwframe_WM_INITMENU (gw_find_frame (hwnd), wParam, lParam);
174 break;
175 case WM_MENUSELECT:
176 rc = gwframe_WM_MENUSELECT (gw_find_frame (hwnd), wParam, lParam);
177 break;
178 #if _MSC_VER > 900
179 case WM_NOTIFY:
180 rc = gwframe_WM_NOTIFY (gw_find_frame (hwnd), wParam, lParam);
181 break;
182 #endif
183 case WM_PAINT:
184 rc = gwframe_WM_PAINT (gw_find_frame (hwnd), wParam, lParam);
185 break;
186 case WM_SETFOCUS:
187 rc = gwframe_WM_SETFOCUS (gw_find_frame (hwnd), wParam, lParam);
188 break;
189 case WM_SIZE:
190 rc = gwframe_WM_SIZE (gw_find_frame (hwnd), wParam, lParam);
191 break;
192 }
193
194 return (rc == 0) ? 0 : DefWindowProc (hwnd, msg, wParam, lParam);
195 }
196
197 /* ---[ ClientWndProc ]------------------------------------------------ */
198
199 LONG APIENTRY ClientWndProc (HWND hwnd, UINT msg, UINT wParam, LONG lParam)
200
201 {
202 LONG rc = 1;
203
204 switch (msg) {
205 case WM_CHAR:
206 rc = gwclient_WM_CHAR (gw_find_client (hwnd), wParam, lParam);
207 break;
208 case WM_DROPFILES:
209 rc = gwclient_WM_DROPFILES (gw_find_client (hwnd), wParam, lParam);
210 break;
211 case WM_ERASEBKGND:
212 rc = gwclient_WM_ERASEBKGND (gw_find_client (hwnd), wParam, lParam);
213 break;
214 case WM_KEYDOWN:
215 rc = gwclient_WM_KEYDOWN (gw_find_client (hwnd), wParam, lParam);
216 break;
217 case WM_KEYUP:
218 rc = gwclient_WM_KEYUP (gw_find_client (hwnd), wParam, lParam);
219 break;
220 case WM_KILLFOCUS:
221 rc = gwclient_WM_KILLFOCUS (gw_find_client (hwnd), wParam, lParam);
222 break;
223 case WM_LBUTTONDBLCLK:
224 rc = gwclient_WM_LBUTTONDBLCLK (gw_find_client (hwnd), wParam, lParam);
225 break;
226 case WM_LBUTTONDOWN:
227 rc = gwclient_WM_LBUTTONDOWN (gw_find_client (hwnd), wParam, lParam);
228 break;
229 case WM_LBUTTONUP:
230 rc = gwclient_WM_LBUTTONUP (gw_find_client (hwnd), wParam, lParam);
231 break;
232 case WM_MOUSEMOVE:
233 rc = gwclient_WM_MOUSEMOVE (gw_find_client (hwnd), wParam, lParam);
234 break;
235 #if defined (WM_MOUSEWHEEL)
236 case WM_MOUSEWHEEL:
237 rc = gwclient_WM_MOUSEWHEEL (gw_find_client (hwnd), wParam, lParam);
238 break;
239 #endif
240 case WM_PAINT:
241 rc = gwclient_WM_PAINT (gw_find_client (hwnd), wParam, lParam);
242 break;
243 case WM_RBUTTONDBLCLK:
244 rc = gwclient_WM_RBUTTONDBLCLK (gw_find_client (hwnd), wParam, lParam);
245 break;
246 case WM_RBUTTONDOWN:
247 rc = gwclient_WM_RBUTTONDOWN (gw_find_client (hwnd), wParam, lParam);
248 break;
249 case WM_RBUTTONUP:
250 rc = gwclient_WM_RBUTTONUP (gw_find_client (hwnd), wParam, lParam);
251 break;
252 case WM_SETFOCUS:
253 rc = gwclient_WM_SETFOCUS (gw_find_client (hwnd), wParam, lParam);
254 break;
255 case WM_SIZE:
256 rc = gwclient_WM_SIZE (gw_find_client (hwnd), wParam, lParam);
257 break;
258 case WM_SYSKEYDOWN:
259 rc = gwclient_WM_SYSKEYDOWN (gw_find_client (hwnd), wParam, lParam);
260 break;
261 case WM_VSCROLL:
262 rc = gwclient_WM_VSCROLL (gw_find_client (hwnd), wParam, lParam);
263 break;
264 }
265
266 return (rc == 0) ? 0 : DefWindowProc (hwnd, msg, wParam, lParam);
267 }
268
269 #endif
270
Something went wrong with that request. Please try again.