1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
// w32dlib - Win32 Control Helpers
//
// Copyright (C) 2005 Ian Cowburn (ianc@noddybox.demon.co.uk)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// -------------------------------------------------------------------------
//
#include "w32dlib/base.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
namespace W32DLib
{
// Just to save any cstdio is it a define or function worries
//
using namespace std;
#ifdef W32D_DEBUG
const char *MsgName(UINT msg)
{
switch(msg)
{
case WM_APP: return "WM_APP";
case WM_ACTIVATE: return "WM_ACTIVATE";
case WM_ACTIVATEAPP: return "WM_ACTIVATEAPP";
case WM_AFXFIRST: return "WM_AFXFIRST";
case WM_AFXLAST: return "WM_AFXLAST";
case WM_ASKCBFORMATNAME: return "WM_ASKCBFORMATNAME";
case WM_CANCELJOURNAL: return "WM_CANCELJOURNAL";
case WM_CANCELMODE: return "WM_CANCELMODE";
case WM_CAPTURECHANGED: return "WM_CAPTURECHANGED";
case WM_CHANGECBCHAIN: return "WM_CHANGECBCHAIN";
case WM_CHAR: return "WM_CHAR";
case WM_CHARTOITEM: return "WM_CHARTOITEM";
case WM_CHILDACTIVATE: return "WM_CHILDACTIVATE";
case WM_CLEAR: return "WM_CLEAR";
case WM_CLOSE: return "WM_CLOSE";
case WM_COMMAND: return "WM_COMMAND";
case WM_COMMNOTIFY: return "WM_COMMNOTIFY";
case WM_COMPACTING: return "WM_COMPACTING";
case WM_COMPAREITEM: return "WM_COMPAREITEM";
case WM_CONTEXTMENU: return "WM_CONTEXTMENU";
case WM_COPY: return "WM_COPY";
case WM_COPYDATA: return "WM_COPYDATA";
case WM_CREATE: return "WM_CREATE";
case WM_CTLCOLORBTN: return "WM_CTLCOLORBTN";
case WM_CTLCOLORDLG: return "WM_CTLCOLORDLG";
case WM_CTLCOLOREDIT: return "WM_CTLCOLOREDIT";
case WM_CTLCOLORLISTBOX: return "WM_CTLCOLORLISTBOX";
case WM_CTLCOLORMSGBOX: return "WM_CTLCOLORMSGBOX";
case WM_CTLCOLORSCROLLBAR: return "WM_CTLCOLORSCROLLBAR";
case WM_CTLCOLORSTATIC: return "WM_CTLCOLORSTATIC";
case WM_CUT: return "WM_CUT";
case WM_DEADCHAR: return "WM_DEADCHAR";
case WM_DELETEITEM: return "WM_DELETEITEM";
case WM_DESTROY: return "WM_DESTROY";
case WM_DESTROYCLIPBOARD: return "WM_DESTROYCLIPBOARD";
case WM_DEVICECHANGE: return "WM_DEVICECHANGE";
case WM_DEVMODECHANGE: return "WM_DEVMODECHANGE";
case WM_DISPLAYCHANGE: return "WM_DISPLAYCHANGE";
case WM_DRAWCLIPBOARD: return "WM_DRAWCLIPBOARD";
case WM_DRAWITEM: return "WM_DRAWITEM";
case WM_DROPFILES: return "WM_DROPFILES";
case WM_ENABLE: return "WM_ENABLE";
case WM_ENDSESSION: return "WM_ENDSESSION";
case WM_ENTERIDLE: return "WM_ENTERIDLE";
case WM_ENTERMENULOOP: return "WM_ENTERMENULOOP";
case WM_ENTERSIZEMOVE: return "WM_ENTERSIZEMOVE";
case WM_ERASEBKGND: return "WM_ERASEBKGND";
case WM_EXITMENULOOP: return "WM_EXITMENULOOP";
case WM_EXITSIZEMOVE: return "WM_EXITSIZEMOVE";
case WM_FONTCHANGE: return "WM_FONTCHANGE";
case WM_GETDLGCODE: return "WM_GETDLGCODE";
case WM_GETFONT: return "WM_GETFONT";
case WM_GETHOTKEY: return "WM_GETHOTKEY";
case WM_GETICON: return "WM_GETICON";
case WM_GETMINMAXINFO: return "WM_GETMINMAXINFO";
case WM_GETTEXT: return "WM_GETTEXT";
case WM_GETTEXTLENGTH: return "WM_GETTEXTLENGTH";
case WM_HANDHELDFIRST: return "WM_HANDHELDFIRST";
case WM_HANDHELDLAST: return "WM_HANDHELDLAST";
case WM_HELP: return "WM_HELP";
case WM_HOTKEY: return "WM_HOTKEY";
case WM_HSCROLL: return "WM_HSCROLL";
case WM_HSCROLLCLIPBOARD: return "WM_HSCROLLCLIPBOARD";
case WM_ICONERASEBKGND: return "WM_ICONERASEBKGND";
case WM_INITDIALOG: return "WM_INITDIALOG";
case WM_INITMENU: return "WM_INITMENU";
case WM_INITMENUPOPUP: return "WM_INITMENUPOPUP";
case WM_INPUTLANGCHANGE: return "WM_INPUTLANGCHANGE";
case WM_INPUTLANGCHANGEREQUEST: return "WM_INPUTLANGCHANGEREQUEST";
case WM_KEYDOWN: return "WM_KEYDOWN";
case WM_KEYUP: return "WM_KEYUP";
case WM_KILLFOCUS: return "WM_KILLFOCUS";
case WM_MDIACTIVATE: return "WM_MDIACTIVATE";
case WM_MDICASCADE: return "WM_MDICASCADE";
case WM_MDICREATE: return "WM_MDICREATE";
case WM_MDIDESTROY: return "WM_MDIDESTROY";
case WM_MDIGETACTIVE: return "WM_MDIGETACTIVE";
case WM_MDIICONARRANGE: return "WM_MDIICONARRANGE";
case WM_MDIMAXIMIZE: return "WM_MDIMAXIMIZE";
case WM_MDINEXT: return "WM_MDINEXT";
case WM_MDIREFRESHMENU: return "WM_MDIREFRESHMENU";
case WM_MDIRESTORE: return "WM_MDIRESTORE";
case WM_MDISETMENU: return "WM_MDISETMENU";
case WM_MDITILE: return "WM_MDITILE";
case WM_MEASUREITEM: return "WM_MEASUREITEM";
//case WM_MENURBUTTONUP: return "WM_MENURBUTTONUP";
case WM_MENUCHAR: return "WM_MENUCHAR";
case WM_MENUSELECT: return "WM_MENUSELECT";
case WM_NEXTMENU: return "WM_NEXTMENU";
case WM_MOVE: return "WM_MOVE";
case WM_MOVING: return "WM_MOVING";
case WM_NCACTIVATE: return "WM_NCACTIVATE";
case WM_NCCALCSIZE: return "WM_NCCALCSIZE";
case WM_NCCREATE: return "WM_NCCREATE";
case WM_NCDESTROY: return "WM_NCDESTROY";
case WM_NCHITTEST: return "WM_NCHITTEST";
case WM_NCLBUTTONDBLCLK: return "WM_NCLBUTTONDBLCLK";
case WM_NCLBUTTONDOWN: return "WM_NCLBUTTONDOWN";
case WM_NCLBUTTONUP: return "WM_NCLBUTTONUP";
case WM_NCMBUTTONDBLCLK: return "WM_NCMBUTTONDBLCLK";
case WM_NCMBUTTONDOWN: return "WM_NCMBUTTONDOWN";
case WM_NCMBUTTONUP: return "WM_NCMBUTTONUP";
case WM_NCMOUSEMOVE: return "WM_NCMOUSEMOVE";
case WM_NCPAINT: return "WM_NCPAINT";
case WM_NCRBUTTONDBLCLK: return "WM_NCRBUTTONDBLCLK";
case WM_NCRBUTTONDOWN: return "WM_NCRBUTTONDOWN";
case WM_NCRBUTTONUP: return "WM_NCRBUTTONUP";
case WM_NEXTDLGCTL: return "WM_NEXTDLGCTL";
case WM_NOTIFY: return "WM_NOTIFY";
case WM_NOTIFYFORMAT: return "WM_NOTIFYFORMAT";
case WM_NULL: return "WM_NULL";
case WM_PAINT: return "WM_PAINT";
case WM_PAINTCLIPBOARD: return "WM_PAINTCLIPBOARD";
case WM_PAINTICON: return "WM_PAINTICON";
case WM_PALETTECHANGED: return "WM_PALETTECHANGED";
case WM_PALETTEISCHANGING: return "WM_PALETTEISCHANGING";
case WM_PARENTNOTIFY: return "WM_PARENTNOTIFY";
case WM_PASTE: return "WM_PASTE";
case WM_PENWINFIRST: return "WM_PENWINFIRST";
case WM_PENWINLAST: return "WM_PENWINLAST";
case WM_POWER: return "WM_POWER";
case WM_POWERBROADCAST: return "WM_POWERBROADCAST";
case WM_PRINT: return "WM_PRINT";
case WM_PRINTCLIENT: return "WM_PRINTCLIENT";
case WM_QUERYDRAGICON: return "WM_QUERYDRAGICON";
case WM_QUERYENDSESSION: return "WM_QUERYENDSESSION";
case WM_QUERYNEWPALETTE: return "WM_QUERYNEWPALETTE";
case WM_QUERYOPEN: return "WM_QUERYOPEN";
case WM_QUEUESYNC: return "WM_QUEUESYNC";
case WM_QUIT: return "WM_QUIT";
case WM_RENDERALLFORMATS: return "WM_RENDERALLFORMATS";
case WM_RENDERFORMAT: return "WM_RENDERFORMAT";
case WM_SETCURSOR: return "WM_SETCURSOR";
case WM_SETFOCUS: return "WM_SETFOCUS";
case WM_SETFONT: return "WM_SETFONT";
case WM_SETHOTKEY: return "WM_SETHOTKEY";
case WM_SETICON: return "WM_SETICON";
case WM_SETREDRAW: return "WM_SETREDRAW";
case WM_SETTEXT: return "WM_SETTEXT";
case WM_SETTINGCHANGE: return "WM_SETTINGCHANGE";
case WM_SHOWWINDOW: return "WM_SHOWWINDOW";
case WM_SIZE: return "WM_SIZE";
case WM_SIZECLIPBOARD: return "WM_SIZECLIPBOARD";
case WM_SIZING: return "WM_SIZING";
case WM_SPOOLERSTATUS: return "WM_SPOOLERSTATUS";
case WM_STYLECHANGED: return "WM_STYLECHANGED";
case WM_STYLECHANGING: return "WM_STYLECHANGING";
case WM_SYSCHAR: return "WM_SYSCHAR";
case WM_SYSCOLORCHANGE: return "WM_SYSCOLORCHANGE";
case WM_SYSCOMMAND: return "WM_SYSCOMMAND";
case WM_SYSDEADCHAR: return "WM_SYSDEADCHAR";
case WM_SYSKEYDOWN: return "WM_SYSKEYDOWN";
case WM_SYSKEYUP: return "WM_SYSKEYUP";
case WM_TCARD: return "WM_TCARD";
case WM_TIMECHANGE: return "WM_TIMECHANGE";
case WM_TIMER: return "WM_TIMER";
case WM_UNDO: return "WM_UNDO";
case WM_USER: return "WM_USER";
case WM_USERCHANGED: return "WM_USERCHANGED";
case WM_VKEYTOITEM: return "WM_VKEYTOITEM";
case WM_VSCROLL: return "WM_VSCROLL";
case WM_VSCROLLCLIPBOARD: return "WM_VSCROLLCLIPBOARD";
case WM_WINDOWPOSCHANGED: return "WM_WINDOWPOSCHANGED";
case WM_WINDOWPOSCHANGING: return "WM_WINDOWPOSCHANGING";
//case WM_WININICHANGE: return "WM_WININICHANGE";
//case WM_KEYFIRST: return "WM_KEYFIRST";
//case WM_KEYLAST: return "WM_KEYLAST";
case WM_SYNCPAINT: return "WM_SYNCPAINT";
case WM_MOUSEACTIVATE: return "WM_MOUSEACTIVATE";
case WM_MOUSEMOVE: return "WM_MOUSEMOVE";
case WM_LBUTTONDOWN: return "WM_LBUTTONDOWN";
case WM_LBUTTONUP: return "WM_LBUTTONUP";
case WM_LBUTTONDBLCLK: return "WM_LBUTTONDBLCLK";
case WM_RBUTTONDOWN: return "WM_RBUTTONDOWN";
case WM_RBUTTONUP: return "WM_RBUTTONUP";
case WM_RBUTTONDBLCLK: return "WM_RBUTTONDBLCLK";
case WM_MBUTTONDOWN: return "WM_MBUTTONDOWN";
case WM_MBUTTONUP: return "WM_MBUTTONUP";
case WM_MBUTTONDBLCLK: return "WM_MBUTTONDBLCLK";
case WM_MOUSEWHEEL: return "WM_MOUSEWHEEL";
//case WM_MOUSEFIRST: return "WM_MOUSEFIRST";
//case WM_MOUSELAST: return "WM_MOUSELAST";
case WM_MOUSEHOVER: return "WM_MOUSEHOVER";
case WM_MOUSELEAVE: return "WM_MOUSELEAVE";
default: return "UNKNOWN";
}
}
void W32Debug(const char *func, const char *file, const char *msg)
{
static const char *filter=std::getenv("W32DEBUGFILTER");
static FILE *fp=0;
int len;
if (!fp)
{
fp=fopen("c:/debug.out","w");
setbuf(fp,0);
}
if (filter && !std::strstr(filter,file))
{
return;
}
len=35-std::strlen(func)-std::strlen(file)-3;
if (len<1)
{
fprintf(fp,"%s (%s): %s\n",func,file,msg);
}
else
{
fprintf(fp,"%s (%s)%-*.*s: %s\n",func,file,len,len,"",msg);
}
}
#else
const char *MsgName(UINT msg)
{
return "";
}
void W32Debug(const char *func, const char *file, const char *msg)
{
}
#endif // W32D_DEBUG
std::string EncodeCString(const char *p)
{
std::string ret("\"");
while(*p)
{
switch(*p)
{
case '"':
ret+="\\\"";
break;
case '\r':
ret+="\\r";
break;
case '\n':
ret+="\\n";
break;
default:
if (*p<32 || *p>126)
{
char s[32];
sprintf(s,"\\0%o",static_cast<unsigned int>(*p));
ret+=s;
}
else
{
ret+=*p;
}
break;
}
p++;
}
ret+="\"";
return ret;
}
}; // namespace W32DLib
// END OF FILE
|