| 1 | /***
 | 
|---|
| 2 |  Main source of the Gotcha! screencapture program.
 | 
|---|
| 3 |  Copyright (C) 1998-2002 Thorsten Thielen <thth@c2226.de>
 | 
|---|
| 4 | 
 | 
|---|
| 5 |  This program is free software; you can redistribute it and/or modify
 | 
|---|
| 6 |  it under the terms of the GNU General Public License as published by
 | 
|---|
| 7 |  the Free Software Foundation; either version 2 of the License, or
 | 
|---|
| 8 |  (at your option) any later version.
 | 
|---|
| 9 | 
 | 
|---|
| 10 |  This program is distributed in the hope that it will be useful,
 | 
|---|
| 11 |  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 12 |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 13 |  GNU General Public License for more details.
 | 
|---|
| 14 | 
 | 
|---|
| 15 |  You should have received a copy of the GNU General Public License
 | 
|---|
| 16 |  along with this program; if not, write to the Free Software
 | 
|---|
| 17 |  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
|---|
| 18 |  ***/
 | 
|---|
| 19 | 
 | 
|---|
| 20 | #define INCL_WINHOOKS
 | 
|---|
| 21 | 
 | 
|---|
| 22 | #include "gotcha.h"
 | 
|---|
| 23 | #include "dll/gotchdll.h"
 | 
|---|
| 24 | #include "settings.h"
 | 
|---|
| 25 | #include "string.h"
 | 
|---|
| 26 | 
 | 
|---|
| 27 | #include "io.h"
 | 
|---|
| 28 | #define INCL_EXCEPTQ_CLASS
 | 
|---|
| 29 | #define INCL_LOADEXCEPTQ
 | 
|---|
| 30 | #include "exceptq.h"
 | 
|---|
| 31 | 
 | 
|---|
| 32 | HAB         hab;
 | 
|---|
| 33 | HWND        hwndFrame, hwndSnapshot;
 | 
|---|
| 34 | PFNWP       OldFrameWP, wpOldButton;
 | 
|---|
| 35 | PSETTINGS   pset;
 | 
|---|
| 36 | BOOL        g_fQuiet = FALSE, g_fIdle = FALSE, g_fSetPathName = FALSE;
 | 
|---|
| 37 | HWND        g_hwndMenuSSW;
 | 
|---|
| 38 | HMODULE     g_hmod = NULLHANDLE;
 | 
|---|
| 39 | Helper      *g_phelp = NULL;
 | 
|---|
| 40 | 
 | 
|---|
| 41 | #include "bitmap.cpp"
 | 
|---|
| 42 | #include "mainwin.cpp"
 | 
|---|
| 43 | #include "snapshot.cpp"
 | 
|---|
| 44 | #include "savebmp.cpp"
 | 
|---|
| 45 | 
 | 
|---|
| 46 | // ** CheckCmdlineArgs **************************************************** /*FOLD00*/
 | 
|---|
| 47 | 
 | 
|---|
| 48 | BOOL CheckCmdlineArgs (int argc, char *argv[])
 | 
