-
Notifications
You must be signed in to change notification settings - Fork 5
/
progman.c
434 lines (365 loc) · 10.1 KB
/
progman.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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
/* * * * * * * *\
PROGMAN.C -
Copyright (c) 1991, Microsoft Corporation
DESCRIPTION -
This file is for support of program manager under NT Windows.
This file is/was ported from progman.c (program manager).
MODIFICATION HISTORY -
Initial Version: x/x/90 Author Unknown, since he didn't feel like commenting the code...
NT 32b Version: 1/16/91 Jeff Pack, Intitial port to begin.
NT x86_64 Ver: 3/9/22 freedom, cleaned up and 64-bitted
\* * * * * * * */
// Includes
#include "progman.h"
#include "pmanfunc.h"
// Variables
BOOL UserIsAdmin = FALSE;
BOOL AccessToCommonGroups = FALSE;
BOOL bLoadIt = FALSE;
BOOL bMinOnRun = FALSE;
BOOL bArranging = FALSE;
BOOL bAutoArrange = FALSE;
BOOL bAutoArranging = FALSE;
BOOL bExitWindows = FALSE;
BOOL bScrolling = FALSE;
BOOL bSaveSettings = TRUE;
BOOL bLoadEvil = FALSE;
BOOL bMove = FALSE;
BOOL bInDDE = FALSE;
BOOL bIconTitleWrap = TRUE;
BOOL fInExec = FALSE;
BOOL fNoRun = FALSE;
BOOL fNoClose = FALSE;
BOOL fNoSave = FALSE;
BOOL fNoFileMenu = FALSE;
BOOL fExiting = FALSE;
BOOL fLowMemErrYet = FALSE;
BOOL fErrorOnExtract = FALSE;
BOOL bFrameSysMenu = FALSE;
TCHAR szNULL[] = TEXT("");
TCHAR szProgman[] = TEXT("progman");
//
// Program Manager's Settings keys
//
TCHAR szWindow[] = TEXT("Window");
TCHAR szOrder[] = TEXT("UNICODE Order");
TCHAR szAnsiOrder[] = TEXT("Order");
TCHAR szStartup[] = TEXT("startup");
TCHAR szAutoArrange[] = TEXT("AutoArrange");
TCHAR szSaveSettings[] = TEXT("SaveSettings");
TCHAR szMinOnRun[] = TEXT("MinOnRun");
TCHAR szFocusOnCommonGroup[] = TEXT("FocusOnCommonGroup");
TCHAR szProgmanHelp[] = TEXT("PROGMAN.HLP");
TCHAR szTitle[MAXTITLELEN + 1];
TCHAR szMessage[MAXMESSAGELEN+1];
TCHAR szNameField[MAX_PATH];
TCHAR szPathField[MAX_PATH];
TCHAR szDirField[MAX_PATH];
TCHAR szIconPath[MAX_PATH];
TCHAR szOriginalDirectory[MAX_PATH];
TCHAR szWindowsDirectory[MAX_PATH];
TCHAR szOOMExitMsg[64];
TCHAR szOOMExitTitle[32];
/* for Program Groups in Registry */
HKEY hkeyProgramManager = NULL; // progman.ini key
HKEY hkeyPMSettings = NULL; // keys corresponding to progman.ini sections
HKEY hkeyPMRestrict = NULL;
HKEY hkeyPMGroups = NULL;
HKEY hkeyPMCommonGroups = NULL;
TCHAR szAnsiProgramGroups[] = TEXT("Program Groups"); // registry key for groups
HKEY hkeyProgramGroups = NULL;
HKEY hkeyAnsiProgramGroups = NULL;
HKEY hkeyCommonGroups = NULL;
PSECURITY_ATTRIBUTES pSecurityAttributes = NULL;
PSECURITY_ATTRIBUTES pAdminSecAttr = NULL;
HANDLE hAccel;
HINSTANCE hAppInstance;
HANDLE hCommdlg = NULL;
HICON hDlgIcon = NULL;
HICON hItemIcon = NULL;
HICON hGroupIcon = NULL;
HICON hCommonGrpIcon = NULL;
HICON hProgmanIcon = NULL;
HICON hIconGlobal = NULL;
HFONT hFontTitle = NULL;
HWND hwndProgman = NULL;
HWND hwndMDIClient = NULL;
HBRUSH hbrWorkspace = NULL;
WORD wPendingHotKey = 0;
DWORD dwDDEAppId = 0;
//HANDLE hPendingWindow = 0;
DWORD dwEditLevel = 0;
WORD wLockError = 0;
UINT uiActivateShellWindowMessage = 0;
UINT uiConsoleWindowMessage = 0;
UINT uiSaveSettingsMessage = 0; // for upedit.exe: User Profile Editor
int nGroups = 0;
int dyBorder;
int iDlgIconId;
int iDlgIconIndex;
int cxIconSpace;
int cyIconSpace;
int cxOffset;
int cyOffset;
int cxArrange;
int cyArrange;
int cxIcon;
int cyIcon;
PGROUP pFirstGroup = NULL;
PGROUP pCurrentGroup = NULL;
PGROUP pActiveGroup = NULL;
PGROUP *pLastGroup = &pFirstGroup;
PGROUP pExecingGroup = NULL;
PITEM pExecingItem = NULL;
RECT rcDrag = { 0,0,0,0 };
HWND hwndDrag = 0;
WORD wNewSelection;
UINT uiHelpMessage; // stuff for help
UINT uiBrowseMessage; // stuff for help
WORD wMenuID = 0;
HANDLE hSaveMenuHandle = 0L; /*Save hMenu into one variable*/
WORD wSaveFlags = 0; /*Save flags into another*/
HANDLE hSaveMenuHandleAroundSendMessage; /*Save hMenu into one variable*/
WORD wSaveFlagsAroundSendMessage; /*Save flags into another*/
WORD wSaveMenuIDAroundSendMessage;
DWORD dwContext = 0L;
HHOOK hhkMsgFilter = NULL;
BOOL bUseANSIGroups = FALSE;
extern BOOL bInNtSetup;
extern VOID TMMain(void);
HANDLE hTMThread = NULL;
BOOL FAR PASCAL CheckHotKey(WPARAM wParam, LPARAM lParam);
/*** main -- Program entry point (was WinMain).
*
*
*
* int APIENTRY main(int argc, char *argv[], char *envp[])
*
* ENTRY - int argc - argument count.
* char *argv[] - argument list.
* char *envp[] - environment.
*
* EXIT - TRUE if success, FALSE if not.
* SYNOPSIS -
* WARNINGS -
* EFFECTS -
*
*/
int __cdecl wmain(
int argc,
wchar_t *argv[],
wchar_t *envp[])
{
MSG msg;
HANDLE hInst;
LPTSTR lpszCmdLine = NULL;
int nCmdShow = SW_SHOWNORMAL;
DWORD dwThreadID;
DWORD dwEvent;
hInst = GetModuleHandle(NULL);
if (argc > 1) {
//
// Get the command line, sans program name.
//
lpszCmdLine = SkipProgramName(GetCommandLine());
}
/*
* Initialize the window classes and other junk.
*/
if (!AppInit(hInst, lpszCmdLine, nCmdShow)) {
return FALSE;
}
//
// Don't start the taskman thread if progman is started from NTSETUP.
//
if (!bInNtSetup) {
HKEY hkeyWinlogon;
DWORD dwType;
TCHAR szBuffer[MAX_PATH];
DWORD cbBuffer;
BOOL bUseDefaultTaskman = TRUE;
//
// Check if a replacement taskman exits. First open the Taskman
// entry in winlogon's settings.
//
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"),
0,
KEY_READ,
&hkeyWinlogon) == ERROR_SUCCESS) {
//
// Query the taskman name.
//
cbBuffer = sizeof(szBuffer);
if (RegQueryValueEx(hkeyWinlogon,
TEXT("Taskman"),
0,
&dwType,
(LPBYTE)szBuffer,
&cbBuffer) == ERROR_SUCCESS) {
//
// The taskman entry exits. Confirm that it is not NULL.
//
if (szBuffer[0] != TEXT('\0')) {
//
// Try to spawn the taskman replacement. If
// the spawning succeeds, ExecProgram will return 0.
//
if (ExecProgram (szBuffer, NULL, NULL, FALSE,
0, 0, FALSE) == 0) {
bUseDefaultTaskman = FALSE;
}
}
}
//
// Close the registry key.
//
RegCloseKey (hkeyWinlogon);
}
//
// Check to see if we should spawn the default taskman.
//
if (bUseDefaultTaskman) {
hTMThread = CreateThread(NULL, (DWORD)0,
(LPTHREAD_START_ROUTINE)TMMain,
(LPVOID)NULL, 0, &dwThreadID);
}
}
//
// Messaging Loop.
//
while (TRUE) {
while (PeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) {
ExitProcess(0);
return (int)msg.wParam;
}
/*
* First test if this is a hot key.
*
*/
if (msg.message == WM_SYSKEYDOWN || msg.message == WM_KEYDOWN) {
if (CheckHotKey(msg.wParam, msg.lParam))
continue;
}
/*
* Since we use RETURN as an accelerator we have to manually
* restore ourselves when we see VK_RETURN and we are minimized.
*/
if (hwndProgman != NULL && msg.message == WM_SYSKEYDOWN && msg.wParam == VK_RETURN &&
IsIconic(hwndProgman)) {
ShowWindow(hwndProgman, SW_NORMAL);
} else {
if ((hwndMDIClient == NULL ||
!TranslateMDISysAccel(hwndMDIClient, &msg)) &&
(hwndProgman == NULL ||
!TranslateAccelerator(hwndProgman, hAccel, &msg))) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
dwEvent = MsgWaitForMultipleObjects(2, gahEvents, FALSE,
INFINITE, QS_ALLINPUT);
if (dwEvent < (WAIT_OBJECT_0 + 2)) {
HandleGroupKeyChange((dwEvent == (WAIT_OBJECT_0 + 1)));
}
}
return msg.wParam;
}
/*** MyMessageBox --
*
*
* int APIENTRY MyMessageBox(HWND hWnd, WORD idTitle, WORD idMessage, LPSTR lpsz, WORD wStyle)
*
* ENTRY - HWND hWnd
* WORD idTitle
* WORD idMessage
* LPSTR lpsz
* WORD wStyle
*
* EXIT - int xx - Looks like -1 is error, otherwise result.
*
* SYNOPSIS - ???
*
* WARNINGS -
* EFFECTS -
*
*/
int APIENTRY MyMessageBox(HWND hWnd, WORD idTitle, WORD idMessage, LPTSTR psz, WORD wStyle)
{
TCHAR szTempField[MAXMESSAGELEN];
int iMsgResult = NULL;
if (bInDDE){
return(1);
}
if (!LoadString(hAppInstance, idTitle, szTitle, CharSizeOf(szTitle))){
goto MessageBoxOOM;
}
if (idMessage < 32){
if (!LoadString(hAppInstance, IDS_UNKNOWNMSG, szTempField, CharSizeOf(szTempField))){
goto MessageBoxOOM;
}
wsprintf(szMessage, szTempField, idMessage);
}
else{
if (!LoadString(hAppInstance, idMessage, szTempField, CharSizeOf(szTempField)))
goto MessageBoxOOM;
if (psz)
wsprintf(szMessage, szTempField, (LPTSTR)psz);
else
lstrcpy(szMessage, szTempField);
}
if (hWnd){
hWnd = GetLastActivePopup(hWnd);
}
iMsgResult = MessageBox(hWnd, szMessage, szTitle, wStyle );
if (iMsgResult == -1){
MessageBoxOOM:
MessageBox(GetLastActivePopup(hwndProgman), szOOMExitMsg, szOOMExitTitle, MB_SYSTEMMODAL | MB_ICONHAND | MB_OK);
}
return(iMsgResult);
}
/*** MessageFilter --
*
*
* int APIENTRY MessageFilter(int nCode, WPARAM wParam, LPMSG lpMsg)
*
* ENTRY - int nCode
* WPARAM wParam
* WORD idMessage
* LPMSG lpMsg
*
* EXIT - int xx - Looks like 0 is error, otherwise 1 is success
*
* SYNOPSIS - ???
*
* WARNINGS -
* EFFECTS -
*
*/
LRESULT APIENTRY MessageFilter(int nCode, WPARAM wParam, LPARAM lParam)
{
LPMSG lpMsg = (LPMSG)lParam;
if (nCode < 0){
goto DefHook;
}
if (nCode == MSGF_MENU) {
if (lpMsg->message == WM_KEYDOWN && lpMsg->wParam == VK_F1) {
/* Window of menu we want help for is in loword of lParam.*/
PostMessage(hwndProgman, uiHelpMessage, MSGF_MENU, (LPARAM)lpMsg->hwnd);
return(1);
}
} else if (nCode == MSGF_DIALOGBOX) {
if (lpMsg->message == WM_KEYDOWN && lpMsg->wParam == VK_F1) {
/* Dialog box we want help for is in loword of lParam */
PostMessage(hwndProgman, uiHelpMessage, MSGF_DIALOGBOX, (LPARAM)lpMsg->hwnd);
return(1);
}
}
else {
DefHook:
return DefHookProc(nCode, wParam, lParam, &hhkMsgFilter);
}
return(0);
}