| [2] | 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"
|
|---|
| [10] | 23 | #include "dll/gotchdll.h"
|
|---|
| [2] | 24 | #include "settings.h"
|
|---|
| 25 | #include "string.h"
|
|---|
| 26 |
|
|---|
| 27 | #include "io.h"
|
|---|
| [13] | 28 | #define INCL_EXCEPTQ_CLASS
|
|---|
| 29 | #define INCL_LOADEXCEPTQ
|
|---|
| 30 | #include "exceptq.h"
|
|---|
| [2] | 31 |
|
|---|
| 32 | HAB hab;
|
|---|
| 33 | HWND hwndFrame, hwndSnapshot;
|
|---|
| 34 | PFNWP OldFrameWP, wpOldButton;
|
|---|
| 35 | PSETTINGS pset;
|
|---|
| 36 | BOOL g_fQuiet = 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 | }
|
|---|
| 75 | }
|
|---|
| 76 | // force saving to the given file name
|
|---|
| 77 | else if ((stricmp (argv[i], "-f") == 0) && (i < argc-1))
|
|---|
| 78 | {
|
|---|
| 79 | if (argv[i+1][0] != '-')
|
|---|
| 80 | {
|
|---|
| 81 | i++;
|
|---|
| 82 | pset->SetFileSaveStyle (FSS_FORCEFILE);
|
|---|
| 83 | pset->SetForceSaveFile (argv[i]);
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 | // set to idle priority
|
|---|
| 87 | else if (stricmp (argv[i], "-i") == 0)
|
|---|
| 88 | {
|
|---|
| 89 | pset->SetFlag (SEI_IDLEPRIORITY, TRUE);
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | return fAuto;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | // ** main **************************************************************** /*FOLD00*/
|
|---|
| 97 |
|
|---|
| 98 | int main (int argc, PSZ argv[])
|
|---|
| 99 | {
|
|---|
| [13] | 100 | ScopedExceptqLoader sel;
|
|---|
| [2] | 101 | #ifdef _DOLOGDEBUG_
|
|---|
| 102 | LogDebug( "Gotcha! start" );
|
|---|
| 103 | #endif
|
|---|
| 104 | #ifdef _DOLOGMEM_
|
|---|
| 105 | LogMem("main", TRUE);
|
|---|
| 106 | #endif
|
|---|
| 107 |
|
|---|
| 108 | // init system and msg queue
|
|---|
| 109 | hab = WinInitialize (0);
|
|---|
| 110 | HMQ hmq = WinCreateMsgQueue (hab, 0);
|
|---|
| 111 |
|
|---|
| 112 | //DisplayError("DEBUG", "%d", Version());
|
|---|
| 113 | #ifdef _USEDLL_
|
|---|
| 114 | if (g_fQuiet && (Version() < 1))
|
|---|
| 115 | {
|
|---|
| 116 | DisplayError("GOTCHA.DLL TO OLD",
|
|---|
| 117 | "The file gotcha.dll is to old for this version of "
|
|---|
| 118 | "Gotcha! As you should have received a sufficiently "
|
|---|
| 119 | "new version with the program, check if an older "
|
|---|
| 120 | "version of gotcha.dll is still residing somewhere "
|
|---|
| 121 | "in your LIBPATH. And did you actually copy the new "
|
|---|
| 122 | "gotcha.dll to some directory in your LIBPATH?");
|
|---|
| 123 | exit (0);
|
|---|
| 124 | }
|
|---|
| 125 | #endif
|
|---|
| 126 |
|
|---|
| 127 | // register our window classes
|
|---|
| 128 | WinRegisterClass (hab, "thth.wc.gotcha.main", WindowProcedure, 0L,
|
|---|
| 129 | sizeof (ULONG)*2L);
|
|---|
| 130 | WinRegisterClass (hab, "thth.wc.gotcha.snapshot", wpSnapshot,
|
|---|
| 131 | CS_SIZEREDRAW, sizeof (ULONG)*2L);
|
|---|
| 132 |
|
|---|
| 133 | // load the settings
|
|---|
| 134 | pset = new SETTINGS;
|
|---|
| 135 |
|
|---|
| 136 | // check cmd line args and if "-a" found take screenshot and exit
|
|---|
| 137 | if (CheckCmdlineArgs (argc, argv))
|
|---|
| 138 | {
|
|---|
| 139 | CaptureWindow (HWND_DESKTOP, HWND_DESKTOP, NULL, TRUE);
|
|---|
| 140 | delete pset;
|
|---|
| 141 | WinDestroyMsgQueue (hmq);
|
|---|
| 142 | WinTerminate (hab);
|
|---|
| 143 | exit (0);
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | SetIdlePriority(pset->QueryFlag(SEI_IDLEPRIORITY));
|
|---|
| 147 |
|
|---|
| 148 | // create the windows
|
|---|
| 149 | hwndFrame = CreateMainWindow ();
|
|---|
| 150 | hwndSnapshot = CreateSnapshotWindow ();
|
|---|
| 151 |
|
|---|
| 152 | SWP swp;
|
|---|
| 153 | USHORT us[7];
|
|---|
| 154 |
|
|---|
| 155 | // position main window
|
|---|
| 156 | pset->QueryWindowData (&swp, us, FALSE);
|
|---|
| 157 | WinSetWindowPos (hwndFrame, HWND_DESKTOP, swp.x,swp.y, 0,0,
|
|---|
| 158 | SWP_SHOW | SWP_MOVE);
|
|---|
| 159 |
|
|---|
| 160 | // init the quiet mode
|
|---|
| 161 | if (g_fQuiet)
|
|---|
| 162 | {
|
|---|
| 163 | #ifdef _USEDLL_
|
|---|
| 164 | InitDLL (hab, hwndFrame);
|
|---|
| 165 | StartInputHook ();
|
|---|
| 166 | #endif
|
|---|
| 167 |
|
|---|
| 168 | CHAR ach[61];
|
|---|
| 169 | WinQueryWindowText (hwndFrame, sizeof (ach), ach);
|
|---|
| 170 | strcat (ach, RSTR (IDS_QUIETMODE));
|
|---|
| 171 | WinSetWindowText (hwndFrame, ach);
|
|---|
| 172 | WinSetWindowPos (hwndFrame, NULLHANDLE, 0,0, 0,0, SWP_MINIMIZE);
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | // position snapshot window
|
|---|
| 176 | pset->QueryWindowData (&swp, us);
|
|---|
| 177 |
|
|---|
| 178 | // size, activate & show window
|
|---|
| 179 | WinSetWindowPos (hwndSnapshot, HWND_DESKTOP, swp.x,swp.y, swp.cx,swp.cy,
|
|---|
| 180 | SWP_SHOW | SWP_SIZE | SWP_MOVE);
|
|---|
| 181 | if (! pset->SnapshotWindow ())
|
|---|
| 182 | WinShowWindow (hwndSnapshot, FALSE);
|
|---|
| 183 | else
|
|---|
| 184 | WinShowWindow (hwndSnapshot, TRUE);
|
|---|
| 185 |
|
|---|
| 186 | WinSetWindowPos (hwndFrame, NULLHANDLE, 0,0, 0,0, SWP_SHOW);
|
|---|
| 187 | WinSetWindowPos (WinWindowFromID (hwndFrame, FID_CLIENT), NULLHANDLE,
|
|---|
| 188 | 0,0, 0,0, SWP_SHOW);
|
|---|
| 189 |
|
|---|
| 190 | g_phelp = new Helper(hwndFrame);
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 | // do the main msg loop
|
|---|
| 194 | QMSG qmsg;
|
|---|
| 195 | while (WinGetMsg (hab, &qmsg, 0L, 0, 0))
|
|---|
| 196 | WinDispatchMsg (hab, &qmsg);
|
|---|
| 197 |
|
|---|
| 198 | // save size, etc. of snapshot window
|
|---|
| 199 | WinQueryWindowPos (hwndSnapshot, &swp);
|
|---|
| 200 | pset->SetWindowData (&swp);
|
|---|
| 201 |
|
|---|
| 202 | // save size, etc. of main window
|
|---|
| 203 | WinQueryWindowPos (hwndFrame, &swp);
|
|---|
| 204 | pset->SetWindowData (&swp, FALSE);
|
|---|
| 205 |
|
|---|
| 206 | // goodbye windows!
|
|---|
| 207 | WinDestroyWindow (hwndSnapshot);
|
|---|
| 208 | WinDestroyWindow (hwndFrame);
|
|---|
| 209 |
|
|---|
| 210 | #ifdef _USEDLL_
|
|---|
| 211 | if (g_fQuiet)
|
|---|
| 212 | StopInputHook ();
|
|---|
| 213 | #endif
|
|---|
| 214 |
|
|---|
| 215 | delete g_phelp;
|
|---|
| 216 | delete pset;
|
|---|
| 217 |
|
|---|
| 218 | WinDestroyMsgQueue (hmq);
|
|---|
| 219 | WinTerminate (hab);
|
|---|
| 220 |
|
|---|
| 221 | #ifdef _DOLOGMEM_
|
|---|
| 222 | LogMem("main", FALSE);
|
|---|
| 223 | #endif
|
|---|
| 224 | #ifdef _DOLOGDEBUG_
|
|---|
| 225 | LogDebug( "Gotcha! end" );
|
|---|
| 226 | #endif
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | // ** DisplayError ******************************************************** /*FOLD00*/
|
|---|
| 230 |
|
|---|
| 231 | VOID DisplayError (PSZ pszTitle, PSZ psz, ...)
|
|---|
| 232 | {
|
|---|
| 233 | CHAR dstring[401];
|
|---|
| 234 | va_list valst;
|
|---|
| 235 |
|
|---|
| 236 | va_start (valst, psz);
|
|---|
| 237 | vsnprintf (dstring, 401, psz, valst);
|
|---|
| 238 | va_end (valst);
|
|---|
| 239 |
|
|---|
| 240 | WinMessageBox (HWND_DESKTOP, WinQueryActiveWindow (HWND_DESKTOP), dstring,
|
|---|
| 241 | pszTitle, 0, MB_OK | MB_ERROR | MB_APPLMODAL | MB_MOVEABLE);
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | // ** AddSysMenuItem ****************************************************** /*fold00*/
|
|---|
| 245 |
|
|---|
| 246 | VOID AddSysMenuItem (HWND hwndFrame, MENUITEM *Item, PSZ Text)
|
|---|
| 247 | {
|
|---|
| 248 | HWND hwndSysMenu = WinWindowFromID (hwndFrame, FID_SYSMENU);
|
|---|
| 249 | USHORT idSysMenu = SHORT1FROMMR (WinSendMsg (hwndSysMenu,
|
|---|
| 250 | MM_ITEMIDFROMPOSITION, NULL,
|
|---|
| 251 | NULL ));
|
|---|
| 252 | MENUITEM miSysMenu;
|
|---|
| 253 | WinSendMsg (hwndSysMenu, MM_QUERYITEM,
|
|---|
| 254 | MPFROM2SHORT (idSysMenu,FALSE), MPFROMP(&miSysMenu));
|
|---|
| 255 |
|
|---|
| 256 | HWND hwndSysSubMenu = miSysMenu.hwndSubMenu;
|
|---|
| 257 |
|
|---|
| 258 | WinSendMsg (hwndSysSubMenu, MM_INSERTITEM, MPFROMP(Item), MPFROMP(Text));
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | // ** DoCountdown ********************************************************* /*fold00*/
|
|---|
| 262 |
|
|---|
| 263 | VOID DoCountdown (ULONG ul)
|
|---|
| 264 | {
|
|---|
| 265 | if (ul > 10)
|
|---|
| 266 | DosBeep (4000L-3000L, 20);
|
|---|
| 267 | else
|
|---|
| 268 | DosBeep (4000L-ul*300L, 20);
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | // ** SetIdlePriority **************************************************** /*FOLD00*/
|
|---|
| 272 |
|
|---|
| 273 | VOID SetIdlePriority (BOOL f)
|
|---|
| 274 | {
|
|---|
| 275 | if (f)
|
|---|
| 276 | DosSetPriority(PRTYS_PROCESS, PRTYC_IDLETIME, 0, 0);
|
|---|
| 277 | else
|
|---|
| 278 | DosSetPriority(PRTYS_PROCESS, PRTYC_REGULAR, 0, 0);
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 | // ***********************************************************************
|
|---|
| 282 |
|
|---|
| 283 | #ifdef _DOLOGMEM_
|
|---|
| 284 | VOID LogMem (PSZ psz, BOOL f)
|
|---|
| 285 | {
|
|---|
| 286 | FILE *pf = fopen("gotcha.mem","ab");
|
|---|
| 287 | static ULONG TotalPhysicalMemory, ul = 0;
|
|---|
| 288 | ULONG i;
|
|---|
| 289 | if (!f)
|
|---|
| 290 | ul--;
|
|---|
| 291 | DosQuerySysInfo(QSV_TOTAVAILMEM, QSV_TOTAVAILMEM, &TotalPhysicalMemory,
|
|---|
| 292 | sizeof(TotalPhysicalMemory));
|
|---|
| 293 | for (i = 0; i < ul; i++)
|
|---|
| 294 | fputs(" ", pf);
|
|---|
| 295 | fprintf(pf,"%10ld (%s)\n", TotalPhysicalMemory, psz);
|
|---|
| 296 | if (f)
|
|---|
| 297 | ul++;
|
|---|
| 298 | fclose(pf);
|
|---|
| 299 | }
|
|---|
| 300 | #endif
|
|---|
| 301 |
|
|---|
| 302 | #ifdef _DOLOGDEBUG_
|
|---|
| 303 | VOID LogDebug( PSZ psz, ... )
|
|---|
| 304 | {
|
|---|
| 305 | CHAR dstring[401];
|
|---|
| 306 | va_list valst;
|
|---|
| 307 |
|
|---|
| 308 | va_start (valst, psz);
|
|---|
| 309 | vsnprintf (dstring, 401, psz, valst);
|
|---|
| 310 | va_end (valst);
|
|---|
| 311 |
|
|---|
| 312 | FILE *pf = fopen( "gotcha.log", "ab" );
|
|---|
| 313 | fprintf( pf, "%s\n", dstring );
|
|---|
| 314 | fclose( pf );
|
|---|
| 315 | }
|
|---|
| 316 | #endif
|
|---|
| 317 |
|
|---|
| 318 | // ***********************************************************************
|
|---|