|---|
| 49 | {
 | 
|---|
| 50 |     BOOL   fAuto = FALSE;
 | 
|---|
| 51 | 
 | 
|---|
| 52 |     for (USHORT i = 1; i < argc; i++)
 | 
|---|
| 53 |     {
 | 
|---|
| 54 |         // quiet or batch mode
 | 
|---|
| 55 |         if ((stricmp (argv[i], "-q") == 0) || (stricmp (argv[i], "-a") == 0))
 | 
|---|
| 56 |         {
 | 
|---|
| 57 |             if (pset->QuerySaveStyle () != FSS_FORCEFILE)
 | 
|---|
| 58 |                 pset->SetFileSaveStyle (FSS_NUMFILES);
 | 
|---|
| 59 | 
 | 
|---|
| 60 |             if (stricmp (argv[i], "-q") == 0)
 | 
|---|
| 61 |             {
 | 
|---|
| 62 |                 pset->SerialCapture (FALSE);
 | 
|---|
| 63 |                 g_fQuiet = TRUE;
 | 
|---|
| 64 |             }
 | 
|---|
| 65 |             else
 | 
|---|
| 66 |                 fAuto = TRUE;
 | 
|---|
| 67 | 
 | 
|---|
| 68 |             if (i < argc-1)
 | 
|---|
| 69 |                 if (argv[i+1][0] != '-')
 | 
|---|
| 70 |                 {
 | 
|---|
| 71 |                     i++;
 | 
|---|
| 72 |                     pset->SetFileSaveStyle (FSS_NUMFILES);
 | 
|---|
| 73 |                     pset->SetNumSaveDir (argv[i]);
 | 
|---|
| 74 |                     g_fSetPathName = TRUE;
 | 
|---|
| 75 |                 }
 | 
|---|
| 76 |         }
 | 
|---|
| 77 |         // force saving to the given file name
 | 
|---|
| 78 |         else if ((stricmp (argv[i], "-f") == 0) && (i < argc-1))
 | 
|---|
| 79 |         {
 | 
|---|
| 80 |             if (argv[i+1][0] != '-')
 | 
|---|
| 81 |             {
 | 
|---|
| 82 |                 i++;
 | 
|---|
| 83 |                 pset->SetFileSaveStyle (FSS_FORCEFILE);
 | 
|---|
| 84 |                 pset->SetForceSaveFile (argv[i]);
 | 
|---|
| 85 |                 g_fSetPathName = TRUE;
 | 
|---|
| 86 |             }
 | 
|---|
| 87 |         }
 | 
|---|
| 88 |         // set to idle priority
 | 
|---|
| 89 |         else if (stricmp (argv[i], "-i") == 0)
 | 
|---|
| 90 |         {
 | 
|---|
| 91 |             g_fIdle = TRUE;
 | 
|---|
| 92 |             pset->SetFlag (SEI_IDLEPRIORITY, TRUE);
 | 
|---|
| 93 |         }
 | 
|---|
| 94 |     }
 | 
|---|
| 95 | 
 | 
|---|
| 96 |     return fAuto;
 | 
|---|
| 97 | }
 | 
|---|
| 98 | 
 | 
|---|
| 99 | // ** main **************************************************************** /*FOLD00*/
 | 
|---|
| 100 | 
 | 
|---|
| 101 | int main (int argc, PSZ argv[])
 | 
