source: trunk/dll/winlist.c@ 907

Last change on this file since 907 was 907, checked in by Steven Levine, 18 years ago

Avoid out of memory traps in Compare Directories
Rework Compare Directories progress display for 2 second update rate
Start refactoring to reduce dependence on fm3dll.h
Add timer services (IsITimerExpired etc.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1
2/***********************************************************************
3
4 $Id: winlist.c 907 2008-01-06 07:26:17Z stevenhl $
5
6 Window List Dialog
7
8 Copyright (c) 1993-97 M. Kimes
9 Copyright (c) 2005, 2006 Steven H.Levine
10
11 23 May 05 SHL Use QWL_USER
12 22 Jul 06 SHL Check more run time errors
13 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
14
15***********************************************************************/
16
17#include <stdlib.h>
18#include <string.h>
19
20#define INCL_DOS
21#define INCL_WIN
22
23#include "fm3dlg.h"
24#include "fm3dll.h"
25
26#pragma data_seg(DATA1)
27
28static PSZ pszSrcFile = __FILE__;
29
30
31MRESULT EXPENTRY WinListDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
32{
33 SHORT sSelect;
34
35 static HWND Me = (HWND) 0;
36
37 switch (msg) {
38 case WM_INITDLG:
39 if (Me || !mp2) {
40 if (Me)
41 PostMsg(Me, UM_FOCUSME, MPVOID, MPVOID);
42 WinDismissDlg(hwnd, 0);
43 }
44 else {
45
46 HENUM henum;
47 HWND hwndChild;
48 USHORT id;
49 CHAR wtext[CCHMAXPATH + 1];
50
51 Me = hwnd;
52 WinSetWindowULong(hwnd, QWL_USER, *(HWND *) mp2);
53 henum = WinBeginEnumWindows(*(HWND *) mp2);
54 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
55 id = WinQueryWindowUShort(hwndChild, QWS_ID);
56 if (!id)
57 continue;
58 *wtext = ' ';
59 WinQueryWindowText(hwndChild, CCHMAXPATH, wtext + 1);
60 wtext[CCHMAXPATH] = 0;
61 sSelect =
62 (SHORT) WinSendDlgItemMsg(hwnd, WLIST_LISTBOX, LM_INSERTITEM,
63 MPFROM2SHORT(LIT_SORTASCENDING, 0),
64 MPFROMP(wtext));
65 if (sSelect >= 0)
66 WinSendDlgItemMsg(hwnd, WLIST_LISTBOX, LM_SETITEMHANDLE,
67 MPFROM2SHORT(sSelect, 0),
68 MPFROMLONG((ULONG) hwndChild));
69 }
70 WinEndEnumWindows(henum);
71
72 {
73 PSWBLOCK pswb;
74 ULONG ulSize, ulcEntries;
75 register INT i, y;
76
77 /* Get the switch list information */
78 ulcEntries = WinQuerySwitchList(0, NULL, 0);
79 ulSize = sizeof(SWBLOCK) + sizeof(HSWITCH) + (ulcEntries + 4) *
80 (LONG) sizeof(SWENTRY);
81 /* Allocate memory for list */
82 pswb = xmalloc((unsigned)ulSize, pszSrcFile, __LINE__);
83 if (pswb) {
84 /* Put the info in the list */
85 ulcEntries = WinQuerySwitchList(0, pswb, ulSize - sizeof(SWENTRY));
86 /* do the dirty deed */
87 y = 0;
88 for (i = 0; i < pswb->cswentry; i++) {
89 if (pswb->aswentry[i].swctl.uchVisibility == SWL_VISIBLE &&
90 pswb->aswentry[i].swctl.fbJump == SWL_JUMPABLE &&
91 ((pswb->aswentry[i].swctl.idProcess == mypid &&
92 (strnicmp(pswb->aswentry[i].swctl.szSwtitle,
93 "FM/2", 4))) ||
94 !strnicmp(pswb->aswentry[i].swctl.szSwtitle, "AV/2", 4) ||
95 !stricmp(pswb->aswentry[i].swctl.szSwtitle, "File Manager/2")
96 || !stricmp(pswb->aswentry[i].swctl.szSwtitle, "Collector")
97 || !strnicmp(pswb->aswentry[i].swctl.szSwtitle, "VTree", 5)
98 || !strnicmp(pswb->aswentry[i].swctl.szSwtitle, "VDir", 4)
99 || (!strnicmp(pswb->aswentry[i].swctl.szSwtitle, FM2Str, 4)
100 && strnicmp(pswb->aswentry[i].swctl.szSwtitle, "FM/2",
101 4)))) {
102 *wtext = '*';
103 wtext[1] = 0;
104 strcat(wtext, pswb->aswentry[i].swctl.szSwtitle);
105 wtext[CCHMAXPATH] = 0;
106 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
107 WLIST_LISTBOX,
108 LM_INSERTITEM,
109 MPFROM2SHORT
110 (LIT_SORTASCENDING, 0),
111 MPFROMP(wtext));
112 if (sSelect >= 0)
113 WinSendDlgItemMsg(hwnd,
114 WLIST_LISTBOX,
115 LM_SETITEMHANDLE,
116 MPFROM2SHORT(sSelect, 0),
117 MPFROMLONG(pswb->aswentry[i].swctl.hwnd));
118 }
119 y++;
120 }
121 free(pswb);
122 DosPostEventSem(CompactSem);
123 }
124 }
125
126 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
127 WLIST_LISTBOX,
128 LM_QUERYITEMCOUNT, MPVOID, MPVOID);
129 if (sSelect <= 0)
130 WinDismissDlg(hwnd, 0);
131 }
132 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
133 break;
134
135 case UM_FOCUSME:
136 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
137 return 0;
138
139 case UM_SETUP:
140 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
141 return 0;
142
143 case UM_SETUP2:
144 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID);
145 return 0;
146
147 case UM_SETUP3:
148 WinSetActiveWindow(HWND_DESKTOP, hwnd);
149 return 0;
150
151 case WM_CONTROL:
152 switch (SHORT1FROMMP(mp1)) {
153 case WLIST_LISTBOX:
154 switch (SHORT2FROMMP(mp1)) {
155 case LN_ENTER:
156 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
157 break;
158 }
159 break;
160 }
161 return 0;
162
163 case WM_COMMAND:
164 switch (SHORT1FROMMP(mp1)) {
165 case WLIST_MINIMIZE:
166 case WLIST_CLOSE:
167 case DID_OK:
168 {
169 HWND hwndActive = (HWND) WinQueryWindowULong(hwnd, QWL_USER);
170
171 hwndActive = WinQueryActiveWindow(hwndActive);
172 sSelect = (SHORT) WinSendDlgItemMsg(hwnd,
173 WLIST_LISTBOX,
174 LM_QUERYSELECTION,
175 MPFROM2SHORT(LIT_FIRST, 0),
176 MPVOID);
177 while (sSelect >= 0) {
178
179 HWND HwndC;
180
181 HwndC = (HWND) WinSendDlgItemMsg(hwnd,
182 WLIST_LISTBOX,
183 LM_QUERYITEMHANDLE,
184 MPFROM2SHORT(sSelect, 0), MPVOID);
185 if (HwndC) {
186
187 SWP swp;
188
189 WinQueryWindowPos(HwndC, &swp);
190 if (SHORT1FROMMP(mp1) == DID_OK) {
191 if (!(swp.fl & SWP_MINIMIZE) && (swp.cx == 0 || swp.cy == 0)) {
192 GetNextWindowPos((HWND) WinQueryWindowULong(hwnd, QWL_USER),
193 &swp, NULL, NULL);
194 WinSetWindowPos(HwndC, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
195 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ZORDER |
196 SWP_ACTIVATE | SWP_FOCUSACTIVATE);
197 }
198 else
199 WinSetWindowPos(HwndC, HWND_TOP, 0, 0, 0, 0,
200 SWP_RESTORE | SWP_SHOW | SWP_ZORDER |
201 SWP_ACTIVATE | SWP_FOCUSACTIVATE);
202 }
203 else if (SHORT1FROMMP(mp1) == WLIST_MINIMIZE) {
204 WinSetWindowPos(HwndC, HWND_BOTTOM, 0, 0, 0, 0,
205 SWP_MINIMIZE | SWP_DEACTIVATE |
206 SWP_FOCUSDEACTIVATE | SWP_ZORDER);
207 if (hwndActive == HwndC) {
208 WinSetWindowPos(WinWindowFromID(WinQueryWindow(hwndActive,
209 QW_PARENT),
210 TREE_FRAME), HWND_TOP, 0, 0,
211 0, 0,
212 SWP_SHOW | SWP_RESTORE | SWP_ACTIVATE |
213 SWP_FOCUSACTIVATE | SWP_ZORDER);
214 hwndActive = (HWND) 0;
215 }
216 }
217 else if (WinQueryWindowUShort(HwndC, QWS_ID) != TREE_FRAME)
218 PostMsg(HwndC, WM_CLOSE, MPVOID, MPVOID);
219 }
220 sSelect = (SHORT) WinSendDlgItemMsg(hwnd, WLIST_LISTBOX,
221 LM_QUERYSELECTION,
222 MPFROM2SHORT(sSelect, 0),
223 MPVOID);
224 }
225 }
226 WinDismissDlg(hwnd, 0);
227 break;
228
229 case IDM_HELP:
230 if (hwndHelp)
231 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
232 MPFROM2SHORT(HELP_WINLIST, 0), MPFROMSHORT(HM_RESOURCEID));
233 break;
234
235 case DID_CANCEL:
236 WinDismissDlg(hwnd, 0);
237 break;
238 }
239 return 0;
240
241 case WM_DESTROY:
242 if (Me == hwnd)
243 Me = (HWND) 0;
244 else
245 WinSetWindowPos(Me, HWND_TOP, 0, 0, 0, 0,
246 SWP_SHOW | SWP_RESTORE | SWP_ZORDER | SWP_ACTIVATE);
247 break;
248 }
249 return WinDefDlgProc(hwnd, msg, mp1, mp2);
250}
251
252VOID WindowList(HWND hwnd)
253{
254 WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, WinListDlgProc, FM3ModHandle,
255 WLIST_FRAME, MPFROMP(&hwnd));
256}
257
258#pragma alloc_text(WINLIST,WindowList,WinListDlgProc)
Note: See TracBrowser for help on using the repository browser.