source: trunk/dll/winlist.c@ 1036

Last change on this file since 1036 was 1009, checked in by Steven Levine, 17 years ago

Add xfree xstrdup Fortify support
Add MT capable Fortify scope logic

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