|---|
| 102 | {
 | 
|---|
| 103 |     ScopedExceptqLoader sel;
 | 
|---|
| 104 | #ifdef _DOLOGDEBUG_
 | 
|---|
| 105 |     LogDebug( "Gotcha! start" );
 | 
|---|
| 106 | #endif
 | 
|---|
| 107 | #ifdef _DOLOGMEM_
 | 
|---|
| 108 |     LogMem("main", TRUE);
 | 
|---|
| 109 | #endif
 | 
|---|
| 110 | 
 | 
|---|
| 111 |     // init system and msg queue
 | 
|---|
| 112 |     hab = WinInitialize (0);
 | 
|---|
| 113 |     HMQ hmq = WinCreateMsgQueue (hab, 0);
 | 
|---|
| 114 | 
 | 
|---|
| 115 |     //DisplayError("DEBUG", "%d", Version());
 | 
|---|
| 116 | #ifdef _QUIET_
 | 
|---|
| 117 |     if ((Version() < 1))
 | 
|---|
| 118 |     {
 | 
|---|
| 119 |         DisplayError("GOTCHA.DLL TO OLD",
 | 
|---|
| 120 |                      "The file gotcha.dll is to old for this version of "
 | 
|---|
| 121 |                      "Gotcha! As you should have received a sufficiently "
 | 
|---|
| 122 |                      "new version with the program, check if an older "
 | 
|---|
| 123 |                      "version of gotcha.dll is still residing somewhere "
 | 
|---|
| 124 |                      "in your LIBPATH. And did you actually copy the new "
 | 
|---|
| 125 |                      "gotcha.dll to some directory in your LIBPATH?");
 | 
|---|
| 126 |         exit (0);
 | 
|---|
| 127 |     }
 | 
|---|
| 128 | 
 | 
|---|
| 129 |     bool fPrtScr = FALSE;
 | 
|---|
| 130 |     ULONG ulDataSize;
 | 
|---|
| 131 |     int rc;
 | 
|---|
| 132 | 
 | 
|---|
| 133 |     rc = PrfQueryProfileSize( HINI_PROFILE, "PM_ControlPanel", "PrintScreen",
 | 
|---|
| 134 |                              &ulDataSize );
 | 
|---|
| 135 |     rc = PrfQueryProfileData(HINI_USERPROFILE, "PM_ControlPanel", "PrintScreen",
 | 
|---|
| 136 |                              &fPrtScr, &ulDataSize);
 | 
|---|
| 137 |     if (fPrtScr || !rc) {
 | 
|---|
| 138 |         fPrtScr = TRUE;
 | 
|---|
| 139 |         bool temp = FALSE;
 | 
|---|
| 140 |         rc = PrfWriteProfileData(HINI_USERPROFILE, "PM_ControlPanel", "PrintScreen",
 | 
|---|
| 141 |                                  &temp, sizeof(bool));
 | 
|---|
| 142 |     }
 | 
|---|
| 143 | #endif
 | 
|---|
| 144 | 
 | 
|---|
| 145 |     // register our window classes
 | 
|---|
| 146 |     WinRegisterClass (hab, "thth.wc.gotcha.main", WindowProcedure, 0L,
 | 
|---|
| 147 |                       sizeof (ULONG)*2L);
 | 
|---|
| 148 |     WinRegisterClass (hab, "thth.wc.gotcha.snapshot", wpSnapshot,
 | 
|---|
| 149 |                       CS_SIZEREDRAW, sizeof (ULONG)*2L);
 | 
|---|
| 150 | 
 | 
|---|
| 151 |     // load the settings
 | 
|---|
| 152 |     pset = new SETTINGS;
 | 
|---|
| 153 | 
 | 
|---|
| 154 |     pset->idleSetInIni = pset->QueryFlag(SEI_IDLEPRIORITY);
 | 
|---|
| 155 |     pset->saveStyle = pset->QuerySaveStyle ();
 | 
|---|
| 156 |     pset->pNumSaveDir = pset->QueryNumSaveDir ();
 | 
|---|
| 157 |     pset->pForceSaveFile = pset->QueryForceSaveFile();
 | 
|---|
| 158 |     pset->bSerialCapture = pset->SerialCapture ();
 | 
|---|
| 159 |     // check cmd line args and if "-a" found take screenshot and exit
 | 
|---|
| 160 |     if (CheckCmdlineArgs (argc, argv))
 | 
|---|
| 161 |     {
 | 
|---|
| 162 |         CaptureWindow (HWND_DESKTOP, HWND_DESKTOP, NULL, TRUE);
 | 
|---|
| 163 |         pset->SetFileSaveStyle(pset->saveStyle);
 | 
|---|
| 164 |         delete pset;
 | 
|---|
| 165 |         WinDestroyMsgQueue (hmq);
 | 
|---|
| 166 |         WinTerminate (hab);
 | 
|---|
| 167 |         exit (0);
 | 
|---|
| 168 |     }
 | 
|---|
| 169 | 
 | 
|---|
| 170 |     SetIdlePriority(pset->QueryFlag(SEI_IDLEPRIORITY));
 | 
|---|
| 171 | 
 | 
|---|
| 172 |     // create the windows
 | 
|---|
| 173 |     hwndFrame = CreateMainWindow ();
 | 
|---|
| 174 |     hwndSnapshot = CreateSnapshotWindow ();
 | 
|---|
| 175 | 
 | 
|---|
| 176 |     SWP swp;
 | 
|---|
| 177 |     USHORT us[7];
 | 
|---|
| 178 | 
 | 
|---|
| 179 |     // position main window
 | 
|---|
| 180 |     pset->QueryWindowData (&swp, us, FALSE);
 | 
|---|
| 181 |     WinSetWindowPos (hwndFrame, HWND_DESKTOP, swp.x,swp.y, 0,0,
 | 
|---|
| 182 |                      SWP_SHOW | SWP_MOVE);
 | 
|---|
| 183 | 
 | 
|---|
| 184 |     // init the quiet mode
 | 
|---|
| 185 |     //if (g_fQuiet)
 | 
|---|
| 186 |     //{
 | 
|---|
| 187 | #ifdef _QUIET_
 | 
|---|
| 188 | //#if 1
 | 
|---|
| 189 |     DebugHereIAm();
 | 
|---|
| 190 |         InitDLL (hab, hwndFrame);
 | 
|---|
| 191 |         StartInputHook ();
 | 
|---|
| 192 | #endif
 | 
|---|
| 193 | 
 | 
|---|
| 194 |         //CHAR ach[61];
 | 
|---|
| 195 |         //WinQueryWindowText (hwndFrame, sizeof (ach), ach);
 | 
|---|
| 196 |         //strcat (ach, RSTR (IDS_QUIETMODE));
 | 
|---|
| 197 |         //WinSetWindowText (hwndFrame, ach);
 | 
|---|
| 198 |         //WinSetWindowPos (hwndFrame, NULLHANDLE, 0,0, 0,0, SWP_MINIMIZE);
 | 
|---|
| 199 |         //HSWITCH hswitch = WinQuerySwitchHandle(hwndFrame, 0);
 | 
|---|
| 200 |         //WinRemoveSwitchEntry(hswitch);
 | 
|---|
| 201 |     //}
 | 
|---|
| 202 | 
 | 
|---|
| 203 |     // position snapshot window
 | 
|---|
| 204 |     pset->QueryWindowData (&swp, us);
 | 
|---|
| 205 | 
 | 
|---|
| 206 |     // size, activate & show window
 | 
|---|
| 207 |     WinSetWindowPos (hwndSnapshot, HWND_DESKTOP, swp.x,swp.y, swp.cx,swp.cy,
 | 
|---|
| 208 |                      SWP_SHOW | SWP_SIZE | SWP_MOVE);
 | 
|---|
| 209 |     if (! pset->SnapshotWindow ())
 | 
|---|
| 210 |         WinShowWindow (hwndSnapshot, FALSE);
 | 
|---|
| 211 |     else
 | 
|---|
| 212 |         WinShowWindow (hwndSnapshot, TRUE);
 | 
|---|
| 213 | 
 | 
|---|
| 214 |     WinSetWindowPos (hwndFrame, NULLHANDLE, 0,0, 0,0, SWP_SHOW);
 | 
|---|
| 215 |     WinSetWindowPos (WinWindowFromID (hwndFrame, FID_CLIENT), NULLHANDLE,
 | 
|---|
| 216 |                      0,0, 0,0, SWP_SHOW);
 | 
|---|
| 217 | 
 | 
|---|
| 218 |     g_phelp = new Helper(hwndFrame);
 | 
|---|
| 219 | 
 | 
|---|
| 220 | 
 | 
|---|
| 221 |     // do the main msg loop
 | 
|---|
| 222 |     QMSG   qmsg;
 | 
|---|
| 223 |     while (WinGetMsg (hab, &qmsg, 0L, 0, 0))
 | 
|---|
| 224 |         WinDispatchMsg (hab, &qmsg);
 | 
|---|
| 225 | 
 | 
|---|
| 226 | 
 | 
|---|
| 227 |     // Set priorty to unless user set regular since running -q sets it to idle in the ini
 | 
|---|
| 228 |     if (g_fIdle || g_fQuiet) {
 | 
|---|
| 229 |         pset->SetFlag (SEI_IDLEPRIORITY, pset->idleSetInIni);
 | 
|---|
| 230 |         if (g_fQuiet) {
 | 
|---|
| 231 |             pset->SetFileSaveStyle (pset->saveStyle); // changed with -q
 | 
|---|
| 232 |             pset->SerialCapture (pset->bSerialCapture); // changed with -q
 | 
|---|
| 233 |         }
 | 
|---|
| 234 |     }
 | 
|---|
| 235 |     // Don't change the ini stored paths if the paths were set from the command line
 | 
|---|
| 236 |     if (g_fSetPathName) {
 | 
|---|
| 237 |         pset->SetFileSaveStyle(pset->saveStyle);
 | 
|---|
| 238 |         pset->SetForceSaveFile (pset->pForceSaveFile);
 | 
|---|
| 239 |         pset->SetNumSaveDir (pset->pNumSaveDir);
 | 
|---|
| 240 |     }
 | 
|---|
| 241 |     // save size, etc. of snapshot window
 | 
|---|
| 242 |     WinQueryWindowPos (hwndSnapshot, &swp);
 | 
|---|
| 243 |     pset->SetWindowData (&swp);
 | 
|---|
| 244 | 
 | 
|---|
| 245 |     // save size, etc. of main window
 | 
|---|
| 246 |     WinQueryWindowPos (hwndFrame, &swp);
 | 
|---|
| 247 |     pset->SetWindowData (&swp, FALSE);
 | 
|---|
| 248 | 
 | 
|---|
| 249 |     // goodbye windows!
 | 
|---|
| 250 |     WinDestroyWindow (hwndSnapshot);
 | 
|---|
| 251 |     WinDestroyWindow (hwndFrame);
 | 
|---|
| 252 | 
 | 
|---|
| 253 | #ifdef _QUIET_
 | 
|---|
| 254 | //#if 1
 | 
|---|
| 255 |     if (fPrtScr || !rc) {
 | 
|---|
| 256 |         PrfWriteProfileData(HINI_USERPROFILE, "PM_ControlPanel", "PrintScreen",
 | 
|---|
| 257 |                             &fPrtScr, sizeof(bool));
 | 
|---|
| 258 |     }
 | 
|---|
| 259 |     //if (g_fQuiet)
 | 
|---|
| 260 |         StopInputHook ();
 | 
|---|
| 261 | #endif
 | 
|---|
| 262 | 
 | 
|---|
| 263 |     delete g_phelp;
 | 
|---|
| 264 |     delete pset;
 | 
|---|
| 265 | 
 | 
|---|
| 266 |     WinDestroyMsgQueue (hmq);
 | 
|---|
| 267 |     WinTerminate (hab);
 | 
|---|
| 268 | 
 | 
|---|
| 269 | #ifdef _DOLOGMEM_
 | 
|---|
| 270 |     LogMem("main", FALSE);
 | 
|---|
| 271 | #endif
 | 
|---|
| 272 | #ifdef _DOLOGDEBUG_
 | 
|---|
| 273 |     LogDebug( "Gotcha! end" );
 | 
|---|
| 274 | #endif
 | 
|---|
| 275 | }
 | 
