source: trunk/dll/notify.c@ 356

Last change on this file since 356 was 356, 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: 15.2 KB
Line 
1
2/***********************************************************************
3
4 $Id: notify.c 356 2006-07-26 19:58:37Z 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(p != str)
202 free(p);
203 if(id > NOTE_MAX)
204 id = NOTE_FRAME;
205 }
206
207 AddNote(str);
208
209 return hwnd;
210}
211
212
213HWND Notify (char *str)
214{
215 return (HWND)WinSendMsg(MainObjectHwnd,UM_NOTIFY,MPFROMP(str),MPVOID);
216}
217
218
219VOID NotifyError (CHAR *filename,APIRET status)
220{
221 CHAR errortext[512];
222
223 if(!filename)
224 return;
225 sprintf(errortext,
226 GetPString(IDS_ERRORACCESSTEXT),
227 status,
228 filename);
229 if(toupper(*filename) > 'B') {
230 if(status == 21)
231 strcat(errortext,GetPString(IDS_EMPTYREMOVETEXT));
232 else if(status == 27)
233 strcat(errortext, GetPString(IDS_CDMUSICTEXT));
234 else if(status == 19)
235 strcat(errortext,GetPString(IDS_WRITEPROTECTTEXT));
236 else if(status == 108)
237 strcat(errortext,GetPString(IDS_DRIVELOCKEDTEXT));
238 }
239 else {
240 if(status == 21)
241 strcat(errortext,GetPString(IDS_EMPTYFLOPPYTEXT));
242 else if(status == 27)
243 strcat(errortext,GetPString(IDS_UNFORMATEDTEXT));
244 else if(status == 107)
245 sprintf(&errortext[strlen(errortext)],
246 GetPString(IDS_PHANTOMTEXT),
247 toupper(*filename));
248 else if(status == 19)
249 strcat(errortext,GetPString(IDS_DISKWRITEPROTEXTTEXT));
250 else if(status == 108)
251 strcat(errortext,GetPString(IDS_DISKLOCKEDTEXT));
252 }
253 DosBeep(250,10);
254 DosBeep(500,10);
255 DosBeep(250,10);
256 DosBeep(500,10);
257 Notify(errortext);
258}
259
260
261MRESULT EXPENTRY NoteWndProc (HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
262{
263 static HPOINTER hptrIcon = (HPOINTER)0;
264
265 switch(msg) {
266 case WM_INITDLG:
267 if(hwndNotify != (HWND)0) {
268 if(mp2) {
269 WinSendDlgItemMsg(hwndNotify,
270 NOTE_LISTBOX,
271 LM_INSERTITEM,
272 MPFROM2SHORT(LIT_END,0),
273 mp2);
274 PostMsg(hwndNotify,
275 UM_NOTIFY,
276 MPVOID,
277 MPVOID);
278 free((CHAR *)mp2);
279 }
280 WinDismissDlg(hwnd,0);
281 break;
282 }
283 hwndNotify = hwnd;
284 fThreadNotes = FALSE;
285 {
286 BOOL dummy = TRUE;
287
288 PrfWriteProfileData(fmprof,
289 FM3Str,
290 "ThreadNotes",
291 &dummy,
292 sizeof(BOOL));
293 }
294 if(mp2) {
295 WinSendDlgItemMsg(hwnd,
296 NOTE_LISTBOX,
297 LM_INSERTITEM,
298 MPFROM2SHORT(LIT_END,0),
299 mp2);
300 free((CHAR *)mp2);
301 }
302 {
303 HWND hwndActive;
304
305 hwndActive = WinQueryActiveWindow(HWND_DESKTOP);
306 PostMsg(hwnd,
307 UM_FOCUSME,
308 MPFROMLONG(hwndActive),
309 MPVOID);
310 }
311 hptrIcon = WinLoadPointer(HWND_DESKTOP,
312 FM3ModHandle,
313 NOTE_FRAME);
314 if(hptrIcon)
315 WinDefDlgProc(hwnd,
316 WM_SETICON,
317 MPFROMLONG(hptrIcon),
318 MPFROMLONG(0L));
319 break;
320
321 case UM_FOCUSME:
322 {
323 ULONG size = sizeof(SWP),
324 fl = SWP_ZORDER | SWP_FOCUSDEACTIVATE | SWP_SHOW;
325 SWP swp;
326
327 if(PrfQueryProfileData(fmprof,
328 FM3Str,
329 "NoteWndSwp",
330 (PVOID)&swp,
331 &size)) {
332 if(swp.fl & (SWP_HIDE | SWP_MINIMIZE)) {
333 fl |= SWP_MINIMIZE;
334 fl &= (~SWP_SHOW);
335 }
336 else
337 fl |= (SWP_MOVE | SWP_SIZE);
338 }
339 WinSetWindowPos(hwnd,
340 HWND_BOTTOM,
341 swp.x,
342 swp.y,
343 swp.cx,
344 swp.cy,
345 fl);
346 if(fl & SWP_MINIMIZE) {
347 WinSetWindowUShort(hwnd,QWS_XRESTORE,(USHORT)swp.x);
348 WinSetWindowUShort(hwnd,QWS_CXRESTORE,(USHORT)swp.cx);
349 WinSetWindowUShort(hwnd,QWS_YRESTORE,(USHORT)swp.y);
350 WinSetWindowUShort(hwnd,QWS_CYRESTORE,(USHORT)swp.cy);
351 }
352 }
353 if(mp1)
354 WinSetActiveWindow(HWND_DESKTOP,(HWND)mp1);
355 return 0;
356
357 case UM_STRETCH:
358 {
359 SWP swp;
360 LONG titl,szbx,szby;
361
362 WinQueryWindowPos(hwnd,&swp);
363 if(!(swp.fl & (SWP_MINIMIZE | SWP_HIDE))) {
364 szbx = SysVal(SV_CXSIZEBORDER);
365 szby = SysVal(SV_CYSIZEBORDER);
366 titl = SysVal(SV_CYTITLEBAR);
367 WinSetWindowPos(WinWindowFromID(hwnd,NOTE_LISTBOX),
368 HWND_TOP,
369 szbx,
370 szby,
371 swp.cx - (szbx * 2L),
372 (swp.cy - titl) - (szby * 2L),
373 SWP_MOVE | SWP_SIZE);
374 }
375 if(!(swp.fl & SWP_MAXIMIZE)) {
376 if(swp.fl & (SWP_MINIMIZE | SWP_HIDE)) {
377 swp.x = WinQueryWindowUShort(hwnd,QWS_XRESTORE);
378 swp.y = WinQueryWindowUShort(hwnd,QWS_YRESTORE);
379 swp.cx = WinQueryWindowUShort(hwnd,QWS_CXRESTORE);
380 swp.cy = WinQueryWindowUShort(hwnd,QWS_CYRESTORE);
381 }
382 PrfWriteProfileData(fmprof,
383 FM3Str,
384 "NoteWndSwp",
385 (PVOID)&swp,
386 sizeof(SWP));
387 }
388 }
389 return 0;
390
391 case WM_ADJUSTWINDOWPOS:
392 PostMsg(hwnd,
393 UM_STRETCH,
394 MPVOID,
395 MPVOID);
396 break;
397
398 case UM_CONTAINER_FILLED:
399 {
400 SHORT x,y;
401
402 x = (SHORT)WinSendDlgItemMsg(hwnd,
403 NOTE_LISTBOX,
404 LM_QUERYITEMCOUNT,
405 MPVOID,
406 MPVOID);
407 if(x > 60) {
408 for(y = 0;y < x - 50;y++)
409 WinSendDlgItemMsg(hwnd,
410 NOTE_LISTBOX,
411 LM_DELETEITEM,
412 MPFROMSHORT(y),
413 MPVOID);
414 }
415 }
416 return 0;
417
418 case UM_NOTIFY:
419 {
420 SHORT x;
421
422 x = (SHORT)WinSendDlgItemMsg(hwnd,
423 NOTE_LISTBOX,
424 LM_QUERYITEMCOUNT,
425 MPVOID,
426 MPVOID);
427 if(x > 0)
428 WinSendDlgItemMsg(hwnd,
429 NOTE_LISTBOX,
430 LM_SETTOPINDEX,
431 MPFROMSHORT(x),
432 MPVOID);
433 }
434 return 0;
435
436 case UM_SHOWME:
437 WinSetWindowPos(hwnd,
438 HWND_TOP,
439 0,
440 0,
441 0,
442 0,
443 SWP_SHOW | SWP_RESTORE | SWP_ZORDER | SWP_ACTIVATE);
444 return 0;
445
446 case WM_COMMAND:
447 return 0;
448
449 case WM_CLOSE:
450 WinDismissDlg(hwnd,0);
451 return 0;
452
453 case WM_DESTROY:
454 if(hwndNotify == hwnd) {
455 fThreadNotes = FALSE;
456 PrfWriteProfileData(fmprof,
457 FM3Str,
458 "ThreadNotes",
459 &fThreadNotes,
460 sizeof(BOOL));
461 hwndNotify = (HWND)0;
462 }
463 if(hptrIcon)
464 WinDestroyPointer(hptrIcon);
465 if(!PostMsg((HWND)0,
466 WM_QUIT,
467 MPVOID,
468 MPVOID))
469 WinSendMsg((HWND)0,
470 WM_QUIT,
471 MPVOID,
472 MPVOID);
473 break;
474 }
475 return WinDefDlgProc(hwnd,msg,mp1,mp2);
476}
477
478
479VOID NoteThread (VOID *args)
480{
481 HAB hab2;
482 HMQ hmq2;
483
484 hab2 = WinInitialize(0);
485 if(hab2) {
486 hmq2 = WinCreateMsgQueue(hab2,0);
487 if(hmq2) {
488 if(!hwndNotify)
489 WinDlgBox(HWND_DESKTOP,
490 HWND_DESKTOP,
491 NoteWndProc,
492 FM3ModHandle,
493 NOTE_FRAME,
494 (CHAR *)args);
495 WinDestroyMsgQueue(hmq2);
496 }
497 WinTerminate(hab2);
498 }
499}
500
501
502VOID StartNotes (CHAR *note)
503{
504 if (!hwndNotify) {
505 if (_beginthread(NoteThread,NULL,65536,(PVOID)note) == -1)
506 Runtime_Error(pszSrcFile, __LINE__, GetPString(IDS_COULDNTSTARTTHREADTEXT));
507 }
508}
509
510
511BOOL AddNote (CHAR *note)
512{
513 CHAR *s,*p;
514 BOOL once = FALSE,ret = FALSE;
515
516 if((fThreadNotes || hwndNotify) && note && *note) {
517 p = note;
518 while(*p == ' ')
519 p++;
520 if(*p) {
521 if(!hwndNotify) {
522 fThreadNotes = FALSE;
523 StartNotes(NULL);
524 if(!hwndNotify)
525 DosSleep(33L);
526 if(!hwndNotify)
527 DosSleep(33L);
528 if(!hwndNotify)
529 DosSleep(33L);
530 }
531 if(hwndNotify) {
532 s = malloc(strlen(p) + 14);
533 if(s) {
534 sprintf(s,"%08lx %s",_threadid,p);
535 while(!once) {
536 if((SHORT)WinSendDlgItemMsg(hwndNotify,
537 NOTE_LISTBOX,
538 LM_INSERTITEM,
539 MPFROM2SHORT(LIT_END,0),
540 MPFROMP(s)) >= 0) {
541 ret = TRUE;
542 PostMsg(hwndNotify,
543 UM_NOTIFY,
544 MPVOID,
545 MPVOID);
546 break;
547 }
548 PostMsg(hwndNotify,
549 UM_CONTAINER_FILLED,
550 MPVOID,
551 MPVOID);
552 once = TRUE;
553 }
554 }
555 free(s);
556 }
557 }
558 }
559 return ret;
560}
561
562
563VOID EndNote (VOID)
564{
565 if(hwndNotify)
566 if(!PostMsg(hwndNotify,
567 WM_CLOSE,
568 MPVOID,
569 MPVOID))
570 WinSendMsg(hwndNotify,
571 WM_CLOSE,
572 MPVOID,
573 MPVOID);
574}
575
576
577VOID ShowNote (VOID)
578{
579 if(!hwndNotify)
580 StartNotes(NULL);
581 if(!hwndNotify)
582 DosSleep(33L);
583 if(!hwndNotify)
584 DosSleep(33L);
585 if(!hwndNotify)
586 DosSleep(33L);
587 if(hwndNotify)
588 PostMsg(hwndNotify,
589 UM_SHOWME,
590 MPVOID,
591 MPVOID);
592}
593
594
595VOID HideNote (VOID)
596{
597 if(hwndNotify)
598 WinSetWindowPos(hwndNotify,
599 HWND_BOTTOM,
600 0,
601 0,
602 0,
603 0,
604 SWP_MINIMIZE | SWP_ZORDER | SWP_FOCUSDEACTIVATE);
605}
Note: See TracBrowser for help on using the repository browser.