OSDN Git Service

IM0036
[peercast-im/PeerCastIM.git] / c: / Git / PeerCast.root / PeerCast / ui / win32 / simple / Simple.cpp
1 // ------------------------------------------------
2 // File : simple.cpp
3 // Date: 4-apr-2002
4 // Author: giles
5 // Desc: 
6 //              Simple tray icon interface to PeerCast, mostly win32 related stuff.
7 //              
8 // (c) 2002 peercast.org
9 // ------------------------------------------------
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
14
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 // GNU General Public License for more details.
19 // ------------------------------------------------
20
21 #include <windows.h>
22 #include <direct.h> 
23 #include "stdafx.h"
24 #include "resource.h"
25 #include "gui.h"
26 #include "channel.h"
27 #include "servent.h"
28 #include "servmgr.h"
29 #include "win32/wsys.h"
30 #include "peercast.h"
31 #include "simple.h"
32 #include "version2.h"
33 #include "gdiplus.h"
34 #include "time.h"
35 #include "stats.h"
36 #include "sys.h"
37 #ifdef _DEBUG
38 #include "chkMemoryLeak.h"
39 #define DEBUG_NEW new(__FILE__, __LINE__)
40 #define new DEBUG_NEW
41 #endif
42
43 #define MAX_LOADSTRING 100
44
45 #define PLAY_CMD 7000
46 #define RELAY_CMD 8000
47 #define INFO_CMD 9000
48 #define URL_CMD 10000
49
50 #define MAX_CHANNELS 999
51
52
53 extern "C"
54 {
55         void loadIcons(HINSTANCE hInstance, HWND hWnd);
56 };
57
58 UINT g_iTaskbarCreated = ~0;    // for PCRaw (tray icon)
59
60 // PeerCast globals
61
62 static int currNotify=0;
63 String iniFileName;
64 HWND guiWnd;
65 HWND mainWnd;
66 static HMENU trayMenu = NULL,ltrayMenu = NULL;  // for PCRaw (tray icon)
67 bool showGUI=true;
68 bool allowMulti=false;
69 bool killMe=false;
70 bool allowTrayMenu=true;
71 static bool winDistinctionNT=false;
72 int             seenNewVersionTime=0;
73 HICON icon1,icon2;
74 ChanInfo chanInfo;
75 bool chanInfoIsRelayed;
76 //GnuID lastPlayID;
77 String exePath;
78 ULONG_PTR gdiplusToken;
79
80 extern Stats stats;
81 ThreadInfo trafficDlgThread;
82 HWND trafficDlg = NULL;
83 FileStream fs;
84
85 // \83v\83\8d\83g\83^\83C\83v\90é\8c¾
86 void createGUI(HWND);
87 LRESULT CALLBACK TrafficDlgProc(HWND, UINT, WPARAM, LPARAM);
88
89 // ---------------------------------
90 Sys * APICALL MyPeercastInst::createSys()
91 {
92         return new WSys(mainWnd);
93 }
94 // ---------------------------------
95 const char * APICALL MyPeercastApp ::getIniFilename()
96 {
97         return iniFileName.cstr();
98 }
99
100 // ---------------------------------
101 const char *APICALL MyPeercastApp ::getClientTypeOS() 
102 {
103         return PCX_OS_WIN32;
104 }
105
106 // ---------------------------------
107 const char * APICALL MyPeercastApp::getPath()
108 {
109         return exePath.cstr();
110 }
111
112 // --------------------------------- JP-EX
113 void    APICALL MyPeercastApp ::openLogFile()
114 {
115         logFile.openWriteReplace("log.txt");
116 }
117 // --------------------------------- JP-EX
118 void    APICALL MyPeercastApp ::getDirectory()
119 {
120         char path_buffer[256],drive[32],dir[128];
121         GetModuleFileName(NULL,path_buffer,255);
122         _splitpath(path_buffer,drive,dir,NULL,NULL);
123         sprintf(servMgr->modulePath,"%s%s",drive,dir);
124 }
125 // --------------------------------- JP-EX
126 bool    APICALL MyPeercastApp ::clearTemp()
127 {
128         if (servMgr->clearPLS)
129                 return true;
130
131         return false;
132 }
133
134
135 class NOTIFYICONDATA2
136 {
137 public:
138         DWORD cbSize; // DWORD
139         HWND hWnd; // HWND
140         UINT uID; // UINT
141         UINT uFlags; // UINT
142         UINT uCallbackMessage; // UINT
143         HICON hIcon; // HICON
144         char szTip[128]; // char[128]
145         DWORD dwState; // DWORD
146         DWORD dwStateMask; // DWORD
147         char szInfo[256]; // char[256]
148         UINT uTimeoutOrVersion; // UINT
149         char szInfoTitle[64]; // char[64]
150         DWORD dwInfoFlags; // DWORD
151         //GUID guidItem; > IE 6
152 };
153
154 NOTIFYICONDATA2 trayIcon;
155
156
157 // Global Variables:
158 HINSTANCE hInst;                                                                // current instance
159 TCHAR szTitle[MAX_LOADSTRING];                                                          // The title bar text
160 TCHAR szWindowClass[MAX_LOADSTRING];                                                            // The title bar text
161 TCHAR szWindowClass2[MAX_LOADSTRING];                                                           // The title bar text
162
163 // Foward declarations of functions included in this code module:
164 ATOM                            MyRegisterClass(HINSTANCE hInstance);
165 ATOM                            MyRegisterClass2(HINSTANCE hInstance);
166 ATOM                            MyRegisterClass3(HINSTANCE hInstance);
167 BOOL                            InitInstance(HINSTANCE, int);
168 LRESULT CALLBACK        WndProc(HWND, UINT, WPARAM, LPARAM);
169 LRESULT CALLBACK        About(HWND, UINT, WPARAM, LPARAM);
170 LRESULT CALLBACK        ChanInfoProc(HWND, UINT, WPARAM, LPARAM);
171
172 void setTrayIcon(int type, const char *,const char *,bool);
173 void flipNotifyPopup(int id, ServMgr::NOTIFY_TYPE nt);
174
175
176 HWND chWnd=NULL;
177
178 // --------------------------------------------------
179 void LOG2(const char *fmt,...)
180 {
181         va_list ap;
182         va_start(ap, fmt);
183         char str[4096];
184         vsprintf(str,fmt,ap);
185         OutputDebugString(str);
186         va_end(ap);     
187 }
188
189 // --------------------------------------------------
190 void WINAPI ServiceMain(DWORD argc, LPSTR *argv)
191 {
192         //hInst = hInstance;
193
194         //iniFileName.set(".\\peercast.ini");
195
196         WIN32_FIND_DATA fd; //JP-EX
197         HANDLE hFind; //JP-EX
198
199         OSVERSIONINFO osInfo; //JP-EX
200         osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //JP-EX
201         GetVersionEx(&osInfo);
202         if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
203                 winDistinctionNT = true;
204         else
205                 winDistinctionNT = false;
206
207         // off by default now
208         showGUI = false;
209
210         // get current path
211         {
212                 TCHAR buf[1024];
213                 DWORD ret;
214
215                 ret = GetModuleFileName(NULL, buf, sizeof(buf)/sizeof(TCHAR));
216                 if (ret)
217                 {
218                         exit(-1);
219                 }
220                 for (int i=_tcslen(buf); i>0; --i)
221                 {
222                         if (buf[i] == '\\')
223                         {
224                                 buf[i+1] = '\0';
225                                 break;
226                         }
227                 }
228
229                 exePath = buf;
230         }
231
232         iniFileName.set(exePath.cstr());
233         iniFileName.append("\\peercast.ini");
234
235         _chdir(exePath);
236
237         peercastInst = new MyPeercastInst();
238         peercastApp = new MyPeercastApp();
239
240         peercastInst->init();
241
242         LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x");
243
244         if (peercastApp->clearTemp()) //JP-EX
245         {
246                 DeleteFile("play.pls");
247                 hFind = FindFirstFile("*.asx",&fd);
248                 if (hFind != INVALID_HANDLE_VALUE)
249                 {
250                         do
251                         {
252                                 DeleteFile((char *)&fd.cFileName);
253                         }
254                         while (FindNextFile(hFind,&fd));
255
256                         FindClose(hFind);
257                 }
258         }
259
260         peercastInst->saveSettings();
261         peercastInst->quit();
262 }
263
264 // --------------------------------------------------
265 int WinMainDummy(HINSTANCE hInstance,
266                                  HINSTANCE hPrevInstance,
267                                  LPSTR lpCmdLine,
268                                  int nCmdShow)
269 {
270 #ifdef _DEBUG
271         // memory leak check
272         ::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
273 #endif
274
275         char tmpURL[8192];
276         tmpURL[0]=0;
277         char *chanURL=NULL;
278
279         hInst = hInstance;
280
281         iniFileName.set(".\\peercast.ini");
282
283         WIN32_FIND_DATA fd; //JP-EX
284         HANDLE hFind; //JP-EX
285
286         OSVERSIONINFO osInfo; //JP-EX
287         osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //JP-EX
288         GetVersionEx(&osInfo);
289         if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
290                 winDistinctionNT = true;
291         else
292                 winDistinctionNT = false;
293
294         // off by default now
295         showGUI = false;
296
297         if (strlen(lpCmdLine) > 0)
298         {
299                 char *p;
300                 if ((p = strstr(lpCmdLine,"-inifile"))!=NULL) 
301                         iniFileName.setFromString(p+8);
302
303                 if (strstr(lpCmdLine,"-zen")) 
304                         showGUI = false;
305
306                 if (strstr(lpCmdLine,"-multi")) 
307                         allowMulti = true;
308
309                 if (strstr(lpCmdLine,"-kill")) 
310                         killMe = true;
311
312                 if ((p = strstr(lpCmdLine,"-url"))!=NULL)
313                 {
314                         p+=4;
315                         while (*p)
316                         {
317                                 if (*p=='"')
318                                 {
319                                         p++;
320                                         break;
321                                 }                               
322                                 if (*p != ' ')
323                                         break;
324                                 p++;
325                         }
326                         if (*p)
327                                 strncpy(tmpURL,p,sizeof(tmpURL)-1);
328                 }
329         }
330
331         // get current path
332         {
333                 exePath = iniFileName;
334                 char *s = exePath.cstr();
335                 char *end = NULL;
336                 while (*s)
337                 {
338                         if (*s++ == '\\')
339                                 end = s;
340                 }
341                 if (end)
342                         *end = 0;
343         }
344
345
346         if (strnicmp(tmpURL,"peercast://",11)==0)
347         {
348                 if (strnicmp(tmpURL+11,"pls/",4)==0)
349                         chanURL = tmpURL+11+4;
350                 else
351                         chanURL = tmpURL+11;
352                 showGUI = false;
353         }
354
355
356         MSG msg;
357         HACCEL hAccelTable;
358
359         // Initialize global strings
360         //LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
361         //LoadString(hInstance, IDC_APP_TITLE, szWindowClass, MAX_LOADSTRING);
362
363         strcpy(szTitle,"PeerCast");
364         strcpy(szWindowClass,"PeerCast");
365         strcpy(szWindowClass2,"Main");
366
367         if (!allowMulti)
368         {
369                 HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass);
370
371                 if (GetLastError() == ERROR_ALREADY_EXISTS)
372                 {
373                         HWND oldWin = FindWindow(szWindowClass,NULL);
374                         if (oldWin)
375                         {
376                                 //SendMessage(oldWin,WM_SHOWGUI,0,0);
377                                 if (killMe)
378                                 {
379                                         SendMessage(oldWin,WM_DESTROY,0,0);
380                                         return 0;
381                                 }
382
383                                 if (chanURL)
384                                 {
385                                         COPYDATASTRUCT copy;
386                                         copy.dwData = WM_PLAYCHANNEL;
387                                         copy.cbData = strlen(chanURL)+1;                        // plus null term
388                                         copy.lpData = chanURL;
389                                         SendMessage(oldWin,WM_COPYDATA,NULL,(LPARAM)&copy);
390                                 }else{
391                                         if (showGUI)
392                                                 SendMessage(oldWin,WM_SHOWGUI,0,0);
393                                 }
394                         }
395                         return 0;
396                 }
397         }
398
399         if (killMe)
400                 return 0;
401
402         MyRegisterClass(hInstance);
403         MyRegisterClass2(hInstance);
404
405         // Perform application initialization:
406         if (!InitInstance (hInstance, nCmdShow)) 
407                 return FALSE;
408
409         peercastInst = new MyPeercastInst();
410         peercastApp = new MyPeercastApp();
411
412         peercastInst->init();
413
414         LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x");
415
416         if (peercastApp->clearTemp()) //JP-EX
417         {
418                 DeleteFile("play.pls");
419                 hFind = FindFirstFile("*.asx",&fd);
420                 if (hFind != INVALID_HANDLE_VALUE)
421                 {
422                         do
423                         {
424                                 DeleteFile((char *)&fd.cFileName);
425                         }
426                         while (FindNextFile(hFind,&fd));
427
428                         FindClose(hFind);
429                 }
430         }
431
432         if (chanURL)
433         {
434                 ChanInfo info;
435                 servMgr->procConnectArgs(chanURL,info);
436                 chanMgr->findAndPlayChannel(info,false);
437         }
438
439         hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLE);
440
441         // setup menu notifes
442         int mask = peercastInst->getNotifyMask();
443         if (mask & ServMgr::NT_PEERCAST)
444                 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_PEERCAST,MF_CHECKED|MF_BYCOMMAND);
445         if (mask & ServMgr::NT_BROADCASTERS)
446                 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_BROADCASTERS,MF_CHECKED|MF_BYCOMMAND);
447         if (mask & ServMgr::NT_TRACKINFO)
448                 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_TRACKINFO,MF_CHECKED|MF_BYCOMMAND);
449
450         if (servMgr->startWithGui)
451         {
452                 createGUI((HWND)0);
453         }
454
455         // Main message loop:
456         while (GetMessage(&msg, NULL, 0, 0)) 
457         {
458                 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
459                 {
460                         TranslateMessage(&msg);
461                         DispatchMessage(&msg);
462                 }
463         }
464
465         Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon);
466
467         peercastInst->saveSettings();
468         peercastInst->quit();
469
470         Gdiplus::GdiplusShutdown(gdiplusToken);
471
472         return msg.wParam;
473 }
474
475
476 // ---------------------------------------
477 int APIENTRY WinMain(HINSTANCE hInstance,
478                                          HINSTANCE hPrevInstance,
479                                          LPSTR     lpCmdLine,
480                                          int       nCmdShow)
481 {
482         // SEH handling
483         _EXCEPTION_POINTERS *lpExcept;
484         __try
485         {
486 #if 0
487                 // switch to service
488                 if (lstrlen(lpCmdLine) && strstr(lpCmdLine, "-D") != NULL)
489                 {
490                         SERVICE_TABLE_ENTRY svctbl[] = {
491                                 {"PeerCast", (LPSERVICE_MAIN_FUNCTION)ServiceMain},
492                                 {NULL, NULL}
493                         };
494
495                         if (!StartServiceCtrlDispatcher(svctbl)) 
496                         { 
497                                 //SvcReportEvent(TEXT("StartServiceCtrlDispatcher")); 
498                         }
499                 } else
500 #endif
501                         WinMainDummy(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
502         } __except(lpExcept = GetExceptionInformation(), EXCEPTION_EXECUTE_HANDLER)
503         {
504                 DWORD nParams;
505
506                 fs.openWriteReplace(".\\dump.txt");
507                 fs.writeLine("Exception Point: WinMain");
508                 fs.write("Exception: ", 11);
509                 switch (lpExcept->ExceptionRecord->ExceptionCode)
510                 {
511                 case EXCEPTION_ACCESS_VIOLATION:
512                         fs.writeLine("Access violation");
513                         break;
514
515                 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
516                 case EXCEPTION_INT_DIVIDE_BY_ZERO:
517                         fs.writeLine("Divide by zero");
518                         break;
519
520                 case EXCEPTION_STACK_OVERFLOW:
521                         fs.writeLine("Stack overflow");
522                         break;
523
524                 default:
525                         fs.writeLong(lpExcept->ExceptionRecord->ExceptionCode);
526                         fs.writeLine("");
527                 }
528
529                 fs.writeLineF("Address: %p", lpExcept->ExceptionRecord->ExceptionAddress);
530
531                 fs.writeLine("Additional information:");
532                 nParams = lpExcept->ExceptionRecord->NumberParameters;
533                 for (unsigned i=0; i<nParams; ++i)
534                 {
535                         fs.writeLineF("%d: %lu", i, lpExcept->ExceptionRecord->ExceptionInformation[i]);
536                 }
537                 fs.close();
538
539
540                 fs.openWriteReplace(".\\dump.html");
541                 sys->logBuf->dumpHTML(fs);
542                 fs.close();
543
544                 MessageBox(NULL, "\88ê\94Ê\95Û\8cì\88á\94½\82Ì\88×\81A\83v\83\8d\83O\83\89\83\80\82Í\8b­\90§\8fI\97¹\82³\82ê\82Ü\82·\81B\n"
545                         "\96â\91è\89ð\8c\88\82Ì\82½\82ß\82É\83_\83\93\83v\83f\81[\83^(dump.html, dump.txt)\82ð\92ñ\8b\9f\82µ\82Ä\82­\82¾\82³\82¢\81B", "SEH",
546                         MB_OK|MB_ICONWARNING);
547
548                 return GetExceptionCode();
549         }
550
551         // dummy
552         return 0;
553 }
554
555
556
557 //
558 //  FUNCTION: MyRegisterClass()
559 //
560 //  PURPOSE: Registers the window class.
561 //
562 //  COMMENTS:
563 //
564 //    This function and its usage is only necessary if you want this code
565 //    to be compatible with Win32 systems prior to the 'RegisterClassEx'
566 //    function that was added to Windows 95. It is important to call this function
567 //    so that the application will get 'well formed' small icons associated
568 //    with it.
569 //
570 ATOM MyRegisterClass(HINSTANCE hInstance)
571 {
572         WNDCLASSEX wcex;
573
574         wcex.cbSize = sizeof(WNDCLASSEX); 
575
576         wcex.style                      = CS_HREDRAW | CS_VREDRAW;
577         wcex.lpfnWndProc        = (WNDPROC)WndProc;
578         wcex.cbClsExtra         = 0;
579         wcex.cbWndExtra         = 0;
580         wcex.hInstance          = hInstance;
581         wcex.hIcon                      = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLE);
582         wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
583         wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
584 //      wcex.lpszMenuName       = (LPCSTR)IDC_SIMPLE;
585         wcex.lpszMenuName       = NULL;
586         wcex.lpszClassName      = szWindowClass;
587         wcex.hIconSm            = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
588
589         return RegisterClassEx(&wcex);
590 }
591
592 ATOM MyRegisterClass2(HINSTANCE hInstance)
593 {
594         WNDCLASSEX wcex;
595         
596         wcex.cbSize = sizeof(WNDCLASSEX); 
597
598         wcex.style                      = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ;
599         wcex.lpfnWndProc        = (WNDPROC)GUIProc;
600         wcex.cbClsExtra         = 0;
601         wcex.cbWndExtra         = 0;
602         wcex.hInstance          = hInstance;
603         wcex.hIcon                      = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLE);
604         wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
605         wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
606 //      wcex.lpszMenuName       = (LPCSTR)IDC_SIMPLE;
607         wcex.lpszMenuName       = NULL;
608         wcex.lpszClassName      = szWindowClass2;
609         wcex.hIconSm            = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
610
611         return RegisterClassEx(&wcex);
612 }
613
614 //-----------------------------
615 void loadIcons(HINSTANCE hInstance, HWND hWnd)
616 {
617         icon1 = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL);
618         icon2 = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL2);
619
620     trayIcon.cbSize = sizeof(trayIcon);
621     trayIcon.hWnd = hWnd;
622     trayIcon.uID = 100;
623     trayIcon.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP;
624     trayIcon.uCallbackMessage = WM_TRAYICON;
625     trayIcon.hIcon = icon1;
626     strcpy(trayIcon.szTip, "PeerCast");
627
628     Shell_NotifyIcon(NIM_ADD, (NOTIFYICONDATA*)&trayIcon);
629
630     //ShowWindow(hWnd, nCmdShow);
631     UpdateWindow(hWnd);
632
633         if(!trayMenu)   // for PCRaw (tray icon)
634                 trayMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_TRAYMENU));
635         if(!ltrayMenu)  // for PCRaw (tray icon)
636                 ltrayMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_LTRAYMENU));
637
638
639 }
640
641 //-----------------------------
642 //
643 //   FUNCTION: InitInstance(HANDLE, int)
644 //
645 //   PURPOSE: Saves instance handle and creates main window
646 //
647 //   COMMENTS:
648 //
649 //        In this function, we save the instance handle in a global variable and
650 //        create and display the main program window.
651 //
652 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
653 {
654         HWND hWnd;
655
656         hInst = hInstance; // Store instance handle in our global variable
657
658         hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
659           CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
660
661         if (!hWnd)
662         {
663           return FALSE;
664         }
665
666         mainWnd = hWnd;
667
668         g_iTaskbarCreated = RegisterWindowMessage("TaskbarCreated");    // for PCRaw (tray icon)
669
670         loadIcons(hInstance,hWnd);
671
672         using namespace Gdiplus;
673         GdiplusStartupInput gdiplusStartupInput;
674         GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
675
676         return TRUE;
677 }
678 //-----------------------------
679 //static String trackTitle;
680 //static String channelComment;
681
682 //-----------------------------
683 void channelPopup(const char *title, const char *msg, bool isPopup = true)
684 {
685         String both;
686
687         if (*title == '\0') return;
688         both.append(msg);
689         both.append(" (");
690         both.append(title);
691         both.append(")");
692
693         trayIcon.uFlags = NIF_ICON|NIF_TIP;
694         strncpy(trayIcon.szTip, both.cstr(),sizeof(trayIcon.szTip)-1);
695         trayIcon.szTip[sizeof(trayIcon.szTip)-1]=0;
696
697         if (isPopup) trayIcon.uFlags |= 16;
698         trayIcon.uTimeoutOrVersion = 10000;
699         strncpy(trayIcon.szInfo,msg,sizeof(trayIcon.szInfo)-1);
700         strncpy(trayIcon.szInfoTitle,title,sizeof(trayIcon.szInfoTitle)-1);
701                 
702         Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
703 }
704 //-----------------------------
705 void clearChannelPopup()
706 {
707         trayIcon.uFlags = NIF_ICON|16;
708         trayIcon.uTimeoutOrVersion = 10000;
709     strncpy(trayIcon.szInfo,"",sizeof(trayIcon.szInfo)-1);
710         strncpy(trayIcon.szInfoTitle,"",sizeof(trayIcon.szInfoTitle)-1);
711         Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
712 }
713
714 //-----------------------------
715 // PopupEntry
716 struct PopupEntry {
717         GnuID id;
718         String name;
719         String track;
720         String comment;
721         PopupEntry *next;
722 };
723 static PopupEntry *PEList = NULL;
724 static WLock PELock;
725
726 static void putPopupEntry(PopupEntry *pe)
727 {
728         PELock.on();
729         pe->next = PEList;
730         PEList = pe;
731         PELock.off();
732 }
733
734 static PopupEntry *getPopupEntry(GnuID id)
735 {
736         PELock.on();
737         PopupEntry *pe = PEList;
738         PopupEntry *prev = NULL;
739         while (pe) {
740                 if (id.isSame(pe->id)) {
741                         if (prev) prev->next = pe->next;
742                         else PEList = pe->next;
743                         PELock.off();
744                         pe->next = NULL;
745                         return pe;
746                 }
747                 prev = pe;
748                 pe = pe->next;
749         }
750         PELock.off();
751         return NULL;
752 }
753
754 static PopupEntry *getTopPopupEntry()
755 {
756         PopupEntry *p = NULL;
757         PELock.on();
758         if (PEList) {
759                 p = PEList;
760                 PEList = PEList->next;
761         }
762         PELock.off();
763         return p;
764 }
765
766 //-----------------------------
767 void    APICALL MyPeercastApp::channelStart(ChanInfo *info)
768 {
769
770 //      lastPlayID = info->id;
771 //
772 //      if(!isIndexTxt(info))   // for PCRaw (popup)
773 //              clearChannelPopup();
774
775         PopupEntry *pe = getPopupEntry(info->id);
776         if (!pe) {
777                 pe = new PopupEntry;
778                 pe->id = info->id;
779         }
780         if (!isIndexTxt(info))
781                 putPopupEntry(pe);
782         else
783                 delete pe;
784 }
785 //-----------------------------
786 void    APICALL MyPeercastApp::channelStop(ChanInfo *info)
787 {
788 //      if (info->id.isSame(lastPlayID))
789 //      {
790 //              lastPlayID.clear();
791 //
792 //              if(!isIndexTxt(info))   // for PCRaw (popup)
793 //                      clearChannelPopup();
794 //      }
795
796         PopupEntry *pe = getPopupEntry(info->id);
797         if (pe) delete pe;
798
799         pe = getTopPopupEntry();
800         if (!pe) {
801                 clearChannelPopup();
802         } else {
803                 if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
804                 {
805                         String name,track; //JP-Patch
806                         name = pe->name; //JP-Patch
807                         track = pe->track; //JP-Patch
808                         name.convertTo(String::T_SJIS); //JP-Patch
809                         track.convertTo(String::T_SJIS); //JP-Patch
810                         clearChannelPopup();
811                 //      channelPopup(info->name.cstr(),trackTitle.cstr());
812                         channelPopup(name.cstr(),track.cstr(), false); //JP-Patch
813                 }
814                 putPopupEntry(pe);
815         }
816 }
817 //-----------------------------
818 void    APICALL MyPeercastApp::channelUpdate(ChanInfo *info)
819 {
820         if (info)
821         {
822                 PopupEntry *pe = getPopupEntry(info->id);
823                 if (!pe) return;
824
825                 String tmp;
826                 tmp.append(info->track.artist);
827                 tmp.append(" ");
828                 tmp.append(info->track.title);
829
830
831                 if (!tmp.isSame(pe->track))
832                 {
833                         pe->name = info->name;
834                         pe->track = tmp;
835                         if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
836                         {
837                                 //trackTitle=tmp;
838                                 String name,track; //JP-Patch
839                                 name = info->name; //JP-Patch
840                                 track = tmp; //JP-Patch
841                                 name.convertTo(String::T_SJIS); //JP-Patch
842                                 track.convertTo(String::T_SJIS); //JP-Patch
843                                 if(!isIndexTxt(info))   // for PCRaw (popup)
844                                 {
845                                         clearChannelPopup();
846                                 //      channelPopup(info->name.cstr(),trackTitle.cstr());
847                                         channelPopup(name.cstr(),track.cstr()); //JP-Patch
848                                 }
849                         }
850                 } else if (!info->comment.isSame(pe->comment))
851                 {
852                         pe->name = info->name;
853                         pe->comment = info->comment;
854                         if (ServMgr::NT_BROADCASTERS & peercastInst->getNotifyMask())
855                         {
856                                 //channelComment = info->comment;
857                                 String name,comment; //JP-Patch
858                                 name = info->name; //JP-Patch
859                                 comment = info->comment; //JP-Patch
860                                 name.convertTo(String::T_SJIS); //JP-Patch
861                                 comment.convertTo(String::T_SJIS); //JP-Patch
862                                 if(!isIndexTxt(info))   // for PCRaw (popup)
863                                 {
864                                         clearChannelPopup();
865                                 //      channelPopup(info->name.cstr(),channelComment.cstr());
866                                         channelPopup(name.cstr(),comment.cstr());
867                                 }
868                         }
869                 }
870
871                 if (!isIndexTxt(info))
872                         putPopupEntry(pe);
873                 else
874                         delete pe;
875         }
876 }
877 //-----------------------------
878 void    APICALL MyPeercastApp::notifyMessage(ServMgr::NOTIFY_TYPE type, const char *msg)
879 {
880         static bool shownUpgradeAlert=false;
881
882         currNotify = type;
883
884         trayIcon.uFlags = 0;
885
886         if (!shownUpgradeAlert)
887         {
888             trayIcon.uFlags = NIF_ICON;
889
890                 if (type == ServMgr::NT_UPGRADE)
891                 {
892                         shownUpgradeAlert = true;
893                     trayIcon.hIcon = icon2;
894                 }else
895                 {
896                         trayIcon.hIcon = icon1; 
897                 }
898         }else
899         {
900                 if (type == ServMgr::NT_UPGRADE)
901                         return;
902         }
903
904         const char *title="";
905
906         switch(type)
907         {
908                 case ServMgr::NT_UPGRADE:
909                         title = "Upgrade alert";
910                         break;
911                 case ServMgr::NT_PEERCAST:
912                         title = "Message from PeerCast:";
913                         break;
914
915         }
916
917         if (type & peercastInst->getNotifyMask())
918         {
919                 trayIcon.uFlags |= 16;
920         trayIcon.uTimeoutOrVersion = 10000;
921         strncpy(trayIcon.szInfo,msg,sizeof(trayIcon.szInfo)-1);
922                 strncpy(trayIcon.szInfoTitle,title,sizeof(trayIcon.szInfoTitle)-1);
923             Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
924         }
925 }
926 //-----------------------------
927
928 // createGUI()
929 //
930 void createGUI(HWND hWnd)
931 {
932         if (!guiWnd){
933                 guiWnd = ::CreateWindow(szWindowClass2,
934                         "Peercast-IM@S",
935                         WS_OVERLAPPEDWINDOW & ~(WS_MAXIMIZEBOX) /*| WS_VSCROLL | WS_HSCROLL*/,
936                         0,
937                         0,
938                         800,
939                         600,
940                         NULL,
941                         NULL,
942                         hInst,
943                         NULL);
944         }
945         ShowWindow(guiWnd,SW_SHOWNORMAL);
946
947         // \8e©\93®\82Å\8dÅ\91O\96Ê
948         if (servMgr->topmostGui)
949         {
950                 ::SetWindowPos(guiWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
951         }
952 }
953
954
955 // 
956 // addRelayedChannelsMenu(HMENU m)
957 // 
958 //
959 void addRelayedChannelsMenu(HMENU cm)
960 {
961         int cnt = GetMenuItemCount(cm);
962         for(int i=0; i<cnt-3; i++)
963                 DeleteMenu(cm,0,MF_BYPOSITION);
964
965         Channel *c = chanMgr->channel;
966         while(c)
967         {
968                 if (c->isActive())
969                 {
970                         char str[128],name[64];
971                         strncpy(name,c->info.name,32);
972                         name[32]=0;
973                         if (strlen(c->info.name) > 32)
974                                 strcat(name,"...");
975
976
977                         sprintf(str,"%s  (%d kb/s %s)",name,c->info.bitrate,ChanInfo::getTypeStr(c->info.contentType));
978                         //InsertMenu(cm,0,MF_BYPOSITION,RELAY_CMD+i,str);
979                 }
980                 c=c->next;
981         }
982 }
983
984 typedef int (*COMPARE_FUNC)(const void *,const void *);
985
986 static int compareHitLists(ChanHitList **c2, ChanHitList **c1)
987 {
988         return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());
989 }
990
991 static int compareChannels(Channel **c2, Channel **c1)
992 {
993         return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());
994 }
995
996 // 
997 // addAllChannelsMenu(HMENU m)
998 // 
999 //
1000 void addAllChannelsMenu(HMENU cm)
1001 {
1002         int cnt = GetMenuItemCount(cm);
1003 /*      for(int i=0; i<cnt-2; i++)
1004                 DeleteMenu(cm,0,MF_BYPOSITION);*/
1005
1006         for(int i=0; i<cnt; i++)
1007                 DeleteMenu(cm,0,MF_BYPOSITION);
1008
1009         HMENU yMenu = CreatePopupMenu();
1010         if (!servMgr->rootHost2.isEmpty()){
1011                 InsertMenu(yMenu,0,MF_BYPOSITION,ID_POPUP_YELLOWPAGES2,servMgr->rootHost2);
1012         }
1013         if (!servMgr->rootHost.isEmpty()){
1014                 InsertMenu(yMenu,0,MF_BYPOSITION,ID_POPUP_YELLOWPAGES1,servMgr->rootHost);
1015         }
1016
1017         InsertMenu(cm,0,MF_BYPOSITION|MF_POPUP,(UINT)yMenu,"\83C\83G\83\8d\81[\83y\81[\83W");
1018         InsertMenu(cm,0,MF_BYPOSITION|MF_SEPARATOR,NULL,NULL);
1019         // add channels to menu
1020         int numActive=0;
1021         Channel *ch = chanMgr->channel;
1022         while(ch)
1023         {
1024                 char str[128],name[64];
1025                 String sjis; //JP-Patch
1026                 sjis = ch->info.name; //JP-Patch
1027                 sjis.convertTo(String::T_SJIS); //JP-Patch
1028                 strncpy(name,sjis.cstr(),32);
1029                 //strncpy(name,ch->info.name,32);
1030                 name[32]=0;
1031                 //if (strlen(ch->info.name) > 32)
1032                 if (strlen(sjis.cstr()) > 32) //JP-Patch
1033                         strcat(name,"...");
1034
1035                 sprintf(str,"%s  (%d kb/s %s)",name,ch->info.bitrate,ChanInfo::getTypeStr(ch->info.contentType));
1036
1037                 HMENU opMenu = CreatePopupMenu();
1038                 InsertMenu(opMenu,0,MF_BYPOSITION,INFO_CMD+numActive,"Info");
1039                 if (ch->info.url.isValidURL())
1040                         InsertMenu(opMenu,0,MF_BYPOSITION,URL_CMD+numActive,"URL");
1041                 InsertMenu(opMenu,0,MF_BYPOSITION,PLAY_CMD+numActive,"Play");
1042
1043                 UINT fl = MF_BYPOSITION|MF_POPUP;
1044                 if (ch)
1045                         fl |= (ch->isPlaying()?MF_CHECKED:0);
1046
1047                 InsertMenu(cm,0,fl,(UINT)opMenu,str);
1048                 
1049                 numActive++;
1050
1051                 ch=ch->next;
1052         }
1053
1054
1055         //if (!numActive)
1056         //              InsertMenu(cm,0,MF_BYPOSITION,0,"<No channels>");
1057
1058
1059
1060
1061 }
1062
1063
1064 // 
1065 // flipNotifyPopup(id, flag)
1066 void flipNotifyPopup(int id, ServMgr::NOTIFY_TYPE nt)
1067 {
1068         int mask = peercastInst->getNotifyMask();
1069
1070         mask ^= nt;
1071         if (mask & nt)
1072                 CheckMenuItem(trayMenu,id,MF_CHECKED|MF_BYCOMMAND);
1073         else
1074                 CheckMenuItem(trayMenu,id,MF_UNCHECKED|MF_BYCOMMAND);
1075
1076         peercastInst->setNotifyMask(mask);
1077         peercastInst->saveSettings();
1078 }
1079  
1080
1081 static void showHTML(const char *file)
1082 {
1083         char url[256];
1084         sprintf(url,"%s/%s",servMgr->htmlPath,file);                                    
1085
1086 //      sys->callLocalURL(url,servMgr->serverHost.port);
1087         sys->callLocalURL(url,  // for PCRaw (url)
1088                 (servMgr->allowServer1&Servent::ALLOW_HTML)?(servMgr->serverHost.port):(servMgr->serverHost.port+1));
1089 }
1090
1091 static ChanInfo getChannelInfo(int index)
1092 {
1093         Channel *c = chanMgr->findChannelByIndex(index);
1094         if (c)
1095                 return c->info;
1096
1097         ChanInfo info;
1098         return info;
1099 }
1100
1101 //
1102 //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
1103 //
1104 //  PURPOSE:  Processes messages for the main window.
1105 //
1106 //  WM_COMMAND  - process the application menu
1107 //  WM_PAINT    - Paint the main window
1108 //  WM_DESTROY  - post a quit message and return
1109 //
1110 //
1111 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1112 {
1113         int wmId, wmEvent;
1114         POINT point;
1115         char buf[1024];
1116
1117         if(message == g_iTaskbarCreated)        // for PCRaw (tray icon)
1118                 loadIcons(hInst, hWnd);
1119  
1120         switch (message) 
1121         {
1122                 case WM_SHOWGUI:
1123                         createGUI(hWnd);
1124                         break;
1125
1126
1127                 case WM_TRAYICON:
1128                         switch((UINT)lParam) 
1129                         {
1130                                 case WM_LBUTTONDOWN:
1131                                         if (allowTrayMenu)
1132                                                 SendMessage(hWnd,WM_SHOWMENU,2,0);
1133                                         SetForegroundWindow(hWnd);    
1134                                         break;
1135                                 case WM_RBUTTONDOWN:
1136                                         if (allowTrayMenu)
1137                                                 SendMessage(hWnd,WM_SHOWMENU,1,0);
1138                                         SetForegroundWindow(hWnd);    
1139                                         break;
1140                                 case WM_LBUTTONDBLCLK:
1141                                         createGUI(hWnd);
1142                                         break;
1143                         }
1144                         break;
1145
1146                 case WM_COPYDATA:
1147                         {
1148                                 COPYDATASTRUCT *pc = (COPYDATASTRUCT *)lParam;
1149                                 LOG_DEBUG("URL request: %s",pc->lpData);
1150                                 if (pc->dwData == WM_PLAYCHANNEL)
1151                                 {
1152                                         ChanInfo info;
1153                                         servMgr->procConnectArgs((char *)pc->lpData,info);
1154                                         chanMgr->findAndPlayChannel(info,false);
1155                                 }
1156                                 //sys->callLocalURL((const char *)pc->lpData,servMgr->serverHost.port);
1157                         }
1158                         break;
1159                 case WM_GETPORTNUMBER:
1160                         {
1161                                 int port;
1162                                 port=servMgr->serverHost.port;
1163                                 ReplyMessage(port);
1164                         }
1165                         break;
1166
1167                 case WM_SHOWMENU:
1168                         {
1169                                 if (servMgr->saveGuiPos){
1170                                         CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_CHECKED|MF_BYCOMMAND);
1171                                 } else {
1172                                         CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_UNCHECKED|MF_BYCOMMAND);
1173                                 }
1174
1175                                 // \8e©\93®GUI/\8dÅ\91O\96Ê\8b@\94\
1176                                 if (servMgr->topmostGui)
1177                                 {
1178                                         CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_CHECKED|MF_BYCOMMAND);
1179                                 } else
1180                                 {
1181                                         CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_UNCHECKED|MF_BYCOMMAND);
1182                                 }
1183
1184                                 if (servMgr->startWithGui)
1185                                 {
1186                                         CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_CHECKED|MF_BYCOMMAND);
1187                                 } else
1188                                 {
1189                                         CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_UNCHECKED|MF_BYCOMMAND);
1190                                 }
1191
1192                                 // \83X\83N\83\8a\81[\83\93\83Z\81[\83o\81[\97}\8e~
1193                                 if (servMgr->preventSS)
1194                                 {
1195                                         CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_CHECKED|MF_BYCOMMAND);
1196                                 } else
1197                                 {
1198                                         CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_UNCHECKED|MF_BYCOMMAND);
1199                                 }
1200
1201                                 // \83o\81[\83W\83\87\83\93\83`\83F\83b\83N\82Ì\97L\96³
1202                                 if (servMgr->noVersionCheck)
1203                                 {
1204                                         CheckMenuItem(trayMenu, ID_POPUP_NO_VER_CHECK, MF_CHECKED|MF_BYCOMMAND);
1205                                 } else
1206                                 {
1207                                         CheckMenuItem(trayMenu, ID_POPUP_NO_VER_CHECK, MF_UNCHECKED|MF_BYCOMMAND);
1208                                 }
1209
1210                                 SetForegroundWindow(hWnd);    
1211                                 bool skipMenu=false;
1212
1213                                 allowTrayMenu = false;
1214
1215                                 // check for notifications
1216                                 if (currNotify & ServMgr::NT_UPGRADE)
1217                                 {
1218                                         if (servMgr->downloadURL[0])
1219                                         {
1220                                                 if ((sys->getTime()-seenNewVersionTime) > (60*60))      // notify every hour
1221                                                 {
1222                                                         if (MessageBox(hWnd,"A newer version of PeerCast is available, press OK to upgrade.","PeerCast",MB_OKCANCEL|MB_APPLMODAL|MB_ICONEXCLAMATION) == IDOK)
1223                                                                 sys->getURL(servMgr->downloadURL);
1224
1225                                                         seenNewVersionTime=sys->getTime();
1226                                                         skipMenu=true;
1227                                                 }
1228                                         }
1229                                 }
1230
1231
1232                                 if (!skipMenu)
1233                                 {
1234                                         RECT rcWnd;
1235                                         HMENU menu;
1236                                         UINT flg = 0;
1237
1238                                         SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWnd, 0);
1239                                         GetCursorPos(&point);
1240
1241                                         if (point.x < rcWnd.left){
1242                                                 point.x = rcWnd.left;
1243                                                 flg |= TPM_LEFTALIGN;
1244                                         }
1245                                         if (point.x > rcWnd.right){
1246                                                 point.x = rcWnd.right;
1247                                                 flg |= TPM_RIGHTALIGN;
1248                                         }
1249                                         if (point.y < rcWnd.top){
1250                                                 point.y = rcWnd.top;
1251                                                 flg |= TPM_TOPALIGN;
1252                                         }
1253                                         if (point.y > rcWnd.bottom){
1254                                                 point.y = rcWnd.bottom;
1255                                                 flg |= TPM_BOTTOMALIGN;
1256                                         }
1257                                         if (flg == 0){
1258                                                 flg = TPM_RIGHTALIGN;
1259                                         }
1260
1261                                         switch (wParam)
1262                                         {
1263                                                 case 1:
1264                                                         menu = GetSubMenu(trayMenu,0);
1265                                                         addAllChannelsMenu(GetSubMenu(menu,0));
1266                                                         addRelayedChannelsMenu(GetSubMenu(menu,1));
1267                                                         break;
1268                                                 case 2:
1269                                                         menu = GetSubMenu(ltrayMenu,0);
1270                                                         addAllChannelsMenu(menu);
1271                                                         break;
1272                                         }
1273                                         if (!TrackPopupMenu(menu,flg,point.x,point.y,0,hWnd,NULL))
1274                                         {
1275                                                 LOG_ERROR("Can`t track popup menu: %d",GetLastError());
1276                                         }
1277                                         PostMessage(hWnd,WM_NULL,0,0); 
1278
1279                                 }
1280                                 allowTrayMenu = true;
1281                         }
1282                         break;
1283
1284                 case WM_CREATE:
1285                         if (showGUI)
1286                                 createGUI(hWnd);
1287                         break;
1288
1289                 case WM_COMMAND:
1290                         wmId    = LOWORD(wParam); 
1291                         wmEvent = HIWORD(wParam); 
1292
1293                         if ((wmId >= INFO_CMD) && (wmId < INFO_CMD+MAX_CHANNELS))
1294                         {
1295                                 int c = wmId - INFO_CMD;
1296                                 chanInfo = getChannelInfo(c);
1297                                 chanInfoIsRelayed = false;
1298                                 if (winDistinctionNT)
1299                                         DialogBox(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc);
1300                                 else
1301                                 {
1302                                         HWND WKDLG; //JP-Patch
1303                                         WKDLG = CreateDialog(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc); //JP-Patch
1304                                         ShowWindow(WKDLG,SW_SHOWNORMAL); //JP-Patch
1305                                 }
1306                                 return 0;
1307                         }
1308                         if ((wmId >= URL_CMD) && (wmId < URL_CMD+MAX_CHANNELS))
1309                         {
1310                                 int c = wmId - URL_CMD;
1311                                 chanInfo = getChannelInfo(c);
1312                                 if (chanInfo.url.isValidURL())
1313                                         sys->getURL(chanInfo.url);
1314                                 return 0;
1315                         }
1316                         if ((wmId >= PLAY_CMD) && (wmId < PLAY_CMD+MAX_CHANNELS))
1317                         {
1318                                 int c = wmId - PLAY_CMD;
1319                                 chanInfo = getChannelInfo(c);
1320                                 chanMgr->findAndPlayChannel(chanInfo,false);
1321                                 return 0;
1322                         }
1323                         if ((wmId >= RELAY_CMD) && (wmId < RELAY_CMD+MAX_CHANNELS))
1324                         {
1325                                 int c = wmId - RELAY_CMD;
1326                                 chanInfo = getChannelInfo(c);
1327                                 chanMgr->findAndPlayChannel(chanInfo,true);
1328                                 return 0;
1329                         }
1330
1331                         // Parse the menu selections:
1332                         switch (wmId)
1333                         {
1334                                 case ID_POPUP_SHOWMESSAGES_PEERCAST:
1335                                         flipNotifyPopup(ID_POPUP_SHOWMESSAGES_PEERCAST,ServMgr::NT_PEERCAST);
1336                                         break;
1337                                 case ID_POPUP_SHOWMESSAGES_BROADCASTERS:
1338                                         flipNotifyPopup(ID_POPUP_SHOWMESSAGES_BROADCASTERS,ServMgr::NT_BROADCASTERS);
1339                                         break;
1340                                 case ID_POPUP_SHOWMESSAGES_TRACKINFO:
1341                                         flipNotifyPopup(ID_POPUP_SHOWMESSAGES_TRACKINFO,ServMgr::NT_TRACKINFO);
1342                                         break;
1343
1344                                 case ID_POPUP_ABOUT:
1345                                 case IDM_ABOUT:
1346                                         DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
1347                                         break;
1348                                 case ID_POPUP_SHOWGUI:
1349                                 case IDM_SETTINGS_GUI:
1350                                 case ID_POPUP_ADVANCED_SHOWGUI:
1351                                 {
1352                                         createGUI(hWnd);
1353                                         break;
1354                                 }
1355                                 case ID_POPUP_YELLOWPAGES:
1356                                         sys->getURL("http://yp.peercast.org/");
1357                                         break;
1358                                 case ID_POPUP_YELLOWPAGES1:
1359                                         sprintf(buf, "http://%s",servMgr->rootHost.cstr());
1360                                         sys->getURL(buf);
1361                                         break;
1362                                 case ID_POPUP_YELLOWPAGES2:
1363                                         sprintf(buf, "http://%s",servMgr->rootHost2.cstr());
1364                                         sys->getURL(buf);
1365                                         break;
1366
1367                                 case ID_POPUP_ADVANCED_VIEWLOG:
1368                                         showHTML("viewlog.html");
1369                                         break;
1370                                 case ID_POPUP_ADVANCED_SAVESETTINGS:
1371                                         servMgr->saveSettings(iniFileName.cstr());
1372                                         break;
1373                                 case ID_POPUP_ADVANCED_INFORMATION:
1374                                         showHTML("index.html");
1375                                         break;
1376                                 case ID_FIND_CHANNELS:
1377                                 case ID_POPUP_ADVANCED_ALLCHANNELS:
1378                                 case ID_POPUP_UPGRADE:
1379                                         sys->callLocalURL("admin?cmd=upgrade",servMgr->serverHost.port);
1380                                         break;
1381                                 case ID_POPUP_ADVANCED_RELAYEDCHANNELS:
1382                                 case ID_POPUP_FAVORITES_EDIT:
1383                                         showHTML("relays.html");
1384                                         break;
1385                                 case ID_POPUP_ADVANCED_BROADCAST:
1386                                         showHTML("broadcast.html");
1387                                         break;
1388                                 case ID_POPUP_SETTINGS:
1389                                         showHTML("settings.html");
1390                                         break;
1391                                 case ID_POPUP_CONNECTIONS:
1392                                         showHTML("connections.html");
1393                                         break;
1394                                 case ID_POPUP_HELP:
1395                                         sys->getURL("http://www.peercast.org/help.php");
1396                                         break;
1397
1398                                 case ID_POPUP_SAVE_GUI_POS:
1399                                         if (servMgr->saveGuiPos){
1400                                                 servMgr->saveGuiPos = false;
1401                                                 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_UNCHECKED|MF_BYCOMMAND);
1402                                         } else {
1403                                                 servMgr->saveGuiPos = true;
1404                                                 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_CHECKED|MF_BYCOMMAND);
1405                                         }
1406                                         peercastInst->saveSettings();
1407                                         break;
1408
1409                                 case ID_POPUP_KEEP_DOWNSTREAMS:
1410                                         if (servMgr->keepDownstreams){
1411                                                 servMgr->keepDownstreams = false;
1412                                                 CheckMenuItem(trayMenu, ID_POPUP_KEEP_DOWNSTREAMS, MF_UNCHECKED|MF_BYCOMMAND);
1413                                         } else {
1414                                                 servMgr->keepDownstreams = true;
1415                                                 CheckMenuItem(trayMenu, ID_POPUP_KEEP_DOWNSTREAMS, MF_CHECKED|MF_BYCOMMAND);
1416                                         }
1417                                         //peercastInst->saveSettings();
1418                                         break;
1419
1420                                 case ID_POPUP_TOPMOST:
1421                                         // \8dÅ\91O\96Ê\95\\8e¦
1422                                         if (servMgr->topmostGui)
1423                                         {
1424                                                 servMgr->topmostGui = false;
1425                                                 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_UNCHECKED|MF_BYCOMMAND);
1426                                         } else
1427                                         {
1428                                                 servMgr->topmostGui = true;
1429                                                 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_CHECKED|MF_BYCOMMAND);
1430                                         }
1431                                         peercastInst->saveSettings();
1432                                         break;
1433
1434                                 case ID_POPUP_START_WITH_GUI:
1435                                         // \8bN\93®\8e\9e\82ÉGUI\95\\8e¦
1436                                         if (servMgr->startWithGui)
1437                                         {
1438                                                 servMgr->startWithGui = false;
1439                                                 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_UNCHECKED|MF_BYCOMMAND);
1440                                         } else
1441                                         {
1442                                                 servMgr->startWithGui = true;
1443                                                 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_CHECKED|MF_BYCOMMAND);
1444                                         }
1445                                         peercastInst->saveSettings();
1446                                         break;
1447
1448                                 case ID_POPUP_TRAFFIC:
1449                                         // \83g\83\89\83t\83B\83b\83N\83\82\83j\83^\8bN\93®
1450                                         if (winDistinctionNT)
1451                                                 DialogBox(hInst, (LPCTSTR)IDD_TRAFFIC, hWnd, (DLGPROC)TrafficDlgProc);
1452                                         else
1453                                         {
1454                                                 HWND WKDLG; //JP-Patch
1455                                                 WKDLG = CreateDialog(hInst, (LPCTSTR)IDD_TRAFFIC, hWnd, (DLGPROC)TrafficDlgProc); //JP-Patch
1456                                                 ShowWindow(WKDLG,SW_SHOWNORMAL); //JP-Patch
1457                                         }
1458                                         break;
1459
1460                                 case ID_POPUP_PREVENT_SS:
1461                                         // \83X\83N\83\8a\81[\83\93\83Z\81[\83o\81[\97}\8e~
1462                                         if (servMgr->preventSS)
1463                                         {
1464                                                 servMgr->preventSS = false;
1465                                                 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_UNCHECKED|MF_BYCOMMAND);
1466                                         } else
1467                                         {
1468                                                 servMgr->preventSS = true;
1469                                                 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_CHECKED|MF_BYCOMMAND);
1470                                         }
1471                                         peercastInst->saveSettings();
1472                                         break;
1473
1474                                 case ID_POPUP_NO_VER_CHECK:
1475                                         // \83o\81[\83W\83\87\83\93\83`\83F\83b\83N\82Ì\97L\96³
1476                                         if (servMgr->noVersionCheck)
1477                                         {
1478                                                 servMgr->noVersionCheck = false;
1479                                                 CheckMenuItem(trayMenu, ID_POPUP_NO_VER_CHECK, MF_UNCHECKED|MF_BYCOMMAND);
1480                                         } else
1481                                         {
1482                                                 servMgr->noVersionCheck = true;
1483                                                 CheckMenuItem(trayMenu, ID_POPUP_NO_VER_CHECK, MF_CHECKED|MF_BYCOMMAND);
1484                                         }
1485                                         peercastInst->saveSettings();
1486                                         break;
1487
1488                                 case ID_POPUP_EXIT_CONFIRM:
1489                                 case IDM_EXIT:
1490                                    DestroyWindow(hWnd);
1491                                    break;
1492                                 default:
1493                                    return DefWindowProc(hWnd, message, wParam, lParam);
1494                         }
1495                         break;
1496                 case WM_DESTROY:
1497                         PostQuitMessage(0);
1498                         break;
1499
1500                 case WM_SYSCOMMAND:
1501                         // \82È\82ñ\82©\83A\83N\83e\83B\83u\82\82á\82È\82¢\82Æ\91\97\82ç\82ê\82Ä\82±\82È\82¢\82ç\82µ\82¢
1502                         if (servMgr->preventSS && (wParam == SC_SCREENSAVE) && chanMgr->isBroadcasting())
1503                                 return 1;
1504                         else
1505                                 return DefWindowProc(hWnd, message, wParam, lParam);
1506                         break;
1507
1508                 default:
1509                         return DefWindowProc(hWnd, message, wParam, lParam);
1510    }
1511    return 0;
1512 }
1513 // Mesage handler for about box.
1514 LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1515 {
1516         switch (message)
1517         {
1518                 case WM_INITDIALOG:
1519                         //SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENT);
1520 //                      SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTJP);
1521                         if (version_ex)
1522                         {
1523                                 SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LPARAM)PCX_AGENTEX); // x64\91Î\89\9e
1524                         } else
1525                         {
1526                                 SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTVP);
1527                         }
1528
1529                         return TRUE;
1530
1531                 case WM_COMMAND:
1532                         switch (LOWORD(wParam))
1533                         {
1534                                 case IDOK:
1535                                 case IDCANCEL:
1536                                         EndDialog(hDlg, LOWORD(wParam));
1537                                         return TRUE;
1538                                 case IDC_BUTTON1:
1539                                         sys->getURL("http://www.peercast.org");
1540                                         EndDialog(hDlg, LOWORD(wParam));
1541                                         return TRUE;
1542
1543                         }
1544                         break;
1545                 case WM_DESTROY:
1546                         break;
1547         }
1548     return FALSE;
1549 }
1550
1551 // Mesage handler for chaninfo box
1552 LRESULT CALLBACK ChanInfoProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1553 {
1554         switch (message)
1555         {
1556                 case WM_INITDIALOG:
1557                         {
1558                                 char str[1024];
1559                                 //strcpy(str,chanInfo.track.artist.cstr());
1560                                 strcpy(str,chanInfo.track.artist); //JP-Patch
1561                                 strcat(str," - ");
1562                                 //strcat(str,chanInfo.track.title.cstr());
1563                                 strcat(str,chanInfo.track.title);
1564                                 String name,track,comment,desc,genre; //JP-Patch
1565                                 name = chanInfo.name; //JP-Patch
1566                                 track = str; //JP-Patch
1567                                 comment = chanInfo.comment; //JP-Patch
1568                                 desc = chanInfo.desc; //JP-Patc
1569                                 genre = chanInfo.genre; //JP-Patch
1570                                 name.convertTo(String::T_SJIS); //JP-Patc
1571                                 track.convertTo(String::T_SJIS); //JP-Patch
1572                                 comment.convertTo(String::T_SJIS); //JP-Patch
1573                                 desc.convertTo(String::T_SJIS); //JP-Patch
1574                                 genre.convertTo(String::T_SJIS); //JP-Patch
1575                                 
1576                                 //SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)chanInfo.name.cstr());
1577                                 SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LPARAM)name.cstr()); // x64\91Î\89\9e
1578                                 //SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)name.cstr()); //JP-Patch
1579                                 //SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)str);
1580                                 SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LPARAM)track.cstr()); // x64\91Î\89\9e
1581                                 //SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)track.cstr()); //JP-Patch
1582                                 //SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)chanInfo.comment.cstr());
1583                                 SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LPARAM)comment.cstr()); // x64\91Î\89\9e
1584                                 //SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)comment.cstr()); //JP-Patch
1585                                 //SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)chanInfo.desc.cstr());
1586                                 SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LPARAM)desc.cstr()); // x64\91Î\89\9e
1587                                 //SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)desc.cstr()); //JP-Patch
1588                                 //SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)chanInfo.genre.cstr());
1589                                 SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LPARAM)genre.cstr()); // x64\91Î\89\9e
1590                                 //SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)genre.cstr()); //JP-Patch
1591
1592                                 sprintf(str,"%d kb/s %s",chanInfo.bitrate,ChanInfo::getTypeStr(chanInfo.contentType));
1593                                 SendDlgItemMessage(hDlg,IDC_FORMAT,WM_SETTEXT,0,(LPARAM)str); // x64\91Î\89\9e
1594                                 //SendDlgItemMessage(hDlg,IDC_FORMAT,WM_SETTEXT,0,(LONG)str);
1595
1596
1597                                 if (!chanInfo.url.isValidURL())
1598                                         EnableWindow(GetDlgItem(hDlg,IDC_CONTACT),false);
1599
1600                                 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1601                                 if (ch)
1602                                 {
1603                                         SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LPARAM)ch->getStatusStr()); // x64\91Î\89\9e
1604                                         //SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)ch->getStatusStr());
1605                                         SendDlgItemMessage(hDlg, IDC_KEEP,BM_SETCHECK, ch->stayConnected, 0);
1606
1607                                         // \8c»\8dÝ\82Ì\8cÅ\97L\83\8a\83\8c\81[\8fã\8cÀ\90Ý\92è\82ð\95\\8e¦(0\82Í\96³\8cø)
1608                                         ::SetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, ch->maxRelays, false);
1609                                         if (isIndexTxt(ch))
1610                                         {
1611                                                 // index.txt\82È\82Ì\82Å\96³\8cø\82É
1612                                                 ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_MAXRELAYS), false);
1613                                                 ::EnableWindow(::GetDlgItem(hDlg, IDC_APPLY_MAXRELAYS), false);
1614                                         }
1615                                 }else
1616                                 {
1617                                         SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LPARAM)"OK"); // x64\91Î\89\9e
1618                                         //SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)"OK");
1619                                         EnableWindow(GetDlgItem(hDlg,IDC_KEEP),false);
1620                                 }
1621
1622
1623
1624                                 POINT point;
1625                                 RECT rect,drect;
1626                                 HWND hDsk = GetDesktopWindow();
1627                                 GetWindowRect(hDsk,&drect);
1628                                 GetWindowRect(hDlg,&rect);
1629                                 GetCursorPos(&point);
1630
1631                                 POINT pos,size;
1632                                 size.x = rect.right-rect.left;
1633                                 size.y = rect.bottom-rect.top;
1634
1635                                 if (point.x-drect.left < size.x)
1636                                         pos.x = point.x;
1637                                 else
1638                                         pos.x = point.x-size.x;
1639
1640                                 if (point.y-drect.top < size.y)
1641                                         pos.y = point.y;
1642                                 else
1643                                         pos.y = point.y-size.y;
1644
1645                                 SetWindowPos(hDlg,HWND_TOPMOST,pos.x,pos.y,size.x,size.y,0);
1646                                 chWnd = hDlg;
1647                         }
1648                         return TRUE;
1649
1650                 case WM_COMMAND:
1651                         {
1652                                 char str[1024],idstr[64];
1653                                 chanInfo.id.toStr(idstr);
1654
1655                                 switch (LOWORD(wParam))
1656                                 {
1657                                 case IDC_CONTACT:
1658                                         {
1659                                                 sys->getURL(chanInfo.url);
1660                                                 return TRUE;
1661                                         }
1662                                 case IDC_DETAILS:
1663                                         {
1664                                                 sprintf(str,"admin?page=chaninfo&id=%s&relay=%d",idstr,chanInfoIsRelayed);
1665                                                 sys->callLocalURL(str,servMgr->serverHost.port);
1666                                                 return TRUE;
1667                                         }
1668                                 case IDC_KEEP:
1669                                         {
1670                                                 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1671                                                 if (ch)
1672                                                         ch->stayConnected = SendDlgItemMessage(hDlg, IDC_KEEP,BM_GETCHECK, 0, 0) == BST_CHECKED;;
1673                                                 return TRUE;
1674                                         }
1675
1676
1677                                 case IDC_PLAY:
1678                                         {
1679                                                 chanMgr->findAndPlayChannel(chanInfo,false);
1680                                                 return TRUE;
1681                                         }
1682
1683                                 case IDC_APPLY_MAXRELAYS:
1684                                         {
1685                                                 // \83`\83\83\83\93\83l\83\8b\8cÅ\97L\82Ì\8dÅ\91å\83\8a\83\8c\81[\90\94\82ð\90Ý\92è
1686                                                 BOOL bSucc;
1687                                                 unsigned int mr;
1688
1689                                                 // \93ü\97Í\92l\8eæ\93¾
1690                                                 mr = ::GetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, &bSucc, false);
1691
1692                                                 if (bSucc)
1693                                                 {
1694                                                         Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1695                                                         if (ch && !isIndexTxt(ch))
1696                                                         {
1697                                                                 ch->maxRelays = mr;
1698                                                         }
1699                                                 } else
1700                                                 {
1701                                                         MessageBox(hDlg, "\93ü\97Í\92l\82ª\95s\90³\82Å\82·\81B", "Error", MB_OK|MB_ICONERROR|MB_APPLMODAL);
1702                                                         Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1703                                                         if (ch)
1704                                                                 ::SetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, ch->maxRelays, false);
1705                                                 }
1706                                         }
1707                                 }
1708                         }
1709                         break;
1710
1711                 case WM_CLOSE:
1712                         if (winDistinctionNT)
1713                                 EndDialog(hDlg, 0);
1714                         else
1715                                 DestroyWindow(hDlg); //JP-Patch
1716                         break;
1717
1718                 case WM_ACTIVATE:
1719                         if (LOWORD(wParam) == WA_INACTIVE)
1720                                 if (winDistinctionNT)
1721                                         EndDialog(hDlg, 0);
1722                                 else
1723                                         DestroyWindow(hDlg); //JP-Patch
1724                         break;
1725                 case WM_DESTROY:
1726                         chWnd = NULL;
1727                         break;
1728
1729
1730         }
1731     return FALSE;
1732 }
1733
1734 // control thread (Traffic dialog)
1735 THREAD_PROC trafficDlgUpdate(ThreadInfo *thread)
1736 {
1737         thread->finish = false;
1738
1739         while (trafficDlg && thread->active)
1740         {
1741                 SendMessage(trafficDlg, WM_UPDATETRAFFIC, 0, 0);
1742                 Sleep(1000);
1743         }
1744
1745         thread->finish = true;
1746
1747         return 0;
1748 }
1749
1750 // Dialog procedure (Traffic dialog)
1751 LRESULT CALLBACK TrafficDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1752 {
1753         switch (message)
1754         {
1755         case WM_INITDIALOG:
1756                 // \8aù\82É\8aJ\82¢\82Ä\82é
1757                 if (trafficDlg || trafficDlgThread.active)
1758                 {
1759                         if (winDistinctionNT)
1760                                 EndDialog(hDlg, 0);
1761                         else
1762                                 DestroyWindow(hDlg);
1763                         return FALSE;
1764                 }
1765
1766                 trafficDlg = hDlg;
1767                 trafficDlgThread.func = trafficDlgUpdate;
1768                 if (!sys->startThread(&trafficDlgThread)){
1769                         MessageBox(NULL,"Unable to start GUI","PeerCast",MB_OK|MB_ICONERROR);
1770                         PostMessage(hDlg,WM_DESTROY,0,0);
1771                 }
1772
1773                 break;
1774
1775         case WM_UPDATETRAFFIC:
1776                 {
1777                         enum unitSymbol { B, KB, MB, GB };
1778                         const unsigned long int unit[] = { 1, 1024, 1024*1024, 1024*1024*1024 };
1779                         char suffix[][3] = { "B", "KB", "MB", "GB" };
1780                         const int bufsize = 60;
1781                         char szUp[bufsize], szDown[bufsize];
1782                         unsigned long long int totalDown = stats.getCurrent(Stats::BYTESIN) - stats.getCurrent(Stats::LOCALBYTESIN);
1783                         unsigned long long int totalUp = stats.getCurrent(Stats::BYTESOUT) - stats.getCurrent(Stats::LOCALBYTESOUT);
1784
1785                         // up
1786                         for (int i=GB; i>0; --i)
1787                         {
1788                                 if (totalUp >= unit[i])
1789                                 {
1790                                         sprintf_s<bufsize>(szUp, "%.2f%s", (double)totalUp/unit[i], suffix[i]);
1791                                         break;
1792                                 }
1793
1794                                 if (i == 1)
1795                                         sprintf_s<bufsize>(szUp, "%d%s", totalUp, suffix[0]);
1796                         }
1797
1798                         // down
1799                         for (int i=GB; i>0; --i)
1800                         {
1801                                 if (totalDown >= unit[i])
1802                                 {
1803                                         sprintf_s<bufsize>(szDown, "%.2f%s", (double)totalDown/unit[i], suffix[i]);
1804                                         break;
1805                                 }
1806
1807                                 if (i == 1)
1808                                         sprintf_s<bufsize>(szDown, "%d%s", totalDown, suffix[0]);
1809                         }
1810
1811                         SetDlgItemText(hDlg, IDC_STATIC_UP, szUp);
1812                         SetDlgItemText(hDlg, IDC_STATIC_DOWN, szDown);
1813                 }
1814                 break;
1815
1816         case WM_CLOSE:
1817                 trafficDlg = NULL;
1818                 trafficDlgThread.active = false;
1819                 if (winDistinctionNT)
1820                         EndDialog(hDlg, 0);
1821                 else
1822                         DestroyWindow(hDlg);
1823
1824                 break;
1825
1826         case WM_DESTROY:
1827                 break;
1828         }
1829
1830         return FALSE;
1831 }