1 // ------------------------------------------------
6 // Simple tray icon interface to PeerCast, mostly win32 related stuff.
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.
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 // ------------------------------------------------
29 #include "win32/wsys.h"
38 #include "chkMemoryLeak.h"
39 #define DEBUG_NEW new(__FILE__, __LINE__)
43 #define MAX_LOADSTRING 100
46 #define RELAY_CMD 8000
50 #define MAX_CHANNELS 999
55 void loadIcons(HINSTANCE hInstance, HWND hWnd);
58 UINT g_iTaskbarCreated = ~0; // for PCRaw (tray icon)
62 static int currNotify=0;
66 static HMENU trayMenu = NULL,ltrayMenu = NULL; // for PCRaw (tray icon)
68 bool allowMulti=false;
70 bool allowTrayMenu=true;
71 static bool winDistinctionNT=false;
72 int seenNewVersionTime=0;
75 bool chanInfoIsRelayed;
78 ULONG_PTR gdiplusToken;
81 ThreadInfo trafficDlgThread;
82 HWND trafficDlg = NULL;
85 bool jumpListEnabled = false; // jumplist flag (only for win7 or later)
87 //
\83v
\83\8d\83g
\83^
\83C
\83v
\90é
\8c¾
89 LRESULT CALLBACK TrafficDlgProc(HWND, UINT, WPARAM, LPARAM);
91 // ---------------------------------
92 Sys * APICALL MyPeercastInst::createSys()
94 return new WSys(mainWnd);
96 // ---------------------------------
97 const char * APICALL MyPeercastApp ::getIniFilename()
99 return iniFileName.cstr();
102 // ---------------------------------
103 const char *APICALL MyPeercastApp ::getClientTypeOS()
108 // ---------------------------------
109 const char * APICALL MyPeercastApp::getPath()
111 return exePath.cstr();
114 // --------------------------------- JP-EX
115 void APICALL MyPeercastApp ::openLogFile()
117 logFile.openWriteReplace("log.txt");
119 // --------------------------------- JP-EX
120 void APICALL MyPeercastApp ::getDirectory()
122 char path_buffer[256],drive[32],dir[128];
123 GetModuleFileName(NULL,path_buffer,255);
124 _splitpath(path_buffer,drive,dir,NULL,NULL);
125 sprintf(servMgr->modulePath,"%s%s",drive,dir);
127 // --------------------------------- JP-EX
128 bool APICALL MyPeercastApp ::clearTemp()
130 if (servMgr->clearPLS)
137 class NOTIFYICONDATA2
140 DWORD cbSize; // DWORD
144 UINT uCallbackMessage; // UINT
145 HICON hIcon; // HICON
146 char szTip[128]; // char[128]
147 DWORD dwState; // DWORD
148 DWORD dwStateMask; // DWORD
149 char szInfo[256]; // char[256]
150 UINT uTimeoutOrVersion; // UINT
151 char szInfoTitle[64]; // char[64]
152 DWORD dwInfoFlags; // DWORD
153 //GUID guidItem; > IE 6
156 NOTIFYICONDATA2 trayIcon;
160 HINSTANCE hInst; // current instance
161 TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
162 TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
163 TCHAR szWindowClass2[MAX_LOADSTRING]; // The title bar text
165 // Foward declarations of functions included in this code module:
166 ATOM MyRegisterClass(HINSTANCE hInstance);
167 ATOM MyRegisterClass2(HINSTANCE hInstance);
168 ATOM MyRegisterClass3(HINSTANCE hInstance);
169 BOOL InitInstance(HINSTANCE, int);
170 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
171 LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
172 LRESULT CALLBACK ChanInfoProc(HWND, UINT, WPARAM, LPARAM);
174 void setTrayIcon(int type, const char *,const char *,bool);
175 void flipNotifyPopup(int id, ServMgr::NOTIFY_TYPE nt);
180 // --------------------------------------------------
181 void LOG2(const char *fmt,...)
186 vsprintf(str,fmt,ap);
187 OutputDebugString(str);
191 // --------------------------------------------------
192 void WINAPI ServiceMain(DWORD argc, LPSTR *argv)
196 //iniFileName.set(".\\peercast.ini");
198 WIN32_FIND_DATA fd; //JP-EX
199 HANDLE hFind; //JP-EX
201 OSVERSIONINFO osInfo; //JP-EX
202 osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //JP-EX
203 GetVersionEx(&osInfo);
204 if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
205 winDistinctionNT = true;
207 winDistinctionNT = false;
209 // off by default now
217 ret = GetModuleFileName(NULL, buf, sizeof(buf)/sizeof(TCHAR));
222 for (int i=_tcslen(buf); i>0; --i)
234 iniFileName.set(exePath.cstr());
235 iniFileName.append("\\peercast.ini");
239 peercastInst = new MyPeercastInst();
240 peercastApp = new MyPeercastApp();
242 peercastInst->init();
244 LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x");
246 if (peercastApp->clearTemp()) //JP-EX
248 DeleteFile("play.pls");
249 hFind = FindFirstFile("*.asx",&fd);
250 if (hFind != INVALID_HANDLE_VALUE)
254 DeleteFile((char *)&fd.cFileName);
256 while (FindNextFile(hFind,&fd));
262 peercastInst->saveSettings();
263 peercastInst->quit();
266 // --------------------------------------------------
267 int WinMainDummy(HINSTANCE hInstance,
268 HINSTANCE hPrevInstance,
274 ::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
283 iniFileName.set(".\\peercast.ini");
285 WIN32_FIND_DATA fd; //JP-EX
286 HANDLE hFind; //JP-EX
288 OSVERSIONINFOEX osInfo; //JP-EX
289 osInfo.dwOSVersionInfoSize = sizeof(osInfo); //JP-EX
290 GetVersionEx(reinterpret_cast<LPOSVERSIONINFO>(&osInfo));
291 if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
292 winDistinctionNT = true;
294 winDistinctionNT = false;
296 // for Windows7 or later
297 if ((osInfo.wProductType == VER_NT_WORKSTATION
298 && osInfo.dwMajorVersion == 6
299 && osInfo.dwMinorVersion == 1)
301 (osInfo.dwMajorVersion == 6
302 && osInfo.dwMinorVersion > 1)
304 osInfo.dwMajorVersion > 6)
306 jumpListEnabled = true;
309 // off by default now
312 if (strlen(lpCmdLine) > 0)
315 if ((p = strstr(lpCmdLine,"-inifile"))!=NULL)
316 iniFileName.setFromString(p+8);
318 if (strstr(lpCmdLine,"-zen"))
321 if (strstr(lpCmdLine,"-multi"))
324 if (strstr(lpCmdLine,"-kill"))
327 if ((p = strstr(lpCmdLine,"-url"))!=NULL)
342 strncpy(tmpURL,p,sizeof(tmpURL)-1);
348 exePath = iniFileName;
349 char *s = exePath.cstr();
361 if (strnicmp(tmpURL,"peercast://",11)==0)
363 if (strnicmp(tmpURL+11,"pls/",4)==0)
364 chanURL = tmpURL+11+4;
374 // Initialize global strings
375 //LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
376 //LoadString(hInstance, IDC_APP_TITLE, szWindowClass, MAX_LOADSTRING);
378 strcpy(szTitle,"PeerCast");
379 strcpy(szWindowClass,"PeerCast");
380 strcpy(szWindowClass2,"Main");
384 HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass);
386 if (GetLastError() == ERROR_ALREADY_EXISTS)
388 HWND oldWin = FindWindow(szWindowClass,NULL);
391 //SendMessage(oldWin,WM_SHOWGUI,0,0);
394 SendMessage(oldWin,WM_DESTROY,0,0);
401 copy.dwData = WM_PLAYCHANNEL;
402 copy.cbData = strlen(chanURL)+1; // plus null term
403 copy.lpData = chanURL;
404 SendMessage(oldWin,WM_COPYDATA,NULL,(LPARAM)©);
407 SendMessage(oldWin,WM_SHOWGUI,0,0);
417 MyRegisterClass(hInstance);
418 MyRegisterClass2(hInstance);
420 // Perform application initialization:
421 if (!InitInstance (hInstance, nCmdShow))
424 peercastInst = new MyPeercastInst();
425 peercastApp = new MyPeercastApp();
427 peercastInst->init();
429 LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x");
431 if (peercastApp->clearTemp()) //JP-EX
433 DeleteFile("play.pls");
434 hFind = FindFirstFile("*.asx",&fd);
435 if (hFind != INVALID_HANDLE_VALUE)
439 DeleteFile((char *)&fd.cFileName);
441 while (FindNextFile(hFind,&fd));
450 servMgr->procConnectArgs(chanURL,info);
451 chanMgr->findAndPlayChannel(info,false);
454 hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLE);
456 // setup menu notifes
457 int mask = peercastInst->getNotifyMask();
458 if (mask & ServMgr::NT_PEERCAST)
459 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_PEERCAST,MF_CHECKED|MF_BYCOMMAND);
460 if (mask & ServMgr::NT_BROADCASTERS)
461 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_BROADCASTERS,MF_CHECKED|MF_BYCOMMAND);
462 if (mask & ServMgr::NT_TRACKINFO)
463 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_TRACKINFO,MF_CHECKED|MF_BYCOMMAND);
465 if (servMgr->startWithGui)
470 // Main message loop:
471 while (GetMessage(&msg, NULL, 0, 0))
473 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
475 TranslateMessage(&msg);
476 DispatchMessage(&msg);
480 Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon);
482 peercastInst->saveSettings();
483 peercastInst->quit();
485 Gdiplus::GdiplusShutdown(gdiplusToken);
491 // ---------------------------------------
492 int APIENTRY WinMain(HINSTANCE hInstance,
493 HINSTANCE hPrevInstance,
498 _EXCEPTION_POINTERS *lpExcept;
503 if (lstrlen(lpCmdLine) && strstr(lpCmdLine, "-D") != NULL)
505 SERVICE_TABLE_ENTRY svctbl[] = {
506 {"PeerCast", (LPSERVICE_MAIN_FUNCTION)ServiceMain},
510 if (!StartServiceCtrlDispatcher(svctbl))
512 //SvcReportEvent(TEXT("StartServiceCtrlDispatcher"));
516 WinMainDummy(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
517 } __except(lpExcept = GetExceptionInformation(), EXCEPTION_EXECUTE_HANDLER)
521 fs.openWriteReplace(".\\dump.txt");
522 fs.writeLine("Exception Point: WinMain");
523 fs.write("Exception: ", 11);
524 switch (lpExcept->ExceptionRecord->ExceptionCode)
526 case EXCEPTION_ACCESS_VIOLATION:
527 fs.writeLine("Access violation");
530 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
531 case EXCEPTION_INT_DIVIDE_BY_ZERO:
532 fs.writeLine("Divide by zero");
535 case EXCEPTION_STACK_OVERFLOW:
536 fs.writeLine("Stack overflow");
540 fs.writeLong(lpExcept->ExceptionRecord->ExceptionCode);
544 fs.writeLineF("Address: %p", lpExcept->ExceptionRecord->ExceptionAddress);
546 fs.writeLine("Additional information:");
547 nParams = lpExcept->ExceptionRecord->NumberParameters;
548 for (unsigned i=0; i<nParams; ++i)
550 fs.writeLineF("%d: %lu", i, lpExcept->ExceptionRecord->ExceptionInformation[i]);
555 fs.openWriteReplace(".\\dump.html");
556 sys->logBuf->dumpHTML(fs);
559 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"
560 "
\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",
561 MB_OK|MB_ICONWARNING);
563 return GetExceptionCode();
573 // FUNCTION: MyRegisterClass()
575 // PURPOSE: Registers the window class.
579 // This function and its usage is only necessary if you want this code
580 // to be compatible with Win32 systems prior to the 'RegisterClassEx'
581 // function that was added to Windows 95. It is important to call this function
582 // so that the application will get 'well formed' small icons associated
585 ATOM MyRegisterClass(HINSTANCE hInstance)
589 wcex.cbSize = sizeof(WNDCLASSEX);
591 wcex.style = CS_HREDRAW | CS_VREDRAW;
592 wcex.lpfnWndProc = (WNDPROC)WndProc;
595 wcex.hInstance = hInstance;
596 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLE);
597 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
598 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
599 // wcex.lpszMenuName = (LPCSTR)IDC_SIMPLE;
600 wcex.lpszMenuName = NULL;
601 wcex.lpszClassName = szWindowClass;
602 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
604 return RegisterClassEx(&wcex);
607 ATOM MyRegisterClass2(HINSTANCE hInstance)
611 wcex.cbSize = sizeof(WNDCLASSEX);
613 wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ;
614 wcex.lpfnWndProc = (WNDPROC)GUIProc;
617 wcex.hInstance = hInstance;
618 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLE);
619 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
620 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
621 // wcex.lpszMenuName = (LPCSTR)IDC_SIMPLE;
622 wcex.lpszMenuName = NULL;
623 wcex.lpszClassName = szWindowClass2;
624 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
626 return RegisterClassEx(&wcex);
629 //-----------------------------
630 void loadIcons(HINSTANCE hInstance, HWND hWnd)
632 icon1 = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL);
633 icon2 = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL2);
635 trayIcon.cbSize = sizeof(trayIcon);
636 trayIcon.hWnd = hWnd;
638 trayIcon.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP;
639 trayIcon.uCallbackMessage = WM_TRAYICON;
640 trayIcon.hIcon = icon1;
641 strcpy(trayIcon.szTip, "PeerCast");
643 Shell_NotifyIcon(NIM_ADD, (NOTIFYICONDATA*)&trayIcon);
645 //ShowWindow(hWnd, nCmdShow);
648 if(!trayMenu) // for PCRaw (tray icon)
649 trayMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_TRAYMENU));
650 if(!ltrayMenu) // for PCRaw (tray icon)
651 ltrayMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_LTRAYMENU));
656 //-----------------------------
658 // FUNCTION: InitInstance(HANDLE, int)
660 // PURPOSE: Saves instance handle and creates main window
664 // In this function, we save the instance handle in a global variable and
665 // create and display the main program window.
667 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
671 hInst = hInstance; // Store instance handle in our global variable
673 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
674 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
683 g_iTaskbarCreated = RegisterWindowMessage("TaskbarCreated"); // for PCRaw (tray icon)
685 loadIcons(hInstance,hWnd);
687 using namespace Gdiplus;
688 GdiplusStartupInput gdiplusStartupInput;
689 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
693 //-----------------------------
694 //static String trackTitle;
695 //static String channelComment;
697 //-----------------------------
698 void channelPopup(const char *title, const char *msg, bool isPopup = true)
702 if (*title == '\0') return;
708 trayIcon.uFlags = NIF_ICON|NIF_TIP;
709 strncpy(trayIcon.szTip, both.cstr(),sizeof(trayIcon.szTip)-1);
710 trayIcon.szTip[sizeof(trayIcon.szTip)-1]=0;
712 if (isPopup) trayIcon.uFlags |= 16;
713 trayIcon.uTimeoutOrVersion = 10000;
714 strncpy(trayIcon.szInfo,msg,sizeof(trayIcon.szInfo)-1);
715 strncpy(trayIcon.szInfoTitle,title,sizeof(trayIcon.szInfoTitle)-1);
717 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
719 //-----------------------------
720 void clearChannelPopup()
722 trayIcon.uFlags = NIF_ICON|16;
723 trayIcon.uTimeoutOrVersion = 10000;
724 strncpy(trayIcon.szInfo,"",sizeof(trayIcon.szInfo)-1);
725 strncpy(trayIcon.szInfoTitle,"",sizeof(trayIcon.szInfoTitle)-1);
726 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
729 //-----------------------------
738 static PopupEntry *PEList = NULL;
741 static void putPopupEntry(PopupEntry *pe)
749 static PopupEntry *getPopupEntry(GnuID id)
752 PopupEntry *pe = PEList;
753 PopupEntry *prev = NULL;
755 if (id.isSame(pe->id)) {
756 if (prev) prev->next = pe->next;
757 else PEList = pe->next;
769 static PopupEntry *getTopPopupEntry()
771 PopupEntry *p = NULL;
775 PEList = PEList->next;
781 //-----------------------------
782 void APICALL MyPeercastApp::channelStart(ChanInfo *info)
785 // lastPlayID = info->id;
787 // if(!isIndexTxt(info)) // for PCRaw (popup)
788 // clearChannelPopup();
790 PopupEntry *pe = getPopupEntry(info->id);
795 if (!isIndexTxt(info))
800 //-----------------------------
801 void APICALL MyPeercastApp::channelStop(ChanInfo *info)
803 // if (info->id.isSame(lastPlayID))
805 // lastPlayID.clear();
807 // if(!isIndexTxt(info)) // for PCRaw (popup)
808 // clearChannelPopup();
811 PopupEntry *pe = getPopupEntry(info->id);
814 pe = getTopPopupEntry();
818 if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
820 String name,track; //JP-Patch
821 name = pe->name; //JP-Patch
822 track = pe->track; //JP-Patch
823 name.convertTo(String::T_SJIS); //JP-Patch
824 track.convertTo(String::T_SJIS); //JP-Patch
826 // channelPopup(info->name.cstr(),trackTitle.cstr());
827 channelPopup(name.cstr(),track.cstr(), false); //JP-Patch
832 //-----------------------------
833 void APICALL MyPeercastApp::channelUpdate(ChanInfo *info)
837 PopupEntry *pe = getPopupEntry(info->id);
841 tmp.append(info->track.artist);
843 tmp.append(info->track.title);
846 if (!tmp.isSame(pe->track))
848 pe->name = info->name;
850 if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
853 String name,track; //JP-Patch
854 name = info->name; //JP-Patch
855 track = tmp; //JP-Patch
856 name.convertTo(String::T_SJIS); //JP-Patch
857 track.convertTo(String::T_SJIS); //JP-Patch
858 if(!isIndexTxt(info)) // for PCRaw (popup)
861 // channelPopup(info->name.cstr(),trackTitle.cstr());
862 channelPopup(name.cstr(),track.cstr()); //JP-Patch
865 } else if (!info->comment.isSame(pe->comment))
867 pe->name = info->name;
868 pe->comment = info->comment;
869 if (ServMgr::NT_BROADCASTERS & peercastInst->getNotifyMask())
871 //channelComment = info->comment;
872 String name,comment; //JP-Patch
873 name = info->name; //JP-Patch
874 comment = info->comment; //JP-Patch
875 name.convertTo(String::T_SJIS); //JP-Patch
876 comment.convertTo(String::T_SJIS); //JP-Patch
877 if(!isIndexTxt(info)) // for PCRaw (popup)
880 // channelPopup(info->name.cstr(),channelComment.cstr());
881 channelPopup(name.cstr(),comment.cstr());
886 if (!isIndexTxt(info))
892 //-----------------------------
893 void APICALL MyPeercastApp::notifyMessage(ServMgr::NOTIFY_TYPE type, const char *msg)
895 static bool shownUpgradeAlert=false;
901 if (!shownUpgradeAlert)
903 trayIcon.uFlags = NIF_ICON;
905 if (type == ServMgr::NT_UPGRADE)
907 shownUpgradeAlert = true;
908 trayIcon.hIcon = icon2;
911 trayIcon.hIcon = icon1;
915 if (type == ServMgr::NT_UPGRADE)
919 const char *title="";
923 case ServMgr::NT_UPGRADE:
924 title = "Upgrade alert";
926 case ServMgr::NT_PEERCAST:
927 title = "Message from PeerCast:";
932 if (type & peercastInst->getNotifyMask())
934 trayIcon.uFlags |= 16;
935 trayIcon.uTimeoutOrVersion = 10000;
936 strncpy(trayIcon.szInfo,msg,sizeof(trayIcon.szInfo)-1);
937 strncpy(trayIcon.szInfoTitle,title,sizeof(trayIcon.szInfoTitle)-1);
938 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
941 //-----------------------------
945 void createGUI(HWND hWnd)
948 guiWnd = ::CreateWindow(szWindowClass2,
950 WS_OVERLAPPEDWINDOW & ~(WS_MAXIMIZEBOX) /*| WS_VSCROLL | WS_HSCROLL*/,
960 ShowWindow(guiWnd,SW_SHOWNORMAL);
962 //
\8e©
\93®
\82Å
\8dÅ
\91O
\96Ê
963 if (servMgr->topmostGui)
965 ::SetWindowPos(guiWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
971 // addRelayedChannelsMenu(HMENU m)
974 void addRelayedChannelsMenu(HMENU cm)
976 int cnt = GetMenuItemCount(cm);
977 for(int i=0; i<cnt-3; i++)
978 DeleteMenu(cm,0,MF_BYPOSITION);
980 Channel *c = chanMgr->channel;
985 char str[128],name[64];
986 strncpy(name,c->info.name,32);
988 if (strlen(c->info.name) > 32)
992 sprintf(str,"%s (%d kb/s %s)",name,c->info.bitrate,ChanInfo::getTypeStr(c->info.contentType));
993 //InsertMenu(cm,0,MF_BYPOSITION,RELAY_CMD+i,str);
999 typedef int (*COMPARE_FUNC)(const void *,const void *);
1001 static int compareHitLists(ChanHitList **c2, ChanHitList **c1)
1003 return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());
1006 static int compareChannels(Channel **c2, Channel **c1)
1008 return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());
1012 // addAllChannelsMenu(HMENU m)
1015 void addAllChannelsMenu(HMENU cm)
1017 int cnt = GetMenuItemCount(cm);
1018 /* for(int i=0; i<cnt-2; i++)
1019 DeleteMenu(cm,0,MF_BYPOSITION);*/
1021 for(int i=0; i<cnt; i++)
1022 DeleteMenu(cm,0,MF_BYPOSITION);
1024 HMENU yMenu = CreatePopupMenu();
1025 if (!servMgr->rootHost2.isEmpty()){
1026 InsertMenu(yMenu,0,MF_BYPOSITION,ID_POPUP_YELLOWPAGES2,servMgr->rootHost2);
1028 if (!servMgr->rootHost.isEmpty()){
1029 InsertMenu(yMenu,0,MF_BYPOSITION,ID_POPUP_YELLOWPAGES1,servMgr->rootHost);
1032 InsertMenu(cm,0,MF_BYPOSITION|MF_POPUP,(UINT)yMenu,"
\83C
\83G
\83\8d\81[
\83y
\81[
\83W");
1033 InsertMenu(cm,0,MF_BYPOSITION|MF_SEPARATOR,NULL,NULL);
1034 // add channels to menu
1036 Channel *ch = chanMgr->channel;
1039 char str[128],name[64];
1040 String sjis; //JP-Patch
1041 sjis = ch->info.name; //JP-Patch
1042 sjis.convertTo(String::T_SJIS); //JP-Patch
1043 strncpy(name,sjis.cstr(),32);
1044 //strncpy(name,ch->info.name,32);
1046 //if (strlen(ch->info.name) > 32)
1047 if (strlen(sjis.cstr()) > 32) //JP-Patch
1050 sprintf(str,"%s (%d kb/s %s)",name,ch->info.bitrate,ChanInfo::getTypeStr(ch->info.contentType));
1052 HMENU opMenu = CreatePopupMenu();
1053 InsertMenu(opMenu,0,MF_BYPOSITION,INFO_CMD+numActive,"Info");
1054 if (ch->info.url.isValidURL())
1055 InsertMenu(opMenu,0,MF_BYPOSITION,URL_CMD+numActive,"URL");
1056 InsertMenu(opMenu,0,MF_BYPOSITION,PLAY_CMD+numActive,"Play");
1058 UINT fl = MF_BYPOSITION|MF_POPUP;
1060 fl |= (ch->isPlaying()?MF_CHECKED:0);
1062 InsertMenu(cm,0,fl,(UINT)opMenu,str);
1071 // InsertMenu(cm,0,MF_BYPOSITION,0,"<No channels>");
1080 // flipNotifyPopup(id, flag)
1081 void flipNotifyPopup(int id, ServMgr::NOTIFY_TYPE nt)
1083 int mask = peercastInst->getNotifyMask();
1087 CheckMenuItem(trayMenu,id,MF_CHECKED|MF_BYCOMMAND);
1089 CheckMenuItem(trayMenu,id,MF_UNCHECKED|MF_BYCOMMAND);
1091 peercastInst->setNotifyMask(mask);
1092 peercastInst->saveSettings();
1096 static void showHTML(const char *file)
1099 sprintf(url,"%s/%s",servMgr->htmlPath,file);
1101 // sys->callLocalURL(url,servMgr->serverHost.port);
1102 sys->callLocalURL(url, // for PCRaw (url)
1103 (servMgr->allowServer1&Servent::ALLOW_HTML)?(servMgr->serverHost.port):(servMgr->serverHost.port+1));
1106 static ChanInfo getChannelInfo(int index)
1108 Channel *c = chanMgr->findChannelByIndex(index);
1117 // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
1119 // PURPOSE: Processes messages for the main window.
1121 // WM_COMMAND - process the application menu
1122 // WM_PAINT - Paint the main window
1123 // WM_DESTROY - post a quit message and return
1126 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1132 if(message == g_iTaskbarCreated) // for PCRaw (tray icon)
1133 loadIcons(hInst, hWnd);
1143 switch((UINT)lParam)
1145 case WM_LBUTTONDOWN:
1147 SendMessage(hWnd,WM_SHOWMENU,2,0);
1148 SetForegroundWindow(hWnd);
1150 case WM_RBUTTONDOWN:
1152 SendMessage(hWnd,WM_SHOWMENU,1,0);
1153 SetForegroundWindow(hWnd);
1155 case WM_LBUTTONDBLCLK:
1163 COPYDATASTRUCT *pc = (COPYDATASTRUCT *)lParam;
1164 LOG_DEBUG("URL request: %s",pc->lpData);
1165 if (pc->dwData == WM_PLAYCHANNEL)
1168 servMgr->procConnectArgs((char *)pc->lpData,info);
1169 chanMgr->findAndPlayChannel(info,false);
1171 //sys->callLocalURL((const char *)pc->lpData,servMgr->serverHost.port);
1174 case WM_GETPORTNUMBER:
1177 port=servMgr->serverHost.port;
1184 if (servMgr->saveGuiPos){
1185 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_CHECKED|MF_BYCOMMAND);
1187 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_UNCHECKED|MF_BYCOMMAND);
1190 //
\8e©
\93®GUI/
\8dÅ
\91O
\96Ê
\8b@
\94\
1191 if (servMgr->topmostGui)
1193 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_CHECKED|MF_BYCOMMAND);
1196 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_UNCHECKED|MF_BYCOMMAND);
1199 if (servMgr->startWithGui)
1201 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_CHECKED|MF_BYCOMMAND);
1204 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_UNCHECKED|MF_BYCOMMAND);
1207 //
\83X
\83N
\83\8a\81[
\83\93\83Z
\81[
\83o
\81[
\97}
\8e~
1208 if (servMgr->preventSS)
1210 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_CHECKED|MF_BYCOMMAND);
1213 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_UNCHECKED|MF_BYCOMMAND);
1216 //
\83o
\81[
\83W
\83\87\83\93\83`
\83F
\83b
\83N
\82Ì
\97L
\96³
1217 if (servMgr->noVersionCheck)
1219 CheckMenuItem(trayMenu, ID_POPUP_NO_VER_CHECK, MF_CHECKED|MF_BYCOMMAND);
1222 CheckMenuItem(trayMenu, ID_POPUP_NO_VER_CHECK, MF_UNCHECKED|MF_BYCOMMAND);
1225 SetForegroundWindow(hWnd);
1226 bool skipMenu=false;
1228 allowTrayMenu = false;
1230 // check for notifications
1231 if (currNotify & ServMgr::NT_UPGRADE)
1233 if (servMgr->downloadURL[0])
1235 if ((sys->getTime()-seenNewVersionTime) > (60*60)) // notify every hour
1237 if (MessageBox(hWnd,"A newer version of PeerCast is available, press OK to upgrade.","PeerCast",MB_OKCANCEL|MB_APPLMODAL|MB_ICONEXCLAMATION) == IDOK)
1238 sys->getURL(servMgr->downloadURL);
1240 seenNewVersionTime=sys->getTime();
1253 SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWnd, 0);
1254 GetCursorPos(&point);
1256 if (point.x < rcWnd.left){
1257 point.x = rcWnd.left;
1258 flg |= TPM_LEFTALIGN;
1260 if (point.x > rcWnd.right){
1261 point.x = rcWnd.right;
1262 flg |= TPM_RIGHTALIGN;
1264 if (point.y < rcWnd.top){
1265 point.y = rcWnd.top;
1266 flg |= TPM_TOPALIGN;
1268 if (point.y > rcWnd.bottom){
1269 point.y = rcWnd.bottom;
1270 flg |= TPM_BOTTOMALIGN;
1273 flg = TPM_RIGHTALIGN;
1279 menu = GetSubMenu(trayMenu,0);
1280 addAllChannelsMenu(GetSubMenu(menu,0));
1281 addRelayedChannelsMenu(GetSubMenu(menu,1));
1284 menu = GetSubMenu(ltrayMenu,0);
1285 addAllChannelsMenu(menu);
1288 if (!TrackPopupMenu(menu,flg,point.x,point.y,0,hWnd,NULL))
1290 LOG_ERROR("Can`t track popup menu: %d",GetLastError());
1292 PostMessage(hWnd,WM_NULL,0,0);
1295 allowTrayMenu = true;
1305 wmId = LOWORD(wParam);
1306 wmEvent = HIWORD(wParam);
1308 if ((wmId >= INFO_CMD) && (wmId < INFO_CMD+MAX_CHANNELS))
1310 int c = wmId - INFO_CMD;
1311 chanInfo = getChannelInfo(c);
1312 chanInfoIsRelayed = false;
1313 if (winDistinctionNT)
1314 DialogBox(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc);
1317 HWND WKDLG; //JP-Patch
1318 WKDLG = CreateDialog(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc); //JP-Patch
1319 ShowWindow(WKDLG,SW_SHOWNORMAL); //JP-Patch
1323 if ((wmId >= URL_CMD) && (wmId < URL_CMD+MAX_CHANNELS))
1325 int c = wmId - URL_CMD;
1326 chanInfo = getChannelInfo(c);
1327 if (chanInfo.url.isValidURL())
1328 sys->getURL(chanInfo.url);
1331 if ((wmId >= PLAY_CMD) && (wmId < PLAY_CMD+MAX_CHANNELS))
1333 int c = wmId - PLAY_CMD;
1334 chanInfo = getChannelInfo(c);
1335 chanMgr->findAndPlayChannel(chanInfo,false);
1338 if ((wmId >= RELAY_CMD) && (wmId < RELAY_CMD+MAX_CHANNELS))
1340 int c = wmId - RELAY_CMD;
1341 chanInfo = getChannelInfo(c);
1342 chanMgr->findAndPlayChannel(chanInfo,true);
1346 // Parse the menu selections:
1349 case ID_POPUP_SHOWMESSAGES_PEERCAST:
1350 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_PEERCAST,ServMgr::NT_PEERCAST);
1352 case ID_POPUP_SHOWMESSAGES_BROADCASTERS:
1353 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_BROADCASTERS,ServMgr::NT_BROADCASTERS);
1355 case ID_POPUP_SHOWMESSAGES_TRACKINFO:
1356 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_TRACKINFO,ServMgr::NT_TRACKINFO);
1359 case ID_POPUP_ABOUT:
1361 DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
1363 case ID_POPUP_SHOWGUI:
1364 case IDM_SETTINGS_GUI:
1365 case ID_POPUP_ADVANCED_SHOWGUI:
1370 case ID_POPUP_YELLOWPAGES:
1371 sys->getURL("http://yp.peercast.org/");
1373 case ID_POPUP_YELLOWPAGES1:
1374 sprintf(buf, "http://%s",servMgr->rootHost.cstr());
1377 case ID_POPUP_YELLOWPAGES2:
1378 sprintf(buf, "http://%s",servMgr->rootHost2.cstr());
1382 case ID_POPUP_ADVANCED_VIEWLOG:
1383 showHTML("viewlog.html");
1385 case ID_POPUP_ADVANCED_SAVESETTINGS:
1386 servMgr->saveSettings(iniFileName.cstr());
1388 case ID_POPUP_ADVANCED_INFORMATION:
1389 showHTML("index.html");
1391 case ID_FIND_CHANNELS:
1392 case ID_POPUP_ADVANCED_ALLCHANNELS:
1393 case ID_POPUP_UPGRADE:
1394 sys->callLocalURL("admin?cmd=upgrade",servMgr->serverHost.port);
1396 case ID_POPUP_ADVANCED_RELAYEDCHANNELS:
1397 case ID_POPUP_FAVORITES_EDIT:
1398 showHTML("relays.html");
1400 case ID_POPUP_ADVANCED_BROADCAST:
1401 showHTML("broadcast.html");
1403 case ID_POPUP_SETTINGS:
1404 showHTML("settings.html");
1406 case ID_POPUP_CONNECTIONS:
1407 showHTML("connections.html");
1410 sys->getURL("http://www.peercast.org/help.php");
1413 case ID_POPUP_SAVE_GUI_POS:
1414 if (servMgr->saveGuiPos){
1415 servMgr->saveGuiPos = false;
1416 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_UNCHECKED|MF_BYCOMMAND);
1418 servMgr->saveGuiPos = true;
1419 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_CHECKED|MF_BYCOMMAND);
1421 peercastInst->saveSettings();
1424 case ID_POPUP_KEEP_DOWNSTREAMS:
1425 if (servMgr->keepDownstreams){
1426 servMgr->keepDownstreams = false;
1427 CheckMenuItem(trayMenu, ID_POPUP_KEEP_DOWNSTREAMS, MF_UNCHECKED|MF_BYCOMMAND);
1429 servMgr->keepDownstreams = true;
1430 CheckMenuItem(trayMenu, ID_POPUP_KEEP_DOWNSTREAMS, MF_CHECKED|MF_BYCOMMAND);
1432 //peercastInst->saveSettings();
1435 case ID_POPUP_TOPMOST:
1436 //
\8dÅ
\91O
\96Ê
\95\
\8e¦
1437 if (servMgr->topmostGui)
1439 servMgr->topmostGui = false;
1440 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_UNCHECKED|MF_BYCOMMAND);
1443 servMgr->topmostGui = true;
1444 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_CHECKED|MF_BYCOMMAND);
1446 peercastInst->saveSettings();
1449 case ID_POPUP_START_WITH_GUI:
1450 //
\8bN
\93®
\8e\9e\82ÉGUI
\95\
\8e¦
1451 if (servMgr->startWithGui)
1453 servMgr->startWithGui = false;
1454 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_UNCHECKED|MF_BYCOMMAND);
1457 servMgr->startWithGui = true;
1458 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_CHECKED|MF_BYCOMMAND);
1460 peercastInst->saveSettings();
1463 case ID_POPUP_TRAFFIC:
1464 //
\83g
\83\89\83t
\83B
\83b
\83N
\83\82\83j
\83^
\8bN
\93®
1465 if (winDistinctionNT)
1466 DialogBox(hInst, (LPCTSTR)IDD_TRAFFIC, hWnd, (DLGPROC)TrafficDlgProc);
1469 HWND WKDLG; //JP-Patch
1470 WKDLG = CreateDialog(hInst, (LPCTSTR)IDD_TRAFFIC, hWnd, (DLGPROC)TrafficDlgProc); //JP-Patch
1471 ShowWindow(WKDLG,SW_SHOWNORMAL); //JP-Patch
1475 case ID_POPUP_PREVENT_SS:
1476 //
\83X
\83N
\83\8a\81[
\83\93\83Z
\81[
\83o
\81[
\97}
\8e~
1477 if (servMgr->preventSS)
1479 servMgr->preventSS = false;
1480 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_UNCHECKED|MF_BYCOMMAND);
1483 servMgr->preventSS = true;
1484 CheckMenuItem(trayMenu, ID_POPUP_PREVENT_SS, MF_CHECKED|MF_BYCOMMAND);
1486 peercastInst->saveSettings();
1489 case ID_POPUP_NO_VER_CHECK:
1490 //
\83o
\81[
\83W
\83\87\83\93\83`
\83F
\83b
\83N
\82Ì
\97L
\96³
1491 if (servMgr->noVersionCheck)
1493 servMgr->noVersionCheck = false;
1494 CheckMenuItem(trayMenu, ID_POPUP_NO_VER_CHECK, MF_UNCHECKED|MF_BYCOMMAND);
1497 servMgr->noVersionCheck = true;
1498 CheckMenuItem(trayMenu, ID_POPUP_NO_VER_CHECK, MF_CHECKED|MF_BYCOMMAND);
1500 peercastInst->saveSettings();
1503 case ID_POPUP_EXIT_CONFIRM:
1505 DestroyWindow(hWnd);
1508 return DefWindowProc(hWnd, message, wParam, lParam);
1516 //
\82È
\82ñ
\82©
\83A
\83N
\83e
\83B
\83u
\82¶
\82á
\82È
\82¢
\82Æ
\91\97\82ç
\82ê
\82Ä
\82±
\82È
\82¢
\82ç
\82µ
\82¢
1517 if (servMgr->preventSS && (wParam == SC_SCREENSAVE) && chanMgr->isBroadcasting())
1520 return DefWindowProc(hWnd, message, wParam, lParam);
1524 return DefWindowProc(hWnd, message, wParam, lParam);
1528 // Mesage handler for about box.
1529 LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1534 //SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENT);
1535 // SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTJP);
1538 SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LPARAM)PCX_AGENTEX); // x64
\91Î
\89\9e
1541 SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTVP);
1547 switch (LOWORD(wParam))
1551 EndDialog(hDlg, LOWORD(wParam));
1554 sys->getURL("http://www.peercast.org");
1555 EndDialog(hDlg, LOWORD(wParam));
1566 // Mesage handler for chaninfo box
1567 LRESULT CALLBACK ChanInfoProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1574 //strcpy(str,chanInfo.track.artist.cstr());
1575 strcpy(str,chanInfo.track.artist); //JP-Patch
1577 //strcat(str,chanInfo.track.title.cstr());
1578 strcat(str,chanInfo.track.title);
1579 String name,track,comment,desc,genre; //JP-Patch
1580 name = chanInfo.name; //JP-Patch
1581 track = str; //JP-Patch
1582 comment = chanInfo.comment; //JP-Patch
1583 desc = chanInfo.desc; //JP-Patc
1584 genre = chanInfo.genre; //JP-Patch
1585 name.convertTo(String::T_SJIS); //JP-Patc
1586 track.convertTo(String::T_SJIS); //JP-Patch
1587 comment.convertTo(String::T_SJIS); //JP-Patch
1588 desc.convertTo(String::T_SJIS); //JP-Patch
1589 genre.convertTo(String::T_SJIS); //JP-Patch
1591 //SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)chanInfo.name.cstr());
1592 SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LPARAM)name.cstr()); // x64
\91Î
\89\9e
1593 //SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)name.cstr()); //JP-Patch
1594 //SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)str);
1595 SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LPARAM)track.cstr()); // x64
\91Î
\89\9e
1596 //SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)track.cstr()); //JP-Patch
1597 //SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)chanInfo.comment.cstr());
1598 SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LPARAM)comment.cstr()); // x64
\91Î
\89\9e
1599 //SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)comment.cstr()); //JP-Patch
1600 //SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)chanInfo.desc.cstr());
1601 SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LPARAM)desc.cstr()); // x64
\91Î
\89\9e
1602 //SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)desc.cstr()); //JP-Patch
1603 //SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)chanInfo.genre.cstr());
1604 SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LPARAM)genre.cstr()); // x64
\91Î
\89\9e
1605 //SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)genre.cstr()); //JP-Patch
1607 sprintf(str,"%d kb/s %s",chanInfo.bitrate,ChanInfo::getTypeStr(chanInfo.contentType));
1608 SendDlgItemMessage(hDlg,IDC_FORMAT,WM_SETTEXT,0,(LPARAM)str); // x64
\91Î
\89\9e
1609 //SendDlgItemMessage(hDlg,IDC_FORMAT,WM_SETTEXT,0,(LONG)str);
1612 if (!chanInfo.url.isValidURL())
1613 EnableWindow(GetDlgItem(hDlg,IDC_CONTACT),false);
1615 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1618 SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LPARAM)ch->getStatusStr()); // x64
\91Î
\89\9e
1619 //SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)ch->getStatusStr());
1620 SendDlgItemMessage(hDlg, IDC_KEEP,BM_SETCHECK, ch->stayConnected, 0);
1622 //
\8c»
\8dÝ
\82Ì
\8cÅ
\97L
\83\8a\83\8c\81[
\8fã
\8cÀ
\90Ý
\92è
\82ð
\95\
\8e¦(0
\82Í
\96³
\8cø)
1623 ::SetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, ch->maxRelays, false);
1626 // index.txt
\82È
\82Ì
\82Å
\96³
\8cø
\82É
1627 ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_MAXRELAYS), false);
1628 ::EnableWindow(::GetDlgItem(hDlg, IDC_APPLY_MAXRELAYS), false);
1632 SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LPARAM)"OK"); // x64
\91Î
\89\9e
1633 //SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)"OK");
1634 EnableWindow(GetDlgItem(hDlg,IDC_KEEP),false);
1641 HWND hDsk = GetDesktopWindow();
1642 GetWindowRect(hDsk,&drect);
1643 GetWindowRect(hDlg,&rect);
1644 GetCursorPos(&point);
1647 size.x = rect.right-rect.left;
1648 size.y = rect.bottom-rect.top;
1650 if (point.x-drect.left < size.x)
1653 pos.x = point.x-size.x;
1655 if (point.y-drect.top < size.y)
1658 pos.y = point.y-size.y;
1660 SetWindowPos(hDlg,HWND_TOPMOST,pos.x,pos.y,size.x,size.y,0);
1667 char str[1024],idstr[64];
1668 chanInfo.id.toStr(idstr);
1670 switch (LOWORD(wParam))
1674 sys->getURL(chanInfo.url);
1679 sprintf(str,"admin?page=chaninfo&id=%s&relay=%d",idstr,chanInfoIsRelayed);
1680 sys->callLocalURL(str,servMgr->serverHost.port);
1685 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1687 ch->stayConnected = SendDlgItemMessage(hDlg, IDC_KEEP,BM_GETCHECK, 0, 0) == BST_CHECKED;;
1694 chanMgr->findAndPlayChannel(chanInfo,false);
1698 case IDC_APPLY_MAXRELAYS:
1700 //
\83`
\83\83\83\93\83l
\83\8b\8cÅ
\97L
\82Ì
\8dÅ
\91å
\83\8a\83\8c\81[
\90\94\82ð
\90Ý
\92è
1704 //
\93ü
\97Í
\92l
\8eæ
\93¾
1705 mr = ::GetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, &bSucc, false);
1709 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1710 if (ch && !isIndexTxt(ch))
1716 MessageBox(hDlg, "
\93ü
\97Í
\92l
\82ª
\95s
\90³
\82Å
\82·
\81B", "Error", MB_OK|MB_ICONERROR|MB_APPLMODAL);
1717 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1719 ::SetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, ch->maxRelays, false);
1727 if (winDistinctionNT)
1730 DestroyWindow(hDlg); //JP-Patch
1734 if (LOWORD(wParam) == WA_INACTIVE)
1735 if (winDistinctionNT)
1738 DestroyWindow(hDlg); //JP-Patch
1749 // control thread (Traffic dialog)
1750 THREAD_PROC trafficDlgUpdate(ThreadInfo *thread)
1752 thread->finish = false;
1754 while (trafficDlg && thread->active)
1756 SendMessage(trafficDlg, WM_UPDATETRAFFIC, 0, 0);
1760 thread->finish = true;
1765 // Dialog procedure (Traffic dialog)
1766 LRESULT CALLBACK TrafficDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1771 //
\8aù
\82É
\8aJ
\82¢
\82Ä
\82é
1772 if (trafficDlg || trafficDlgThread.active)
1774 if (winDistinctionNT)
1777 DestroyWindow(hDlg);
1782 trafficDlgThread.func = trafficDlgUpdate;
1783 if (!sys->startThread(&trafficDlgThread)){
1784 MessageBox(NULL,"Unable to start GUI","PeerCast",MB_OK|MB_ICONERROR);
1785 PostMessage(hDlg,WM_DESTROY,0,0);
1790 case WM_UPDATETRAFFIC:
1792 enum unitSymbol { B, KB, MB, GB };
1793 const unsigned long int unit[] = { 1, 1024, 1024*1024, 1024*1024*1024 };
1794 char suffix[][3] = { "B", "KB", "MB", "GB" };
1795 const int bufsize = 60;
1796 char szUp[bufsize], szDown[bufsize];
1797 unsigned long long int totalDown = stats.getCurrent(Stats::BYTESIN) - stats.getCurrent(Stats::LOCALBYTESIN);
1798 unsigned long long int totalUp = stats.getCurrent(Stats::BYTESOUT) - stats.getCurrent(Stats::LOCALBYTESOUT);
1801 for (int i=GB; i>0; --i)
1803 if (totalUp >= unit[i])
1805 sprintf_s<bufsize>(szUp, "%.2f%s", (double)totalUp/unit[i], suffix[i]);
1810 sprintf_s<bufsize>(szUp, "%d%s", totalUp, suffix[0]);
1814 for (int i=GB; i>0; --i)
1816 if (totalDown >= unit[i])
1818 sprintf_s<bufsize>(szDown, "%.2f%s", (double)totalDown/unit[i], suffix[i]);
1823 sprintf_s<bufsize>(szDown, "%d%s", totalDown, suffix[0]);
1826 SetDlgItemText(hDlg, IDC_STATIC_UP, szUp);
1827 SetDlgItemText(hDlg, IDC_STATIC_DOWN, szDown);
1833 trafficDlgThread.active = false;
1834 if (winDistinctionNT)
1837 DestroyWindow(hDlg);