|---|
| 276 | 
 | 
|---|
| 277 | // ** DisplayError ******************************************************** /*FOLD00*/
 | 
|---|
| 278 | 
 | 
|---|
| 279 | VOID DisplayError (PSZ pszTitle, PSZ psz, ...)
 | 
|---|
| 280 | {
 | 
|---|
| 281 |     CHAR      dstring[401];
 | 
|---|
| 282 |     va_list   valst;
 | 
|---|
| 283 | 
 | 
|---|
| 284 |     va_start (valst, psz);
 | 
|---|
| 285 |     vsnprintf (dstring, 401, psz, valst);
 | 
|---|
| 286 |     va_end (valst);
 | 
|---|
| 287 | 
 | 
|---|
| 288 |     WinMessageBox (HWND_DESKTOP, WinQueryActiveWindow (HWND_DESKTOP), dstring,
 | 
|---|
| 289 |                    pszTitle, 0, MB_OK | MB_ERROR | MB_APPLMODAL | MB_MOVEABLE);
 | 
|---|
| 290 | }
 | 
|---|
| 291 | 
 | 
|---|
| 292 | APIRET saymsg2(int DefaultButton, HWND hwnd,  PCSZ pszTitle, PCSZ pszFmt, ...)
 | 
|---|
| 293 | {
 | 
|---|
| 294 |   ULONG i;
 | 
|---|
| 295 |   APIRET rc;
 | 
|---|
| 296 |   CHAR szMsg[4096];
 | 
|---|
| 297 |   va_list va;
 | 
|---|
| 298 |   MB2INFO *pmbInfo;
 | 
|---|
| 299 |   MB2D mb2dBut[3];
 | 
|---|
| 300 |   ULONG ulInfoSize = (sizeof(MB2INFO) + (sizeof(MB2D) * 2));
 | 
|---|
| 301 | 
 | 
|---|
| 302 |   va_start(va, pszFmt);
 | 
|---|
| 303 |   szMsg[sizeof(szMsg) - 1] = 0;
 | 
|---|
| 304 |   vsprintf(szMsg, pszFmt, va);
 | 
|---|
| 305 |   va_end(va);
 | 
|---|
| 306 | 
 | 
|---|
| 307 |   if (szMsg[sizeof(szMsg) - 1]) {
 | 
|---|
| 308 |     fprintf(stderr, "Buffer overflow in saymsg2 - need %u bytes\n", strlen(szMsg) + 1);
 | 
|---|
| 309 |     fflush(stderr);
 | 
|---|
| 310 |   }
 | 
|---|
| 311 | 
 | 
|---|
| 312 |   memset(mb2dBut, 0, sizeof(MB2D) * 3);
 | 
|---|
| 313 |   strcpy(mb2dBut[0].achText,"Ok");
 | 
|---|
| 314 |   strcpy(mb2dBut[1].achText,"Cancel");
 | 
|---|
| 315 |   strcpy(mb2dBut[2].achText,"Settings");
 | 
|---|
| 316 |   mb2dBut[0].idButton = 1;
 | 
|---|
| 317 |   mb2dBut[1].idButton = 2;
 | 
|---|
| 318 |   mb2dBut[2].idButton = 3;
 | 
|---|
| 319 |   if (DefaultButton)
 | 
|---|
| 320 |     mb2dBut[DefaultButton - 1].flStyle = BS_DEFAULT;
 | 
|---|
| 321 |   pmbInfo = (MB2INFO *) malloc(ulInfoSize);
 | 
|---|
| 322 |   memset(pmbInfo, 0, ulInfoSize);
 | 
|---|
| 323 |   if (pmbInfo) {
 | 
|---|
| 324 |     pmbInfo->cb         = ulInfoSize;
 | 
|---|
| 325 |     pmbInfo->hIcon      = 0;
 | 
|---|
| 326 |     pmbInfo->cButtons   = 3;
 | 
|---|
| 327 |     pmbInfo->flStyle    = MB_MOVEABLE | MB_ICONQUESTION ;
 | 
|---|
| 328 |     pmbInfo->hwndNotify = NULLHANDLE;
 | 
|---|
| 329 |     for (i = 0; i < 3; i++) {
 | 
|---|
| 330 |       memcpy( pmbInfo->mb2d+i , mb2dBut+i , sizeof(MB2D));
 | 
|---|
| 331 |     }
 | 
|---|
| 332 |     rc = WinMessageBox2(HWND_DESKTOP, hwnd,
 | 
|---|
| 333 |                         szMsg, pszTitle, SM2_DIALOG,
 | 
|---|
| 334 |                         pmbInfo);
 | 
|---|
| 335 |     WinSetFocus(HWND_DESKTOP, SM2_DIALOG);
 | 
|---|
| 336 |     free(pmbInfo);
 | 
|---|
| 337 |     return rc;
 | 
|---|
| 338 |   }
 | 
|---|
| 339 |   return MBID_ERROR;
 | 
|---|
| 340 | }
 | 
