Changed _FILENAME_H to FILENAME_H_INCLUDED.
[privoxy.git] / w32log.c
1 const char w32log_rcs[] = "$Id: w32log.c,v 1.13 2001/07/19 19:15:14 haroon Exp $";
2 /*********************************************************************
3  *
4  * File        :  $Source: /cvsroot/ijbswa/current/w32log.c,v $
5  *
6  * Purpose     :  Functions for creating and destroying the log window,
7  *                ouputting strings, processing messages and so on.
8  *
9  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
10  *                IJBSWA team.  http://ijbswa.sourceforge.net
11  *
12  *                Written by and Copyright (C) 1999 Adam Lock
13  *                <locka@iol.ie>
14  *
15  *                This program is free software; you can redistribute it 
16  *                and/or modify it under the terms of the GNU General
17  *                Public License as published by the Free Software
18  *                Foundation; either version 2 of the License, or (at
19  *                your option) any later version.
20  *
21  *                This program is distributed in the hope that it will
22  *                be useful, but WITHOUT ANY WARRANTY; without even the
23  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
24  *                PARTICULAR PURPOSE.  See the GNU General Public
25  *                License for more details.
26  *
27  *                The GNU General Public License should be included with
28  *                this file.  If not, you can view it at
29  *                http://www.gnu.org/copyleft/gpl.html
30  *                or write to the Free Software Foundation, Inc., 59
31  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
32  *
33  * Revisions   :
34  *    $Log: w32log.c,v $
35  *    Revision 1.13  2001/07/19 19:15:14  haroon
36  *    - Added a FIXME for EditFile but didn't fix :-)
37  *
38  *    Revision 1.12  2001/07/13 14:04:59  oes
39  *    Removed all #ifdef PCRS
40  *
41  *    Revision 1.11  2001/06/07 23:08:12  jongfoster
42  *    Forward and ACL edit options removed.
43  *
44  *    Revision 1.10  2001/05/31 21:37:11  jongfoster
45  *    GUI changes to rename "permissions file" to "actions file".
46  *
47  *    Revision 1.9  2001/05/31 17:33:13  oes
48  *
49  *    CRLF -> LF
50  *
51  *    Revision 1.8  2001/05/29 09:50:24  jongfoster
52  *    Unified blocklist/imagelist/permissionslist.
53  *    File format is still under discussion, but the internal changes
54  *    are (mostly) done.
55  *
56  *    Also modified interceptor behaviour:
57  *    - We now intercept all URLs beginning with one of the following
58  *      prefixes (and *only* these prefixes):
59  *        * http://i.j.b/
60  *        * http://ijbswa.sf.net/config/
61  *        * http://ijbswa.sourceforge.net/config/
62  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
63  *    - Internal changes so that intercepted and fast redirect pages
64  *      are not replaced with an image.
65  *    - Interceptors now have the option to send a binary page direct
66  *      to the client. (i.e. ijb-send-banner uses this)
67  *    - Implemented show-url-info interceptor.  (Which is why I needed
68  *      the above interceptors changes - a typical URL is
69  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
70  *      The previous mechanism would not have intercepted that, and
71  *      if it had been intercepted then it then it would have replaced
72  *      it with an image.)
73  *
74  *    Revision 1.7  2001/05/26 01:26:34  jongfoster
75  *    New #define, WIN_GUI_EDIT, enables the (embryonic) Win32 GUI editor.
76  *    This #define cannot be set from ./configure - there's no point, it
77  *    doesn't work yet.  See feature request # 425722
78  *
79  *    Revision 1.6  2001/05/26 00:31:30  jongfoster
80  *    Fixing compiler warning about comparing signed/unsigned.
81  *
82  *    Revision 1.5  2001/05/26 00:28:36  jongfoster
83  *    Automatic reloading of config file.
84  *    Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
85  *    Most of the global variables have been moved to a new
86  *    struct configuration_spec, accessed through csp->config->globalname
87  *    Most of the globals remaining are used by the Win32 GUI.
88  *
89  *    Revision 1.4  2001/05/22 18:56:28  oes
90  *    CRLF -> LF
91  *
92  *    Revision 1.3  2001/05/20 15:07:54  jongfoster
93  *    File is now ignored if _WIN_CONSOLE is defined.
94  *
95  *    Revision 1.2  2001/05/20 01:21:20  jongfoster
96  *    Version 2.9.4 checkin.
97  *    - Merged popupfile and cookiefile, and added control over PCRS
98  *      filtering, in new "permissionsfile".
99  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
100  *      file error you now get a message box (in the Win32 GUI) rather
101  *      than the program exiting with no explanation.
102  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
103  *      skipping.
104  *    - Removed tabs from "config"
105  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
106  *    - Bumped up version number.
107  *
108  *    Revision 1.1.1.1  2001/05/15 13:59:07  oes
109  *    Initial import of version 2.9.3 source tree
110  *
111  *
112  *********************************************************************/
113 \f
114
115 #include "config.h"
116
117 #include <assert.h>
118 #include <stdio.h>
119
120 #include <windows.h>
121 #include <richedit.h>
122
123 #include "project.h"
124 #include "w32log.h"
125 #include "w32taskbar.h"
126 #include "w32rulesdlg.h"
127 #include "win32.h"
128 #include "w32res.h"
129 #include "jcc.h"
130 #include "miscutil.h"
131 #include "errlog.h"
132 #include "loadcfg.h"
133
134 const char w32res_h_rcs[] = W32RES_H_VERSION;
135
136 #ifdef __MINGW32__
137 #include "cygwin.h"
138 const char cygwin_h_rcs[] = CYGWIN_H_VERSION;
139 #endif
140
141 const char w32log_h_rcs[] = W32LOG_H_VERSION;
142
143 #ifndef _WIN_CONSOLE /* entire file */
144
145 /*
146  * Timers and the various durations
147  */
148 #define TIMER_ANIM_ID               1
149 #define TIMER_ANIM_TIME             100
150 #define TIMER_ANIMSTOP_ID           2
151 #define TIMER_ANIMSTOP_TIME         1000
152 #define TIMER_CLIPBUFFER_ID         3
153 #define TIMER_CLIPBUFFER_TIME       1000
154 #define TIMER_CLIPBUFFER_FORCE_ID   4
155 #define TIMER_CLIPBUFFER_FORCE_TIME 5000
156
157 /*
158  * Styles of text that can be output
159  */
160 #define STYLE_NONE      0
161 #define STYLE_HIGHLIGHT 1
162 #define STYLE_LINK      2
163 #define STYLE_HEADER    3
164
165 /*
166  * Number of frames of animation in tray activity sequence
167  */
168 #define ANIM_FRAMES 8
169
170 #define DEFAULT_MAX_BUFFER_LINES    200
171 #define DEFAULT_LOG_FONT_NAME       "MS Sans Serif"
172 #define DEFAULT_LOG_FONT_SIZE       8
173
174 /*
175  * These values affect the way the log window behaves, they should be read
176  * from a file but for the moment, they are hardcoded here. Some options are
177  * configurable through the UI.
178  */
179
180 /* Indicates whether task bar shows activity animation */
181 BOOL g_bShowActivityAnimation = 1;
182
183 /* Indicates if the log window appears on the task bar */
184 BOOL g_bShowOnTaskBar = 0;
185
186 /* Indicates whether closing the log window really just hides it */
187 BOOL g_bCloseHidesWindow = 1;
188
189 /* Indicates if messages are logged at all */
190 BOOL g_bLogMessages = 1;
191
192 /* Indicates whether log messages are highlighted */
193 BOOL g_bHighlightMessages = 1;
194
195 /* Indicates if buffer is limited in size */
196 BOOL g_bLimitBufferSize = 1;
197
198 /* Maximum number of lines allowed in buffer when limited */
199 int g_nMaxBufferLines = DEFAULT_MAX_BUFFER_LINES;
200
201 /* Font to use */
202 char g_szFontFaceName[255] = DEFAULT_LOG_FONT_NAME;
203
204 /* Size of font to use */
205 int g_nFontSize = DEFAULT_LOG_FONT_SIZE;
206
207
208 /* FIXME: this is a kludge */
209
210 const char * g_actions_file = NULL;
211 const char * g_re_filterfile = NULL;
212 #ifdef TRUST_FILES
213 const char * g_trustfile = NULL;
214 #endif /* def TRUST_FILES */
215
216 /* FIXME: end kludge */
217
218
219 #ifdef REGEX
220 /* Regular expression for detected URLs */
221 #define RE_URL "http:[^ \n\r]*"
222
223 /*
224  * Regular expressions that are used to perform highlight in the log window
225  */
226 static struct _Pattern
227 {
228    const char *str;
229    int style;
230    regex_t buffer;
231 } patterns_to_highlight[] =
232 {
233    /* url headers */
234    { RE_URL,                STYLE_LINK },
235 /* { "[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[^ \n\r]*", STYLE_LINK }, */
236    /* interesting text to highlight */
237    { "crunch!",           STYLE_HIGHLIGHT },
238    /* http headers */
239    { "referer:",            STYLE_HEADER },
240    { "proxy-connection:",   STYLE_HEADER },
241    { "proxy-agent:",        STYLE_HEADER },
242    { "user-agent:",         STYLE_HEADER },
243    { "host:",               STYLE_HEADER },
244    { "accept:",             STYLE_HEADER },
245    { "accept-encoding:",    STYLE_HEADER },
246    { "accept-language:",    STYLE_HEADER },
247    { "accept-charset:",     STYLE_HEADER },
248    { "accept-ranges:",      STYLE_HEADER },
249    { "date:",               STYLE_HEADER },
250    { "cache-control:",      STYLE_HEADER },
251    { "cache-last-checked:", STYLE_HEADER },
252    { "connection:",         STYLE_HEADER },
253    { "content-type",        STYLE_HEADER },
254    { "content-length",      STYLE_HEADER },
255    { "cookie",              STYLE_HEADER },
256    { "last-modified:",      STYLE_HEADER },
257    { "pragma:",             STYLE_HEADER },
258    { "server:",             STYLE_HEADER },
259    { "etag:",               STYLE_HEADER },
260    { "expires:",            STYLE_HEADER },
261    { "warning:",            STYLE_HEADER },
262    /* this is the terminator statement - do not delete! */
263    { NULL,                  STYLE_NONE }
264 };
265 #endif /* def REGEX */
266
267
268 /*
269  * Public variables
270  */
271 HWND g_hwndLogFrame;
272
273 /*
274  * Private variables
275  */
276 static CRITICAL_SECTION g_criticalsection;
277 static HWND g_hwndTray;
278 static HWND g_hwndLogBox;
279 static WNDPROC g_fnLogBox;
280 static HICON g_hiconAnim[ANIM_FRAMES];
281 static HICON g_hiconIdle;
282 static HICON g_hiconApp;
283 static int g_nAnimFrame;
284 static BOOL g_bClipPending = FALSE;
285 static int g_nRichEditVersion = 0;
286
287 /*
288  * Private functions
289  */
290 static HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow);
291 static HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance);
292 static LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
293 static LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
294 static LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
295 static BOOL InitRichEdit(void);
296 static void LogClipBuffer(void);
297 static void LogCreatePatternMatchingBuffers(void);
298 static void LogDestroyPatternMatchingBuffers(void);
299 static int LogPutStringNoMatch(const char *pszText, int style);
300
301
302 /*********************************************************************
303  *
304  * Function    :  InitLogWindow
305  *
306  * Description :  Initialise the log window.
307  *
308  * Parameters  :  None
309  *
310  * Returns     :  Always TRUE (there should be error checking on the resources).
311  *
312  *********************************************************************/
313 BOOL InitLogWindow(void)
314 {
315    int i;
316
317    /* Load the icons */
318    g_hiconIdle = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IDLE));
319    for (i = 0; i < ANIM_FRAMES; i++)
320    {
321       g_hiconAnim[i] = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER1 + i));
322    }
323    g_hiconApp = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_JUNKBUSTER));
324
325    /* Create the user interface */
326    g_hwndLogFrame = CreateLogWindow(g_hInstance, g_nCmdShow);
327    g_hwndTray = CreateTrayWindow(g_hInstance);
328    TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Junkbuster");
329
330    /* Create pattern matching buffers (for highlighting */
331    LogCreatePatternMatchingBuffers();
332
333    /* Create a critical section to protect multi-threaded access to certain things */
334    InitializeCriticalSection(&g_criticalsection);
335
336    return TRUE;
337
338 }
339
340
341 /*********************************************************************
342  *
343  * Function    :  TermLogWindow
344  *
345  * Description :  Cleanup the logwindow.
346  *
347  * Parameters  :  None
348  *
349  * Returns     :  N/A
350  *
351  *********************************************************************/
352 void TermLogWindow(void)
353 {
354    int i;
355
356    LogDestroyPatternMatchingBuffers();
357
358    TrayDeleteIcon(g_hwndTray, 1);
359    DeleteObject(g_hiconApp);
360    DeleteObject(g_hiconIdle);
361    for (i = 0; i < ANIM_FRAMES; i++)
362    {
363       DeleteObject(g_hiconAnim[i]);
364    }
365
366 }
367
368
369 /*********************************************************************
370  *
371  * Function    :  LogCreatePatternMatchingBuffers
372  *
373  * Description :  Compile the pattern matching buffers.
374  *
375  * Parameters  :  None
376  *
377  * Returns     :  N/A
378  *
379  *********************************************************************/
380 void LogCreatePatternMatchingBuffers(void)
381 {
382 #ifdef REGEX
383    int i;
384    for (i = 0; patterns_to_highlight[i].str != NULL; i++)
385    {
386       regcomp(&patterns_to_highlight[i].buffer, patterns_to_highlight[i].str, REG_ICASE);
387    }
388 #endif
389
390 }
391
392
393 /*********************************************************************
394  *
395  * Function    :  LogDestroyPatternMatchingBuffers
396  *
397  * Description :  Free up the pattern matching buffers.
398  *
399  * Parameters  :  None
400  *
401  * Returns     :  N/A
402  *
403  *********************************************************************/
404 void LogDestroyPatternMatchingBuffers(void)
405 {
406 #ifdef REGEX
407    int i;
408    for (i = 0; patterns_to_highlight[i].str != NULL; i++)
409    {
410       regfree(&patterns_to_highlight[i].buffer);
411    }
412 #endif
413
414 }
415
416
417 /*********************************************************************
418  *
419  * Function    :  LogGetURLUnderCursor
420  *
421  * Description :  Returns the URL from under the cursor (remember to free it!).
422  *
423  * Parameters  :  None
424  *
425  * Returns     :  NULL or a pointer to an URL string.
426  *
427  *********************************************************************/
428 char *LogGetURLUnderCursor(void)
429 {
430    char *szResult = NULL;
431 #ifdef REGEX
432    regex_t re;
433    POINT ptCursor;
434    POINTL ptl;
435    DWORD nPos;
436    DWORD nWordStart = 0;
437    DWORD nWordEnd = 0;
438
439    regcomp(&re, RE_URL, REG_ICASE);
440
441    /* Get the position of the cursor over the text window */
442    GetCursorPos(&ptCursor);
443    ScreenToClient(g_hwndLogBox, &ptCursor);
444    ptl.x = ptCursor.x;
445    ptl.y = ptCursor.y;
446
447    /* Search backwards and fowards to obtain the word that is highlighted */
448    nPos = LOWORD(SendMessage(g_hwndLogBox, EM_CHARFROMPOS, 0, (LPARAM) &ptl));
449    nWordStart = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_LEFT, nPos);
450    nWordEnd = SendMessage(g_hwndLogBox, EM_FINDWORDBREAK, WB_RIGHTBREAK, nPos);
451
452    /* Compare the string to the pattern */
453    if (nWordEnd > nWordStart)
454    {
455       TEXTRANGE range;
456       regmatch_t match;
457
458       range.chrg.cpMin = nWordStart;
459       range.chrg.cpMax = nWordEnd;
460       range.lpstrText = (LPSTR)zalloc(nWordEnd - nWordStart + 1);
461       SendMessage(g_hwndLogBox, EM_GETTEXTRANGE, 0, (LPARAM) &range);
462
463       if (regexec(&re, range.lpstrText, 1, &match, 0) == 0)
464       {
465          szResult = range.lpstrText;
466       }
467       else
468       {
469          free(range.lpstrText);
470       }
471
472       regfree(&re);
473    }
474 #endif
475    return szResult;
476
477 }
478
479
480 /*********************************************************************
481  *
482  * Function    :  LogPutString
483  *
484  * Description :  Inserts text into the logging window.  This is really
485  *                a REGEXP aware wrapper function to `LogPutStringNoMatch'.
486  *
487  * Parameters  :
488  *          1  :  pszText = pointer to string going to the log window
489  *
490  * Returns     :  1 => success, else the return code from `LogPutStringNoMatch'.
491  *                FIXME: this is backwards to the rest of IJB and to common
492  *                programming practice.  Please use 0 => success instead.
493  *
494  *********************************************************************/
495 int LogPutString(const char *pszText)
496 {
497 #ifdef REGEX
498    int i;
499 #endif
500    int result = 0;
501
502    if (pszText == NULL || strlen(pszText) == 0)
503    {
504       return 1;
505    }
506
507    if (!g_bLogMessages)
508    {
509       return 1;
510    }
511
512    /* Critical section stops multiple threads doing nasty interactions that
513     * foul up the highlighting and output.
514     */
515    EnterCriticalSection(&g_criticalsection);
516
517 #ifdef REGEX
518    if (g_bHighlightMessages)
519    {
520       regmatch_t match;
521
522       /* First things first, regexp scan for various things that we would like highlighted */
523       for (i = 0; patterns_to_highlight[i].str != NULL; i++)
524       {
525          if (regexec(&patterns_to_highlight[i].buffer, pszText, 1, &match, 0) == 0)
526          {
527             char *pszBefore = NULL;
528             char *pszMatch = NULL;
529             char *pszAfter = NULL;
530             int nMatchSize;
531
532             /* Split the string up into pieces representing the strings, before
533                at and after the matching pattern
534              */
535             if (match.rm_so > 0)
536             {
537                pszBefore = (char *)malloc((match.rm_so + 1) * sizeof(char));
538                memset(pszBefore, 0, (match.rm_so + 1) * sizeof(char));
539                strncpy(pszBefore, pszText, match.rm_so);
540             }
541             if (match.rm_eo < (regoff_t)strlen(pszText))
542             {
543                pszAfter = strdup(&pszText[match.rm_eo]);
544             }
545             nMatchSize = match.rm_eo - match.rm_so;
546             pszMatch = (char *)malloc(nMatchSize + 1);
547             strncpy(pszMatch, &pszText[match.rm_so], nMatchSize);
548             pszMatch[nMatchSize] = '\0';
549
550             /* Recursively call LogPutString */
551             if (pszBefore)
552             {
553                LogPutString(pszBefore);
554                free(pszBefore);
555             }
556             if (pszMatch)
557             {
558                LogPutStringNoMatch(pszMatch, patterns_to_highlight[i].style);
559                free(pszMatch);
560             }
561             if (pszAfter)
562             {
563                LogPutString(pszAfter);
564                free(pszAfter);
565             }
566
567             result = 1;
568             goto end;
569          }
570       }
571    }
572 #endif
573
574    result = LogPutStringNoMatch(pszText, STYLE_NONE);
575
576 #ifdef REGEX
577 end:
578 #endif
579    LeaveCriticalSection(&g_criticalsection);
580
581    return result;
582
583 }
584
585
586 /*********************************************************************
587  *
588  * Function    :  LogPutStringNoMatch
589  *
590  * Description :  Puts a string into the logging window.
591  *
592  * Parameters  :
593  *          1  :  pszText = pointer to string going to the log window
594  *          2  :  style = STYLE_NONE, STYLE_HEADER, STYLE_HIGHLIGHT, or STYLE_LINK
595  *
596  * Returns     :  Always 1 => success.
597  *                FIXME: this is backwards to the rest of IJB and to common
598  *                programming practice.  Please use 0 => success instead.
599  *
600  *********************************************************************/
601 int LogPutStringNoMatch(const char *pszText, int style)
602 {
603    CHARRANGE range;
604    CHARFORMAT format;
605    int nTextLength;
606
607    assert(g_hwndLogBox);
608    if (g_hwndLogBox == NULL)
609    {
610       return 1;
611    }
612
613    /* TODO preserve existing selection */
614
615    /* Go to the end of the text */
616    nTextLength = GetWindowTextLength(g_hwndLogBox);
617    range.cpMin = nTextLength;
618    range.cpMax = nTextLength;
619    SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
620
621    /* Apply a formatting style */
622    memset(&format, 0, sizeof(format));
623    format.cbSize = sizeof(format);
624    format.dwMask = CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_ITALIC | CFM_COLOR | CFM_FACE | CFM_SIZE;
625    format.yHeight = (g_nFontSize * 1440) / 72;
626    strcpy(format.szFaceName, g_szFontFaceName);
627    if (style == STYLE_NONE)
628    {
629       /* DO NOTHING */
630       format.dwEffects |= CFE_AUTOCOLOR;
631    }
632    else if (style == STYLE_HEADER)
633    {
634       format.dwEffects |= CFE_AUTOCOLOR | CFE_ITALIC;
635    }
636    else if (style == STYLE_HIGHLIGHT)
637    {
638       format.dwEffects |= CFE_AUTOCOLOR | CFE_BOLD;
639    }
640    else if (style == STYLE_LINK)
641    {
642       format.dwEffects |= CFE_UNDERLINE;
643       format.crTextColor = RGB(0, 0, 255);
644    }
645    SendMessage(g_hwndLogBox, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
646
647    /* Append text to the end */
648    SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) pszText);
649
650    /* TODO Restore the old selection */
651
652    /* Purge buffer */
653    if (strchr(pszText, '\n') != NULL)
654    {
655       SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID, TIMER_CLIPBUFFER_TIME, NULL);
656       if (!g_bClipPending)
657       {
658          /* Set the force clip timer going. This timer ensures clipping is done
659             intermittently even when there is a sustained burst of logging
660          */
661          SetTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID, TIMER_CLIPBUFFER_FORCE_TIME, NULL);
662       }
663       g_bClipPending = TRUE;
664    }
665
666    return 1;
667
668 }
669
670
671 /*********************************************************************
672  *
673  * Function    :  LogShowActivity
674  *
675  * Description :  Start the spinner.
676  *
677  * Parameters  :  None
678  *
679  * Returns     :  N/A
680  *
681  *********************************************************************/
682 void LogShowActivity(void)
683 {
684    /* Start some activity timers */
685    if (g_bShowActivityAnimation)
686    {
687       SetTimer(g_hwndLogFrame, TIMER_ANIM_ID, TIMER_ANIM_TIME, NULL);
688       SetTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID, TIMER_ANIMSTOP_TIME, NULL);
689    }
690
691 }
692
693
694 /*********************************************************************
695  *
696  * Function    :  LogClipBuffer
697  *
698  * Description :  Prunes old lines from the log.
699  *
700  * Parameters  :  None
701  *
702  * Returns     :  N/A
703  *
704  *********************************************************************/
705 void LogClipBuffer(void)
706 {
707    int nLines = SendMessage(g_hwndLogBox, EM_GETLINECOUNT, 0, 0);
708    if (g_bLimitBufferSize && nLines > g_nMaxBufferLines)
709    {
710       /* Compute the range representing the lines to be deleted */
711       LONG nLastLineToDelete = nLines - g_nMaxBufferLines;
712       LONG nLastChar = SendMessage(g_hwndLogBox, EM_LINEINDEX, nLastLineToDelete, 0);
713       CHARRANGE range;
714       range.cpMin = 0;
715       range.cpMax = nLastChar;
716
717       /* TODO get current selection */
718
719       /* TODO adjust and clip old selection against range to be deleted */
720
721       /* Select range and erase it (turning off autoscroll to prevent
722          nasty scrolling) */
723       SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
724       SendMessage(g_hwndLogBox, EM_EXSETSEL, 0, (LPARAM) &range);
725       SendMessage(g_hwndLogBox, EM_REPLACESEL, FALSE, (LPARAM) "");
726       SendMessage(g_hwndLogBox, EM_SETOPTIONS, ECOOP_XOR, ECO_AUTOVSCROLL);
727
728       /* Restore old selection */
729    }
730
731 }
732
733
734 /*********************************************************************
735  *
736  * Function    :  CreateHiddenLogOwnerWindow
737  *
738  * Description :  Creates a hidden owner window that stops the log
739  *                window appearing in the task bar.
740  *
741  * Parameters  :
742  *          1  :  hInstance = application's instance handle
743  *
744  * Returns     :  Handle to newly created window.
745  *
746  *********************************************************************/
747 HWND CreateHiddenLogOwnerWindow(HINSTANCE hInstance)
748 {
749    static const char *szWndName = "JunkbusterLogLogOwner";
750    WNDCLASS wc;
751    HWND hwnd;
752
753    wc.style          = 0;
754    wc.lpfnWndProc    = LogOwnerWindowProc;
755    wc.cbClsExtra     = 0;
756    wc.cbWndExtra     = 0;
757    wc.hInstance      = hInstance;
758    wc.hIcon          = 0;
759    wc.hCursor        = 0;
760    wc.hbrBackground  = 0;
761    wc.lpszMenuName   = 0;
762    wc.lpszClassName  = szWndName;
763
764    RegisterClass(&wc);
765
766    hwnd = CreateWindow(szWndName, szWndName,
767       WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
768       CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
769
770    return hwnd;
771
772 }
773
774
775 /*********************************************************************
776  *
777  * Function    :  LogOwnerWindowProc
778  *
779  * Description :  Dummy procedure that does nothing special.
780  *
781  * Parameters  :
782  *          1  :  hwnd = window handle
783  *          2  :  uMsg = message number
784  *          3  :  wParam = first param for this message
785  *          4  :  lParam = next param for this message
786  *
787  * Returns     :  Same as `DefWindowProc'.
788  *
789  *********************************************************************/
790 LRESULT CALLBACK LogOwnerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
791 {
792    return DefWindowProc(hwnd, uMsg, wParam, lParam);
793
794 }
795
796
797 /*********************************************************************
798  *
799  * Function    :  CreateLogWindow
800  *
801  * Description :  Create the logging window.
802  *
803  * Parameters  :
804  *          1  :  hInstance = application's instance handle
805  *          2  :  nCmdShow = window show value (MIN, MAX, NORMAL, etc...)
806  *
807  * Returns     :  Handle to newly created window.
808  *
809  *********************************************************************/
810 HWND CreateLogWindow(HINSTANCE hInstance, int nCmdShow)
811 {
812    static const char *szWndName = "JunkbusterLogWindow";
813    static const char *szWndTitle = "Junkbuster";
814
815    HWND hwnd = NULL;
816    HWND hwndOwner = (g_bShowOnTaskBar) ? NULL : CreateHiddenLogOwnerWindow(hInstance);
817    HWND hwndChild = NULL;
818    RECT rcClient;
819    WNDCLASSEX wc;
820
821    memset(&wc, 0, sizeof(wc));
822    wc.cbSize         = sizeof(wc);
823    wc.style          = CS_DBLCLKS;
824    wc.lpfnWndProc    = LogWindowProc;
825    wc.cbClsExtra     = 0;
826    wc.cbWndExtra     = 0;
827    wc.hInstance      = hInstance;
828    wc.hIcon          = g_hiconApp;
829    wc.hCursor        = 0;
830    wc.hbrBackground  = 0;
831    wc.lpszMenuName   = MAKEINTRESOURCE(IDR_LOGVIEW);
832    wc.lpszClassName  = szWndName;
833    wc.hbrBackground  = GetStockObject(WHITE_BRUSH);
834    RegisterClassEx(&wc);
835
836    hwnd = CreateWindowEx(WS_EX_APPWINDOW, szWndName, szWndTitle,
837       WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
838       CW_USEDEFAULT, hwndOwner, NULL, hInstance, NULL);
839
840    /* Now create a child list box */
841    GetClientRect(hwnd, &rcClient);
842
843    /* Create a rich edit control */
844    InitRichEdit();
845    g_hwndLogBox = CreateWindowEx(0, (g_nRichEditVersion == 0x0100) ? "RichEdit" : RICHEDIT_CLASS, "",
846       ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | ES_NOHIDESEL | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE,
847       rcClient.left, rcClient.top, rcClient.right, rcClient.bottom,
848       hwnd, NULL, hInstance, NULL);
849 /* SendMessage(g_hwndLogBox, EM_SETWORDWRAPMODE, 0, 0); */
850
851    /* Subclass the control to catch certain messages */
852    g_fnLogBox = (WNDPROC) GetWindowLong(g_hwndLogBox, GWL_WNDPROC);
853    SetWindowLong(g_hwndLogBox, GWL_WNDPROC, (LONG) LogRichEditProc);
854
855    /* Minimizing looks stupid when the log window is not on the task bar, so hide instead */
856    if (!g_bShowOnTaskBar &&
857          (nCmdShow == SW_SHOWMINIMIZED ||
858           nCmdShow == SW_MINIMIZE ||
859           nCmdShow == SW_SHOWMINNOACTIVE))
860    {
861       nCmdShow = SW_HIDE;
862    }
863
864    ShowWindow(hwnd, nCmdShow);
865    UpdateWindow(hwnd);
866
867    GetClientRect(g_hwndLogFrame, &rcClient);
868    SetWindowPos(g_hwndLogBox, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_NOZORDER);
869
870    return hwnd;
871
872 }
873
874
875 /*********************************************************************
876  *
877  * Function    :  InitRichEdit
878  *
879  * Description :  Initialise the rich edit control library.
880  *
881  * Parameters  :  None
882  *
883  * Returns     :  TRUE => success, FALSE => failure.
884  *                FIXME: this is backwards to the rest of IJB and to common
885  *                programming practice.  Please use 0 => success instead.
886  *
887  *********************************************************************/
888 BOOL InitRichEdit(void)
889 {
890    static HINSTANCE hInstRichEdit;
891    if (hInstRichEdit == NULL)
892    {
893       g_nRichEditVersion = 0;
894       hInstRichEdit = LoadLibraryA("RICHED20.DLL");
895       if (hInstRichEdit)
896       {
897          g_nRichEditVersion = _RICHEDIT_VER;
898       }
899       else
900       {
901          hInstRichEdit = LoadLibraryA("RICHED32.DLL");
902          if (hInstRichEdit)
903          {
904             g_nRichEditVersion = 0x0100;
905          }
906       }
907    }
908    return (hInstRichEdit != NULL) ? TRUE : FALSE;
909
910 }
911
912
913 /*********************************************************************
914  *
915  * Function    :  ShowLogWindow
916  *
917  * Description :  Shows or hides the log window.  We will also raise the
918  *                window on a show command in case it is buried.
919  *
920  * Parameters  :
921  *          1  :  bShow = TRUE to show, FALSE to mimize/hide
922  *
923  * Returns     :  N/A
924  *
925  *********************************************************************/
926 void ShowLogWindow(BOOL bShow)
927 {
928    if (bShow)
929    {
930       SetForegroundWindow(g_hwndLogFrame);
931       SetWindowPos(g_hwndLogFrame, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
932    }
933    else if (g_bShowOnTaskBar)
934    {
935       ShowWindow(g_hwndLogFrame, SW_MINIMIZE);
936    }
937    else
938    {
939       ShowWindow(g_hwndLogFrame, SW_HIDE);
940    }
941
942 }
943
944
945 /*********************************************************************
946  *
947  * Function    :  EditFile
948  *
949  * Description :  Opens the specified setting file for editing.
950  * FIXME: What if the file has no associated application. Check for return values
951 *        from ShellExecute??
952  *
953  * Parameters  :
954  *          1  :  filename = filename from the config (aka junkbstr.txt) file.
955  *
956  * Returns     :  N/A
957  *
958  *********************************************************************/
959 void EditFile(const char *filename)
960 {
961    if (filename)
962    {
963       ShellExecute(g_hwndLogFrame, "open", filename, NULL, NULL, SW_SHOWNORMAL);
964    }
965
966 }
967
968
969 /*--------------------------------------------------------------------------*/
970 /* Windows message handlers                                                 */
971 /*--------------------------------------------------------------------------*/
972
973
974 /*********************************************************************
975  *
976  * Function    :  OnLogRButtonUp
977  *
978  * Description :  Handler for WM_RBUTTONUP messages.
979  *
980  * Parameters  :
981  *          1  :  nModifier = wParam from mouse message (unused)
982  *          2  :  x = x coordinate of the mouse event
983  *          3  :  y = y coordinate of the mouse event
984  *
985  * Returns     :  N/A
986  *
987  *********************************************************************/
988 void OnLogRButtonUp(int nModifier, int x, int y)
989 {
990    HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_POPUP_SELECTION));
991    if (hMenu != NULL)
992    {
993       HMENU hMenuPopup = GetSubMenu(hMenu, 0);
994 #ifdef WIN_GUI_EDIT
995       char *szURL;
996 #endif /* def WIN_GUI_EDIT */
997
998       /* Check if there is a selection */
999       CHARRANGE range;
1000       SendMessage(g_hwndLogBox, EM_EXGETSEL, 0, (LPARAM) &range);
1001       if (range.cpMin == range.cpMax)
1002       {
1003          EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
1004       }
1005       else
1006       {
1007          EnableMenuItem(hMenuPopup, ID_EDIT_COPY, MF_BYCOMMAND | MF_ENABLED);
1008       }
1009
1010 #ifdef WIN_GUI_EDIT
1011       /* Check if cursor is over a link */
1012       szURL = LogGetURLUnderCursor();
1013       if (szURL)
1014       {
1015          MENUITEMINFO item;
1016          TCHAR szMenuItemTemplate[1000];
1017          char *szMenuItem;
1018
1019          memset(&item, 0, sizeof(item));
1020          item.cbSize = sizeof(item);
1021          item.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
1022          item.fType = MFT_STRING;
1023          item.fState = MFS_ENABLED;
1024          item.wID = ID_NEW_BLOCKER;
1025
1026          /* Put the item into the menu */
1027          memset(szMenuItemTemplate, 0, sizeof(szMenuItemTemplate));
1028          LoadString(g_hInstance, IDS_NEW_BLOCKER, szMenuItemTemplate, sizeof(szMenuItemTemplate) / sizeof(szMenuItemTemplate[0]));
1029
1030          szMenuItem = (char *)malloc(strlen(szMenuItemTemplate) + strlen(szURL) + 1);
1031          sprintf(szMenuItem, szMenuItemTemplate, szURL);
1032
1033          item.dwTypeData = szMenuItem;
1034          item.cch = strlen(szMenuItem);
1035
1036          InsertMenuItem(hMenuPopup, 1, TRUE, &item);
1037
1038          SetDefaultRule(szURL);
1039
1040          free(szURL);
1041       }
1042 #endif /* def WIN_GUI_EDIT */
1043
1044       /* Display the popup */
1045       TrackPopupMenu(hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, x, y, 0, g_hwndLogFrame, NULL);
1046       DestroyMenu(hMenu);
1047    }
1048
1049 }
1050
1051
1052 /*********************************************************************
1053  *
1054  * Function    :  OnLogCommand
1055  *
1056  * Description :  Handler for WM_COMMAND messages.
1057  *
1058  * Parameters  :
1059  *          1  :  nCommand = the command portion of the menu selection event
1060  *
1061  * Returns     :  N/A
1062  *
1063  *********************************************************************/
1064 void OnLogCommand(int nCommand)
1065 {
1066    switch (nCommand)
1067    {
1068       case ID_SHOWWINDOW:
1069          ShowLogWindow(TRUE);
1070          break;
1071
1072       case ID_FILE_EXIT:
1073          PostMessage(g_hwndLogFrame, WM_CLOSE, 0, 0);
1074          break;
1075
1076       case ID_EDIT_COPY:
1077          SendMessage(g_hwndLogBox, WM_COPY, 0, 0);
1078          break;
1079
1080       case ID_VIEW_CLEARLOG:
1081          SendMessage(g_hwndLogBox, WM_SETTEXT, 0, (LPARAM) "");
1082          break;
1083
1084       case ID_VIEW_LOGMESSAGES:
1085          g_bLogMessages = !g_bLogMessages;
1086          /* SaveLogSettings(); */
1087          break;
1088
1089       case ID_VIEW_MESSAGEHIGHLIGHTING:
1090          g_bHighlightMessages = !g_bHighlightMessages;
1091          /* SaveLogSettings(); */
1092          break;
1093
1094       case ID_VIEW_LIMITBUFFERSIZE:
1095          g_bLimitBufferSize = !g_bLimitBufferSize;
1096          /* SaveLogSettings(); */
1097          break;
1098
1099       case ID_VIEW_ACTIVITYANIMATION:
1100          g_bShowActivityAnimation = !g_bShowActivityAnimation;
1101          /* SaveLogSettings(); */
1102          break;
1103
1104 #ifdef TOGGLE
1105       /* by haroon - change toggle to its opposite value */
1106       case ID_TOGGLE_IJB:
1107          g_bToggleIJB = !g_bToggleIJB;
1108          if (g_bToggleIJB)
1109          {
1110             log_error(LOG_LEVEL_INFO, "Now toggled ON.");
1111          }
1112          else
1113          {
1114             log_error(LOG_LEVEL_INFO, "Now toggled OFF.");
1115          }
1116          break;
1117 #endif
1118
1119       case ID_TOOLS_EDITJUNKBUSTER:
1120          EditFile(configfile);
1121          break;
1122
1123       case ID_TOOLS_EDITACTIONS:
1124          EditFile(g_actions_file);
1125          break;
1126
1127       case ID_TOOLS_EDITPERLRE:
1128          EditFile(g_re_filterfile);
1129          break;
1130
1131 #ifdef TRUST_FILES
1132       case ID_TOOLS_EDITTRUST:
1133          EditFile(g_trustfile);
1134          break;
1135 #endif /* def TRUST_FILES */
1136
1137 #ifdef WIN_GUI_EDIT
1138       case ID_NEW_BLOCKER:
1139          ShowRulesDialog(g_hwndLogFrame);
1140          break;
1141 #endif /* def WIN_GUI_EDIT */
1142
1143       case ID_HELP_GPL:
1144          ShellExecute(g_hwndLogFrame, "open", "gpl.html", NULL, NULL, SW_SHOWNORMAL);
1145          break;
1146
1147       case ID_HELP_FAQ:
1148          ShellExecute(g_hwndLogFrame, "open", "ijbfaq.html", NULL, NULL, SW_SHOWNORMAL);
1149          break;
1150
1151       case ID_HELP_MANUAL:
1152          ShellExecute(g_hwndLogFrame, "open", "ijbman.html", NULL, NULL, SW_SHOWNORMAL);
1153          break;
1154
1155       case ID_HELP_STATUS:
1156          ShellExecute(g_hwndLogFrame, "open", "Junkbuster Status.URL", NULL, NULL, SW_SHOWNORMAL);
1157          break;
1158
1159       case ID_HELP_ABOUTJUNKBUSTER:
1160          MessageBox(g_hwndLogFrame, win32_blurb, "Junkbuster Information", MB_OK);
1161          break;
1162
1163       default:
1164          /* DO NOTHING */
1165          break;
1166    }
1167
1168 }
1169
1170
1171 /*********************************************************************
1172  *
1173  * Function    :  OnLogInitMenu
1174  *
1175  * Description :  Handler for WM_INITMENU messages.  Enable, disable,
1176  *                check, and/or uncheck menu options as apropos.
1177  *
1178  * Parameters  :
1179  *          1  :  hmenu = handle to menu to "make current"
1180  *
1181  * Returns     :  N/A
1182  *
1183  *********************************************************************/
1184 void OnLogInitMenu(HMENU hmenu)
1185 {
1186    /* Only enable editors if there is a file to edit */
1187    EnableMenuItem(hmenu, ID_TOOLS_EDITACTIONS, MF_BYCOMMAND | (g_actions_file ? MF_ENABLED : MF_GRAYED));
1188    EnableMenuItem(hmenu, ID_TOOLS_EDITPERLRE, MF_BYCOMMAND | (g_re_filterfile ? MF_ENABLED : MF_GRAYED));
1189 #ifdef TRUST_FILES
1190    EnableMenuItem(hmenu, ID_TOOLS_EDITTRUST, MF_BYCOMMAND | (g_trustfile ? MF_ENABLED : MF_GRAYED));
1191 #endif /* def TRUST_FILES */
1192
1193    /* Check/uncheck options */
1194    CheckMenuItem(hmenu, ID_VIEW_LOGMESSAGES, MF_BYCOMMAND | (g_bLogMessages ? MF_CHECKED : MF_UNCHECKED));
1195    CheckMenuItem(hmenu, ID_VIEW_MESSAGEHIGHLIGHTING, MF_BYCOMMAND | (g_bHighlightMessages ? MF_CHECKED : MF_UNCHECKED));
1196    CheckMenuItem(hmenu, ID_VIEW_LIMITBUFFERSIZE, MF_BYCOMMAND | (g_bLimitBufferSize ? MF_CHECKED : MF_UNCHECKED));
1197    CheckMenuItem(hmenu, ID_VIEW_ACTIVITYANIMATION, MF_BYCOMMAND | (g_bShowActivityAnimation ? MF_CHECKED : MF_UNCHECKED));
1198 #ifdef TOGGLE
1199    /* by haroon - menu item for Enable toggle on/off */
1200    CheckMenuItem(hmenu, ID_TOGGLE_IJB, MF_BYCOMMAND | (g_bToggleIJB ? MF_CHECKED : MF_UNCHECKED));
1201 #endif
1202
1203 }
1204
1205
1206 /*********************************************************************
1207  *
1208  * Function    :  OnLogTimer
1209  *
1210  * Description :  Handler for WM_TIMER messages.
1211  *
1212  * Parameters  :
1213  *          1  :  nTimer = timer id (animation start/stop or clip buffer)
1214  *
1215  * Returns     :  N/A
1216  *
1217  *********************************************************************/
1218 void OnLogTimer(int nTimer)
1219 {
1220    switch (nTimer)
1221    {
1222       case TIMER_ANIM_ID:
1223          TraySetIcon(g_hwndTray, 1, g_hiconAnim[g_nAnimFrame++ % ANIM_FRAMES]);
1224          break;
1225
1226       case TIMER_ANIMSTOP_ID:
1227          g_nAnimFrame = 0;
1228          TraySetIcon(g_hwndTray, 1, g_hiconIdle);
1229          KillTimer(g_hwndLogFrame, TIMER_ANIM_ID);
1230          KillTimer(g_hwndLogFrame, TIMER_ANIMSTOP_ID);
1231          break;
1232
1233       case TIMER_CLIPBUFFER_ID:
1234       case TIMER_CLIPBUFFER_FORCE_ID:
1235          LogClipBuffer();
1236          g_bClipPending = FALSE;
1237          KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_ID);
1238          KillTimer(g_hwndLogFrame, TIMER_CLIPBUFFER_FORCE_ID);
1239          break;
1240
1241       default:
1242          /* DO NOTHING */
1243          break;
1244    }
1245
1246 }
1247
1248
1249 /*********************************************************************
1250  *
1251  * Function    :  LogRichEditProc
1252  *
1253  * Description :  Window subclass routine handles some events for the rich edit control.
1254  *
1255  * Parameters  :
1256  *          1  :  hwnd = window handle of the rich edit control
1257  *          2  :  uMsg = message number
1258  *          3  :  wParam = first param for this message
1259  *          4  :  lParam = next param for this message
1260  *
1261  * Returns     :  Appropriate M$ window message handler codes.
1262  *
1263  *********************************************************************/
1264 LRESULT CALLBACK LogRichEditProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1265 {
1266    switch (uMsg)
1267    {
1268       case WM_RBUTTONUP:
1269       {
1270          POINT pt;
1271          pt.x = LOWORD(lParam);
1272          pt.y = HIWORD(lParam);
1273          ClientToScreen(hwnd, &pt);
1274          OnLogRButtonUp(wParam, pt.x, pt.y);
1275       }
1276       return 0;
1277    }
1278    return CallWindowProc(g_fnLogBox, hwnd, uMsg, wParam, lParam);
1279
1280 }
1281
1282
1283 /*********************************************************************
1284  *
1285  * Function    :  LogWindowProc
1286  *
1287  * Description :  Windows call back routine handles events on the log window.
1288  *
1289  * Parameters  :
1290  *          1  :  hwnd = handle of the logging window
1291  *          2  :  uMsg = message number
1292  *          3  :  wParam = first param for this message
1293  *          4  :  lParam = next param for this message
1294  *
1295  * Returns     :  Appropriate M$ window message handler codes.
1296  *
1297  *********************************************************************/
1298 LRESULT CALLBACK LogWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1299 {
1300    switch (uMsg)
1301    {
1302       case WM_CREATE:
1303          return 0;
1304
1305       case WM_CLOSE:
1306          /* This is the end - beautiful friend - the end */
1307          DestroyWindow(g_hwndLogBox);
1308          DestroyWindow(g_hwndLogFrame);
1309          return 0;
1310
1311       case WM_DESTROY:
1312          PostQuitMessage(0);
1313          return 0;
1314
1315       case WM_SHOWWINDOW:
1316       case WM_SIZE:
1317          /* Resize the logging window to fit the new frame */
1318          if (g_hwndLogBox)
1319          {
1320             RECT rc;
1321             GetClientRect(g_hwndLogFrame, &rc);
1322             SetWindowPos(g_hwndLogBox, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER);
1323          }
1324          return 0;
1325
1326       case WM_INITMENU:
1327          OnLogInitMenu((HMENU) wParam);
1328          return 0;
1329
1330       case WM_TIMER:
1331          OnLogTimer(wParam);
1332          return 0;
1333
1334       case WM_COMMAND:
1335          OnLogCommand(LOWORD(wParam));
1336          return 0;
1337
1338       case WM_SYSCOMMAND:
1339          switch (wParam)
1340          {
1341             case SC_CLOSE:
1342                if (g_bCloseHidesWindow)
1343                {
1344                   ShowLogWindow(FALSE);
1345                   return 0;
1346                }
1347                break;
1348             case SC_MINIMIZE:
1349                ShowLogWindow(FALSE);
1350                return 0;
1351          }
1352          break;
1353    }
1354
1355    return DefWindowProc(hwnd, uMsg, wParam, lParam);
1356
1357 }
1358
1359 #endif /* ndef _WIN_CONSOLE - entire file */
1360
1361 /*
1362   Local Variables:
1363   tab-width: 3
1364   end:
1365 */