source: trunk/dll/notify.c@ 433

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

Validate WinCreateWindow

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.3 KB
Line 
1
2/***********************************************************************
3
4 $Id: notify.c 377 2006-07-27 06:28:31Z root $
5
6 Notifications
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2006 Steven H.Levine
10
11 17 Jul 06 SHL Use Win_Error
12 22 Jul 06 SHL Check more run time errors
13
14***********************************************************************/
15
16#define INCL_DOS
17#define INCL_WIN
18#define INCL_GPI
19#include <os2.h>
20
21#include <stdarg.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <ctype.h>
26#include <time.h>
27#include <stddef.h>
28
29#include "fm3dll.h"
30#include "fm3dlg.h"
31#include "fm3str.h"
32
33#pragma data_seg(DATA1)
34
35static PSZ pszSrcFile = __FILE__;
36
37#pragma alloc_text(NOTIFY,Notify,NotifyWndProc,StartNotify)
38#pragma alloc_text(NOTIFY,NotifyThread,NotifyError)
39#pragma alloc_text(NOTIFY2,AddNote,NoteThread,NoteWndProc)
40#pragma alloc_text(NOTIFY3,StartNotes,EndNote,HideNote,ShowNote)
41
42static HWND hwndNotify;
43
44MRESULT EXPENTRY NotifyWndProc (HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
45{
46 static ULONG showing = 0;
47
48 switch(msg) {
49 case WM_CREATE:
50 showing++;
51 {
52 MRESULT rc;
53
54 rc = PFNWPStatic(hwnd,msg,mp1,mp2);
55 if(!WinStartTimer(WinQueryAnchorBlock(hwnd),
56 hwnd,
57 ID_TIMER2,
58 5000)) {
59 Win_Error(hwnd,hwnd,pszSrcFile,__LINE__,"WinStartTimer");
60 WinDestroyWindow(hwnd);
61 }
62 else {
63
64 RGB2 rgb2F,rgb2;
65
66 memset(&rgb2F,0,sizeof(RGB2));
67 rgb2F.bRed = 65;
68 rgb2.bRed = rgb2.bGreen = rgb2.bBlue = 255;
69 rgb2.fcOptions = 0;
70 SetPresParams(hwnd,&rgb2,&rgb2F,&rgb2,GetPString(IDS_8HELVTEXT));
71 if(hwndMain) {
72 if(hwndStatus)
73 WinShowWindow(hwndStatus,FALSE);
74 if(hwndStatus2)
75 WinShowWindow(hwndStatus2,FALSE);
76 }
77 PostMsg(hwnd,UM_SETUP,MPVOID,MPVOID);
78 }
79 return rc;
80 }
81
82 case UM_SETUP:
83 WinSetWindowPos(hwnd,HWND_TOP,0,0,0,0,SWP_ZORDER | SWP_SHOW);
84 WinInvalidateRect(hwnd,NULL,FALSE);
85 return 0;
86
87 case WM_SETFOCUS:
88 if(mp2)
89 PostMsg(hwnd,UM_REPLACEFOCUS,mp1,MPVOID);
90 break;
91
92 case UM_REPLACEFOCUS:
93 if(mp1)
94 WinSetFocus(HWND_DESKTOP,(HWND)mp1);
95 PostMsg(hwnd,UM_SETUP,MPVOID,MPVOID);
96 return 0;
97
98 case WM_PAINT:
99 {
100 MRESULT mr;
101 HPS hps;
102 SWP swp;
103 POINTL ptl;
104
105 mr = PFNWPStatic(hwnd,msg,mp1,mp2);
106 hps = WinGetPS(hwnd);
107 if(hps) {
108 if(WinQueryWindowPos(hwnd,&swp)) {
109 ptl.x = 0;
110 ptl.y = 0;
111 GpiMove(hps,&ptl);
112 GpiSetColor(hps,CLR_RED);
113 ptl.x = swp.cx - 1;
114 ptl.y = swp.cy - 1;
115 GpiBox(hps,DRO_OUTLINE,&ptl,2,2);
116 }
117 WinReleasePS(hwnd);
118 }
119 return mr;
120 }
121
122 case WM_BUTTON1DOWN:
123 case WM_BUTTON2DOWN:
124 case WM_BUTTON3DOWN:
125 case WM_TIMER:
126 case WM_CLOSE:
127 WinStopTimer(WinQueryAnchorBlock(hwnd),hwnd,ID_TIMER2);
128 WinDestroyWindow(hwnd);
129 return 0;
130
131 case WM_DESTROY:
132 showing--;
133 if(!showing && hwndMain) {
134 if(hwndStatus)
135 WinShowWindow(hwndStatus,TRUE);
136 if(hwndStatus2)
137 WinShowWindow(hwndStatus2,TRUE);
138 }
139 break;
140 }
141 return PFNWPStatic(hwnd,msg,mp1,mp2);
142}
143
144
145HWND DoNotify (char *str)
146{
147 char *p;
148 HWND hwnd = (HWND)0,hwndP;
149 LONG x,y,cx,cy;
150 SWP swp,swpS,swpS2;
151 static USHORT id = NOTE_FRAME;
152
153 if(str && *str) {
154 /* figure out what size the window should be and where it should be */
155 hwndP = (hwndMain) ? WinQueryWindow(hwndMain,QW_PARENT) : HWND_DESKTOP;
156 WinQueryWindowPos(hwndP,&swp);
157 if(hwndStatus)
158 WinQueryWindowPos(hwndStatus,&swpS);
159 if(hwndStatus2)
160 WinQueryWindowPos(hwndStatus2,&swpS2);
161 x = (hwndMain) ? ((hwndStatus) ? swpS.x - 1:
162 WinQuerySysValue(HWND_DESKTOP,SV_CXSIZEBORDER)) : 0;
163 y = (hwndMain) ? ((hwndStatus) ? swpS.y - 1:
164 WinQuerySysValue(HWND_DESKTOP,SV_CYSIZEBORDER)) : 0;
165 if(hwndMain && hwndStatus) {
166 if(hwndStatus2)
167 cx = swpS2.cx + swpS.cx + 8;
168 else
169 cx = swpS.cx + 6;
170 }
171 else
172 cx = (swp.cx - ((x * 2) + 4));
173 cy = (hwndMain) ? ((hwndStatus) ? swpS.cy + 2 : 28) : 28;
174
175 /* pretty-up the note by putting on a leading space */
176 if(*str != ' ') {
177 p = xmalloc(strlen(str) + 2,pszSrcFile,__LINE__);
178 if(!p)
179 p = str;
180 else {
181 strcpy(p + 1,str);
182 *p = ' ';
183 }
184 }
185 else
186 p = str;
187
188 hwnd = WinCreateWindow(hwndP,
189 GetPString(IDS_WCERRORWND),
190 p,
191 SS_TEXT | DT_LEFT | DT_VCENTER | WS_VISIBLE,
192 x,
193 y,
194 cx,
195 cy,
196 hwndP,
197 HWND_TOP,
198 id++,
199 NULL,
200 NULL);
201 if (!hwndP)
202 Win_Error2(hwndP,hwndP,pszSrcFile,__LINE__,IDS_WINCREATEWINDOW);
203
204 if(p != str)
205 free(p);
206 if(id > NOTE_MAX)
207 id = NOTE_FRAME;
208 }
209
210 AddNote(str);
211
212 return hwnd;
213}
214
215
216HWND Notify (char *str)
217{
218 return (HWND)WinSendMsg(MainObjectHwnd,UM_NOTIFY,MPFROMP(str),MPVOID);
219}
220
221
222VOID NotifyError (CHAR *filename,APIRET status)
223{
224 CHAR errortext[512];
225
226 if(!filename)
227 return;
228 sprintf(errortext,
229 GetPString(IDS_ERRORACCESSTEXT),
230 status,
231 filename);
232 if(toupper(*filename) > 'B') {
233 if(status == 21)
234 strcat(errortext,GetPString(IDS_EMPTYREMOVETEXT));
235 else if(status == 27)
236 strcat(errortext, GetPString(IDS_CDMUSICTEXT));
237 else if(status == 19)
238 strcat(errortext,GetPString(IDS_WRITEPROTECTTEXT));
239 else if(status == 108)
240 strcat(errortext,GetPString(IDS_DRIVELOCKEDTEXT));
241 }
242 else {
243 if(status == 21)
244 strcat(errortext,GetPString(IDS_EMPTYFLOPPYTEXT));
245 else if(status == 27)
246 strcat(errortext,GetPString(IDS_UNFORMATEDTEXT));
247 else if(status == 107)
248 sprintf(&errortext[strlen(errortext)],
249 GetPString(IDS_PHANTOMTEXT),
250 toupper(*filename));
251 else if(status == 19)
252 strcat(errortext,GetPString(IDS_DISKWRITEPROTEXTTEXT));
253 else if(status == 108)
254 strcat(errortext,GetPString(IDS_DISKLOCKEDTEXT));
255 }
256 DosBeep(250,10);
257 DosBeep(500,10);
258 DosBeep(250,10);
259 DosBeep(500,10);
260 Notify(errortext);
261}
262
263
264MRESULT EXPENTRY NoteWndProc (HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
265{
266 static HPOINTER hptrIcon = (HPOINTER)0;
267
268 switch(msg) {
269 case WM_INITDLG:
270 if(hwndNotify != (HWND)0) {
271 if(mp2) {
272 WinSendDlgItemMsg(hwndNotify,
273 NOTE_LISTBOX,
274 LM_INSERTITEM,
275 MPFROM2SHORT(LIT_END,0),
276 mp2);
277 PostMsg(hwndNotify,
278 UM_NOTIFY,
279 MPVOID,
280 MPVOID);
281 free((CHAR *)mp2);
282 }
283 WinDismissDlg(hwnd,0);
284 break;
285 }
286 hwndNotify = hwnd;
287 fThreadNotes = FALSE;
288 {
289 BOOL dummy = TRUE;
290
291 PrfWriteProfileData(fmprof,
292 FM3Str,
293 "ThreadNotes",
294 &dummy,
295 sizeof(BOOL));
296 }
297 if(mp2) {
298 WinSendDlgItemMsg(hwnd,
299 NOTE_LISTBOX,
300 LM_INSERTITEM,
301 MPFROM2SHORT(LIT_END,0),
302 mp2);
303 free((CHAR *)mp2);
304 }
305 {
306 HWND hwndActive;
307
308 hwndActive = WinQueryActiveWindow(HWND_DESKTOP);
309 PostMsg(hwnd,
310 UM_FOCUSME,
311 MPFROMLONG(hwndActive),
312 MPVOID);
313 }
314 hptrIcon = WinLoadPointer(HWND_DESKTOP,
315 FM3ModHandle,
316 NOTE_FRAME);
317 if(hptrIcon)
318 WinDefDlgProc(hwnd,
319 WM_SETICON,
320 MPFROMLONG(hptrIcon),
321 MPFROMLONG(0L));
322 break;
323
324 case UM_FOCUSME:
325 {
326 ULONG size = sizeof(SWP),
327 fl = SWP_ZORDER | SWP_FOCUSDEACTIVATE | SWP_SHOW;
328 SWP swp;
329
330 if(PrfQueryProfileData(fmprof,
331 FM3Str,
332 "NoteWndSwp",
333 (PVOID)&swp,
334 &size)) {
335 if(swp.fl & (SWP_HIDE | SWP_MINIMIZE)) {
336 fl |= SWP_MINIMIZE;
337 fl &= (~SWP_SHOW);
338 }
339 else
340 fl |= (SWP_MOVE | SWP_SIZE);
341 }
342 WinSetWindowPos(hwnd,
343 HWND_BOTTOM,
344 swp.x,
345 swp.y,
346 swp.cx,
347 swp.cy,
348 fl);
349 if(fl & SWP_MINIMIZE) {
350 WinSetWindowUShort(hwnd,QWS_XRESTORE,(USHORT)swp.x);
351 WinSetWindowUShort(hwnd,QWS_CXRESTORE,(USHORT)swp.cx);
352 WinSetWindowUShort(hwnd,QWS_YRESTORE,(USHORT)swp.y);
353 WinSetWindowUShort(hwnd,QWS_CYRESTORE,(USHORT)swp.cy);
354 }
355 }
356 if(mp1)
357 WinSetActiveWindow(HWND_DESKTOP,(HWND)mp1);
358 return 0;
359
360 case UM_STRETCH:
361 {
362 SWP swp;
363 LONG titl,szbx,szby;
364
365 WinQueryWindowPos(hwnd,&swp);
366 if(!(swp.fl & (SWP_MINIMIZE | SWP_HIDE))) {
367 szbx = SysVal(SV_CXSIZEBORDER);
368 szby = SysVal(SV_CYSIZEBORDER);
369 titl = SysVal(SV_CYTITLEBAR);
370 WinSetWindowPos(WinWindowFromID(hwnd,NOTE_LISTBOX),
371 HWND_TOP,
372 szbx,
373 szby,
374 swp.cx - (szbx * 2L),
375 (swp.cy - titl) - (szby * 2L),
376 SWP_MOVE | SWP_SIZE);
377 }
378 if(!(swp.fl & SWP_MAXIMIZE)) {
379 if(swp.fl & (SWP_MINIMIZE | SWP_HIDE)) {
380 swp.x = WinQueryWindowUShort(hwnd,QWS_XRESTORE);
381 swp.y = WinQueryWindowUShort(hwnd,QWS_YRESTORE);
382 swp.cx = WinQueryWindowUShort(hwnd,QWS_CXRESTORE);
383 swp.cy = WinQueryWindowUShort(hwnd,QWS_CYRESTORE);
384 }
385 PrfWriteProfileData(fmprof,
386 FM3Str,
387 "NoteWndSwp",
388 (PVOID)&swp,
389 sizeof(SWP));
390 }
391 }
392 return 0;
393
394 case WM_ADJUSTWINDOWPOS:
395 PostMsg(hwnd,
396 UM_STRETCH,
397 MPVOID,
398 MPVOID);
399 break;
400
401 case UM_CONTAINER_FILLED:
402 {
403 SHORT x,y;
404
405 x = (SHORT)WinSendDlgItemMsg(hwnd,
406 NOTE_LISTBOX,
407 LM_QUERYITEMCOUNT,
408 MPVOID,
409 MPVOID);
410 if(x > 60) {
411 for(y = 0;y < x - 50;y++)
412 WinSendDlgItemMsg(hwnd,
413 NOTE_LISTBOX,
414 LM_DELETEITEM,
415 MPFROMSHORT(y),
416 MPVOID);
417 }
418 }
419 return 0;
420
421 case UM_NOTIFY:
422 {
423 SHORT x;
424
425 x = (SHORT)WinSendDlgItemMsg(hwnd,
426 NOTE_LISTBOX,
427 LM_QUERYITEMCOUNT,
428 MPVOID,
429 MPVOID);
430 if(x > 0)
431 WinSendDlgItemMsg(hwnd,
432 NOTE_LISTBOX,
433 LM_SETTOPINDEX,
434 MPFROMSHORT(x),
435 MPVOID);
436 }
437 return 0;
438
439 case UM_SHOWME:
440 WinSetWindowPos(hwnd,
441 HWND_TOP,
442 0,
443 0,
444 0,
445 0,
446 SWP_SHOW | SWP_RESTORE | SWP_ZORDER | SWP_ACTIVATE);
447 return 0;
448
449 case WM_COMMAND:
450 return 0;
451
452 case WM_CLOSE:
453 WinDismissDlg(hwnd,0);
454 return 0;
455
456 case WM_DESTROY:
457 if(hwndNotify == hwnd) {
458 fThreadNotes = FALSE;
459 PrfWriteProfileData(fmprof,
460 FM3Str,
461 "ThreadNotes",
462 &fThreadNotes,
463 sizeof(BOOL));
464 hwndNotify = (HWND)0;
465 }
466 if(hptrIcon)
467 WinDestroyPointer(hptrIcon);
468 if(!PostMsg((HWND)0,
469 WM_QUIT,
470 MPVOID,
471 MPVOID))
472 WinSendMsg((HWND)0,
473 WM_QUIT,
474 MPVOID,
475 MPVOID);
476 break;
477 }
478 return WinDefDlgProc(hwnd,msg,mp1,mp2);
479}
480
481
482VOID NoteThread (VOID *args)
483{
484 HAB hab2;
485 HMQ hmq2;
486
487 hab2 = WinInitialize(0);
488 if(hab2) {
489 hmq2 = WinCreateMsgQueue(hab2,0);
490 if(hmq2) {
491 if(!hwndNotify)
492 WinDlgBox(HWND_DESKTOP,
493 HWND_DESKTOP,
494 NoteWndProc,
495 FM3ModHandle,
496 NOTE_FRAME,
497 (CHAR *)args);
498 WinDestroyMsgQueue(hmq2);
499 }
500 WinTerminate(hab2);
501 }
502}
503
504
505VOID StartNotes (CHAR *note)
506{
507 if (!hwndNotify) {
508 if (_beginthread(NoteThread,NULL,65536,(PVOID)note) == -1)
509 Runtime_Error(pszSrcFile, __LINE__, GetPString(IDS_COULDNTSTARTTHREADTEXT));
510 }
511}
512
513
514BOOL AddNote (CHAR *note)
515{
516 CHAR *s,*p;
517 BOOL once = FALSE,ret = FALSE;
518
519 if((fThreadNotes || hwndNotify) && note && *note) {
520 p = note;
521 while(*p == ' ')
522 p++;
523 if(*p) {
524 if(!hwndNotify) {
525 fThreadNotes = FALSE;
526 StartNotes(NULL);
527 if(!hwndNotify)
528 DosSleep(33L);
529 if(!hwndNotify)
530 DosSleep(33L);
531 if(!hwndNotify)
532 DosSleep(33L);
533 }
534 if(hwndNotify) {
535 s = xmalloc(strlen(p) + 14, pszSrcFile, __LINE__);
536 if(s) {
537 sprintf(s,"%08lx %s",_threadid,p);
538 while(!once) {
539 if((SHORT)WinSendDlgItemMsg(hwndNotify,
540 NOTE_LISTBOX,
541 LM_INSERTITEM,
542 MPFROM2SHORT(LIT_END,0),
543 MPFROMP(s)) >= 0) {
544 ret = TRUE;
545 PostMsg(hwndNotify,
546 UM_NOTIFY,
547 MPVOID,
548 MPVOID);
549 break;
550 }
551 PostMsg(hwndNotify,
552 UM_CONTAINER_FILLED,
553 MPVOID,
554 MPVOID);
555 once = TRUE;
556 }
557 }
558 free(s);
559 }
560 }
561 }
562 return ret;
563}
564
565
566VOID EndNote (VOID)
567{
568 if(hwndNotify)
569 if(!PostMsg(hwndNotify,
570 WM_CLOSE,
571 MPVOID,
572 MPVOID))
573 WinSendMsg(hwndNotify,
574 WM_CLOSE,
575 MPVOID,
576 MPVOID);
577}
578
579
580VOID ShowNote (VOID)
581{
582 if(!hwndNotify)
583 StartNotes(NULL);
584 if(!hwndNotify)
585 DosSleep(33L);
586 if(!hwndNotify)
587 DosSleep(33L);
588 if(!hwndNotify)
589 DosSleep(33L);
590 if(hwndNotify)
591 PostMsg(hwndNotify,
592 UM_SHOWME,
593 MPVOID,
594 MPVOID);
595}
596
597
598VOID HideNote (VOID)
599{
600 if(hwndNotify)
601 WinSetWindowPos(hwndNotify,
602 HWND_BOTTOM,
603 0,
604 0,
605 0,
606 0,
607 SWP_MINIMIZE | SWP_ZORDER | SWP_FOCUSDEACTIVATE);
608}
Note: See TracBrowser for help on using the repository browser.