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