source: trunk/dll/winlist.c@ 433

Last change on this file since 433 was 331, checked in by root, 19 years ago

Check more run time errors

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