|---|
| 341 | // ** AddSysMenuItem ****************************************************** /*FOLD00*/
 | 
|---|
| 342 | 
 | 
|---|
| 343 | VOID AddSysMenuItem (HWND hwndFrame, MENUITEM *Item, PSZ Text)
 | 
|---|
| 344 | {
 | 
|---|
| 345 |     HWND   hwndSysMenu = WinWindowFromID (hwndFrame, FID_SYSMENU);
 | 
|---|
| 346 |     USHORT idSysMenu   = SHORT1FROMMR (WinSendMsg (hwndSysMenu,
 | 
|---|
| 347 |                                                    MM_ITEMIDFROMPOSITION, NULL,
 | 
|---|
| 348 |                                                    NULL ));
 | 
|---|
| 349 |     MENUITEM   miSysMenu;
 | 
|---|
| 350 |     WinSendMsg (hwndSysMenu, MM_QUERYITEM,
 | 
|---|
| 351 |                 MPFROM2SHORT (idSysMenu,FALSE), MPFROMP(&miSysMenu));
 | 
|---|
| 352 | 
 | 
|---|
| 353 |     HWND   hwndSysSubMenu = miSysMenu.hwndSubMenu;
 | 
|---|
| 354 | 
 | 
|---|
| 355 |     WinSendMsg (hwndSysSubMenu, MM_INSERTITEM, MPFROMP(Item), MPFROMP(Text));
 | 
|---|
| 356 | }
 | 
