-
Notifications
You must be signed in to change notification settings - Fork 0
/
crash.c
346 lines (279 loc) · 13.5 KB
/
crash.c
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
//***************************************************************************
// NARS2000 -- Crash Handling
//***************************************************************************
/***************************************************************************
NARS2000 -- An Experimental APL Interpreter
Copyright (C) 2006-2016 Sudley Place Software
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 3 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, see <http://www.gnu.org/licenses/>.
***************************************************************************/
#define STRICT
#include <windows.h>
#include <windowsx.h>
#include "headers.h"
// Save area for old CC ListBox window procedure address
WNDPROC lpfnOldCCListboxWndProc;
//***************************************************************************
// $CC_Create
//
// Perform window-specific initialization
//***************************************************************************
void CC_Create
(HWND hWnd)
{
} // End CC_Create
//***************************************************************************
// $CC_Delete
//
// Perform window-specific uninitialization
//***************************************************************************
void CC_Delete
(HWND hWnd)
{
} // End CC_Delete
//***************************************************************************
// $CCWndProc
//
// Message processing routine for the Crash window
//***************************************************************************
LRESULT APIENTRY CCWndProc
(HWND hWnd, // Window handle
UINT message, // Type of message
WPARAM wParam, // Additional information
LPARAM lParam) // ...
{
////LCLODSAPI ("CC: ", hWnd, message, wParam, lParam);
switch (message)
{
case WM_CREATE:
// Create an Edit Control to fit inside this window
hWndCC_LB =
CreateWindowExW (0L, // Extended styles
WC_LISTBOXW, // Class name
L"Crash Control Listbox",// For debugging only
0
| WS_CHILD
| WS_VSCROLL
| WS_HSCROLL
| WS_CLIPCHILDREN
| LBS_NOINTEGRALHEIGHT
| LBS_EXTENDEDSEL
| LBS_MULTIPLESEL
, // Styles
0, // X-position
0, // Y-...
CW_USEDEFAULT, // Width
CW_USEDEFAULT, // Height
hWnd, // Parent window
(HMENU) IDWC_CC_LB, // ID
_hInstance, // Instance
0); // lParam
// Subclass the List Box so we can handle
// WM_CONTEXTMENU
lpfnOldCCListboxWndProc = (WNDPROC)
SetWindowLongPtrW (hWndCC_LB,
GWLP_WNDPROC,
(APLU3264) (LONG_PTR) (WNDPROC) &LclCCListboxWndProc);
// Initialize window-specific resources
CC_Create (hWnd);
break;
#define fwSizeType wParam
#define nWidth (LOWORD(lParam))
#define nHeight (HIWORD(lParam))
case WM_SIZE: // fwSizeType = wParam; // Resizing flag
// nWidth = LOWORD(lParam); // Width of client area
// nHeight = HIWORD(lParam); // Height of client area
if (fwSizeType NE SIZE_MINIMIZED)
SetWindowPos (hWndCC_LB, // Window handle to position
0, // SWP_NOZORDER
0, // X-position
0, // Y-...
nWidth, // Width
nHeight, // Height
SWP_NOZORDER // Flags
| SWP_SHOWWINDOW
);
break; // Continue with next handler
#undef nHeight
#undef nWidth
#undef fwSizeType
case WM_SYSCOLORCHANGE:
case WM_SETTINGCHANGE:
// Uninitialize window-specific resources
CC_Delete (hWnd);
// Initialize window-specific resources
CC_Create (hWnd);
break; // Continue with next handler
case WM_CONTEXTMENU: // hwnd = (HWND) wParam;
// xPos = LOSHORT (lParam); // Horizontal position of cursor
// yPos = HISHORT (lParam); // Vertical position of cursor
case LB_ADDSTRING: // 0 = wParam;
// lpsz = (LPCTSTR) lParam;
case WM_SETFONT: // hFont = (HFONT) wParam;
// fRedraw = LOWORD (lParam);
case WM_MOUSEWHEEL:
// Pass these messages through to the Edit Control
SendMessageW (hWndCC_LB, message, wParam, lParam);
return FALSE; // We handled the msg
case MYWM_DISPMB:
////////////MBPW (L"1. Copy the data; 2. When you press OK, the program will terminate.", MB_SYSTEMMODAL);
// Avoid using an owning window handle as that prevents
// the user from copying data from the session.
MessageBoxW (NULL,
L"1. Copy the data; 2. When you press OK, the program will terminate.",
WS_APPNAME,
MB_OK | MB_SYSTEMMODAL);
return FALSE; // We handled the msg
case WM_CLOSE:
DestroyWindow (hWnd);
return FALSE; // We handled the msg
case WM_DESTROY:
// Uninitialize window-specific resources
CC_Delete (hWnd);
// Tell the thread to quit, too
PostQuitMessage (0);
return FALSE; // We handled the msg
default:
break;
} // End SWITCH
////LCLODSAPI ("CCZ:", hWnd, message, wParam, lParam);
return DefWindowProcW (hWnd, message, wParam, lParam);
} // End CCWndProc
//***************************************************************************
// $LclCCListboxWndProc
//
// Local window procedure for the Crash Control's LISTBOX
//***************************************************************************
LRESULT WINAPI LclCCListboxWndProc
(HWND hWnd, // Window handle
UINT message, // Type of message
WPARAM wParam, // Additional information
LPARAM lParam) // ...
{
HMENU hMenu;
int iSelCnt,
mfState,
i,
iTotalBytes;
POINT ptScr;
HGLOBAL hGlbInd,
hGlbSel;
LPINT lpMemInd;
LPWCHAR lpSel,
p;
////LCLODSAPI ("CCLB: ", hWnd, message, wParam, lParam);
// Split cases
switch (message)
{
#define idCtl GET_WM_COMMAND_ID (wParam, lParam)
#define cmdCtl GET_WM_COMMAND_CMD (wParam, lParam)
#define hwndCtl GET_WM_COMMAND_HWND (wParam, lParam)
case WM_COMMAND:
switch (idCtl)
{
case IDM_COPY:
// Get the # selected items
iSelCnt = (UINT) SendMessageW (hWnd, LB_GETSELCOUNT, 0, 0);
// Allocate space for that many indices
hGlbInd = GlobalAlloc (GHND, iSelCnt * sizeof (int));
// Lock the memory to get a ptr to it
lpMemInd = GlobalLock (hGlbInd);
// Populate the array
SendMessageW (hWnd, LB_GETSELITEMS, iSelCnt, (LPARAM) lpMemInd);
// Loop through the selected items and calculate
// the storage requirement for the collection
for (iTotalBytes = i = 0; i < iSelCnt; i++)
// The "EOL_LEN +" is for the WC_CR and WC_LF at the end of each line
iTotalBytes += sizeof (WCHAR) * (EOL_LEN + (UINT) SendMessageW (hWnd, LB_GETTEXTLEN, lpMemInd[i], 0));
// Allocate storage for the entire collection
hGlbSel = GlobalAlloc (GHND | GMEM_DDESHARE, iTotalBytes);
// Lock the memory to get a ptr to it
lpSel = GlobalLock (hGlbSel);
// Copy the text to the array, separated by a newline
for (p = lpSel, i = 0; i < iSelCnt; i++)
{
p += (UINT) SendMessageW (hWnd, LB_GETTEXT, lpMemInd[i], (LPARAM) p);
*p++ = WC_CR;
*p++ = WC_LF;
} // End FOR
// We no longer need this ptr
GlobalUnlock (hGlbSel); lpSel = NULL;
// Unlock and free (and set to NULL) a global name and ptr
UnlFreeGlbName (hGlbInd, lpMemInd);
// Prepare to put the data onto the clipboard
OpenClipboard (hWnd);
EmptyClipboard ();
// Put the data onto the clipboard
SetClipboardData (CF_UNICODETEXT,
hGlbSel);
// We're finished with the clipboard
CloseClipboard ();
////////////////////// Free the memory -- NO, the system now owns hGlbSel
////////////////////GlobalFree (hGlbSel); hGlbSel = NULL;
break;
case IDM_SELECTALL:
// Select all items
if (LB_ERR EQ SendMessageW (hWnd,
LB_SELITEMRANGE,
TRUE,
MAKELPARAM (0, -1)))
DbgStop (); // We should never get here
break;
} // End SWITCH
break;
#undef hwndCtl
#undef cmdCtl
#undef idCtl
case WM_CONTEXTMENU: // hwnd = (HWND) wParam;
// xPos = LOSHORT (lParam); // Horizontal position of cursor
// yPos = HISHORT (lParam); // Vertical position of cursor
// Ensure there are items selected
iSelCnt = (UINT) SendMessageW (hWnd, LB_GETSELCOUNT, 0, 0);
mfState = (iSelCnt EQ 0) ? MF_GRAYED : MF_ENABLED;
// Get the mouse position in screen coordinates
GetCursorPos (&ptScr);
// Create a popup menu
hMenu = CreatePopupMenu ();
AppendMenuW (hMenu, // Handle
mfState
| MF_STRING, // Flags
IDM_COPY,
L"&Copy");
AppendMenuW (hMenu, // Handle
MF_ENABLED
| MF_STRING, // Flags
IDM_SELECTALL,
L"Select &All");
TrackPopupMenu (hMenu, // Handle
0 // Flags
| TPM_CENTERALIGN
| TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
,
ptScr.x, // x-position
ptScr.y, // y-position
0, // Reserved (must be zero)
hWnd, // Handle of owner window
NULL); // Dismissal area outside rectangle (none)
// Free the menu resources
DestroyMenu (hMenu);
return FALSE;
} // End SWITCH
////LCLODSAPI ("CCLBZ: ", hWnd, message, wParam, lParam);
return CallWindowProcW (lpfnOldCCListboxWndProc,
hWnd,
message,
wParam,
lParam); // Pass on down the line
} // End LclCCListboxWndProc
//***************************************************************************
// End of File: crash.c
//***************************************************************************