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