|---|
| 357 | 
 | 
|---|
| 358 | // ** DoCountdown ********************************************************* /*fold00*/
 | 
|---|
| 359 | 
 | 
|---|
| 360 | VOID DoCountdown (ULONG ul)
 | 
|---|
| 361 | {
 | 
|---|
| 362 |     if (ul > 10)
 | 
|---|
| 363 |         DosBeep (4000L-3000L, 20);
 | 
|---|
| 364 |     else
 | 
|---|
| 365 |         DosBeep (4000L-ul*300L, 20);
 | 
|---|
| 366 | }
 | 
|---|
| 367 | 
 | 
|---|
| 368 | // ** SetIdlePriority **************************************************** /*FOLD00*/
 | 
|---|
| 369 | 
 | 
|---|
| 370 | VOID SetIdlePriority (BOOL f)
 | 
|---|
| 371 | {
 | 
|---|
| 372 | #if 0 //#ifndef _QUEIT_
 | 
|---|
| 373 |     if (f)
 | 
|---|
| 374 |         DosSetPriority(PRTYS_PROCESS, PRTYC_IDLETIME, 0, 0);
 | 
|---|
| 375 |     else
 | 
|---|
| 376 |         DosSetPriority(PRTYS_PROCESS, PRTYC_REGULAR, 0, 0);
 | 
|---|
| 377 | #else
 | 
|---|
| 378 |     DosSetPriority(PRTYS_PROCESS, PRTYC_FOREGROUNDSERVER, 0, 0);
 | 
|---|
| 379 | #endif
 | 
|---|
| 380 | }
 | 
