source: trunk/gotcha.cpp@ 10

Last change on this file since 10 was 10, checked in by Gregg Young, 8 years ago

The changes in these files were made to fix Open Watcom compiler, WRC and wipfc errors and warning. There are several more in the next commit.

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