|---|
| 381 | 
 | 
|---|
| 382 | // ***********************************************************************
 | 
|---|
| 383 | 
 | 
|---|
| 384 | #ifdef _DOLOGMEM_
 | 
|---|
| 385 | VOID LogMem (PSZ psz, BOOL f)
 | 
|---|
| 386 | {
 | 
|---|
| 387 |     FILE *pf = fopen("gotcha.mem","ab");
 | 
|---|
| 388 |     static ULONG TotalPhysicalMemory, ul = 0;
 | 
|---|
| 389 |     ULONG i;
 | 
|---|
| 390 |     if (!f)
 | 
|---|
| 391 |         ul--;
 | 
|---|
| 392 |     DosQuerySysInfo(QSV_TOTAVAILMEM, QSV_TOTAVAILMEM, &TotalPhysicalMemory,
 | 
|---|
| 393 |                     sizeof(TotalPhysicalMemory));
 | 
|---|
| 394 |     for (i = 0; i < ul; i++)
 | 
|---|
| 395 |         fputs("  ", pf);
 | 
|---|
| 396 |     fprintf(pf,"%10ld (%s)\n", TotalPhysicalMemory, psz);
 | 
|---|
| 397 |     if (f)
 | 
|---|
| 398 |         ul++;
 | 
|---|
| 399 |     fclose(pf);
 | 
|---|
| 400 | }
 | 
|---|
| 401 | #endif
 | 
|---|
| 402 | 
 | 
|---|
| 403 | #ifdef _DOLOGDEBUG_
 | 
|---|
| 404 | VOID LogDebug( PSZ psz, ... )
 | 
|---|
| 405 | {
 | 
|---|
| 406 |     CHAR      dstring[401];
 | 
|---|
| 407 |     va_list   valst;
 | 
|---|
| 408 | 
 | 
|---|
| 409 |     va_start (valst, psz);
 | 
|---|
| 410 |     vsnprintf (dstring, 401, psz, valst);
 | 
|---|
| 411 |     va_end (valst);
 | 
|---|
| 412 | 
 | 
|---|
| 413 |     FILE *pf = fopen( "gotcha.log", "ab" );
 | 
|---|
| 414 |     fprintf( pf, "%s\n", dstring );
 | 
|---|
| 415 |     fclose( pf );
 | 
|---|
| 416 | }
 | 
|---|
| 417 | #endif
 | 
|---|
| 418 | 
 | 
|---|
| 419 | // ***********************************************************************
 | 
|---|