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"
36 #include "chkMemoryLeak.h"
37 #define DEBUG_NEW new(__FILE__, __LINE__)
41 #define MAX_LOADSTRING 100
44 #define RELAY_CMD 8000
48 #define MAX_CHANNELS 999
53 void loadIcons(HINSTANCE hInstance, HWND hWnd);
56 UINT g_iTaskbarCreated = ~0; // for PCRaw (tray icon)
60 static int currNotify=0;
64 static HMENU trayMenu = NULL,ltrayMenu = NULL; // for PCRaw (tray icon)
66 bool allowMulti=false;
68 bool allowTrayMenu=true;
69 static bool winDistinctionNT=false;
70 int seenNewVersionTime=0;
73 bool chanInfoIsRelayed;
76 ULONG_PTR gdiplusToken;
78 //
\83v
\83\8d\83g
\83^
\83C
\83v
\90é
\8c¾
81 // ---------------------------------
82 Sys * APICALL MyPeercastInst::createSys()
84 return new WSys(mainWnd);
86 // ---------------------------------
87 const char * APICALL MyPeercastApp ::getIniFilename()
89 return iniFileName.cstr();
92 // ---------------------------------
93 const char *APICALL MyPeercastApp ::getClientTypeOS()
98 // ---------------------------------
99 const char * APICALL MyPeercastApp::getPath()
101 return exePath.cstr();
104 // --------------------------------- JP-EX
105 void APICALL MyPeercastApp ::openLogFile()
107 logFile.openWriteReplace("log.txt");
109 // --------------------------------- JP-EX
110 void APICALL MyPeercastApp ::getDirectory()
112 char path_buffer[256],drive[32],dir[128];
113 GetModuleFileName(NULL,path_buffer,255);
114 _splitpath(path_buffer,drive,dir,NULL,NULL);
115 sprintf(servMgr->modulePath,"%s%s",drive,dir);
117 // --------------------------------- JP-EX
118 bool APICALL MyPeercastApp ::clearTemp()
120 if (servMgr->clearPLS)
127 class NOTIFYICONDATA2
130 DWORD cbSize; // DWORD
134 UINT uCallbackMessage; // UINT
135 HICON hIcon; // HICON
136 char szTip[128]; // char[128]
137 DWORD dwState; // DWORD
138 DWORD dwStateMask; // DWORD
139 char szInfo[256]; // char[256]
140 UINT uTimeoutOrVersion; // UINT
141 char szInfoTitle[64]; // char[64]
142 DWORD dwInfoFlags; // DWORD
143 //GUID guidItem; > IE 6
146 NOTIFYICONDATA2 trayIcon;
150 HINSTANCE hInst; // current instance
151 TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
152 TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
153 TCHAR szWindowClass2[MAX_LOADSTRING]; // The title bar text
155 // Foward declarations of functions included in this code module:
156 ATOM MyRegisterClass(HINSTANCE hInstance);
157 ATOM MyRegisterClass2(HINSTANCE hInstance);
158 ATOM MyRegisterClass3(HINSTANCE hInstance);
159 BOOL InitInstance(HINSTANCE, int);
160 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
161 LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
162 LRESULT CALLBACK ChanInfoProc(HWND, UINT, WPARAM, LPARAM);
164 void setTrayIcon(int type, const char *,const char *,bool);
165 void flipNotifyPopup(int id, ServMgr::NOTIFY_TYPE nt);
170 // --------------------------------------------------
171 void LOG2(const char *fmt,...)
176 vsprintf(str,fmt,ap);
177 OutputDebugString(str);
183 // ---------------------------------------
184 int APIENTRY WinMain(HINSTANCE hInstance,
185 HINSTANCE hPrevInstance,
191 ::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
200 iniFileName.set(".\\peercast.ini");
202 WIN32_FIND_DATA fd; //JP-EX
203 HANDLE hFind; //JP-EX
205 OSVERSIONINFO osInfo; //JP-EX
206 osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //JP-EX
207 GetVersionEx(&osInfo);
208 if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
209 winDistinctionNT = true;
211 winDistinctionNT = false;
213 // off by default now
216 if (strlen(lpCmdLine) > 0)
219 if ((p = strstr(lpCmdLine,"-inifile"))!=NULL)
220 iniFileName.setFromString(p+8);
222 if (strstr(lpCmdLine,"-zen"))
225 if (strstr(lpCmdLine,"-multi"))
228 if (strstr(lpCmdLine,"-kill"))
231 if ((p = strstr(lpCmdLine,"-url"))!=NULL)
246 strncpy(tmpURL,p,sizeof(tmpURL)-1);
252 exePath = iniFileName;
253 char *s = exePath.cstr();
265 if (strnicmp(tmpURL,"peercast://",11)==0)
267 if (strnicmp(tmpURL+11,"pls/",4)==0)
268 chanURL = tmpURL+11+4;
278 // Initialize global strings
279 //LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
280 //LoadString(hInstance, IDC_APP_TITLE, szWindowClass, MAX_LOADSTRING);
282 strcpy(szTitle,"PeerCast");
283 strcpy(szWindowClass,"PeerCast");
284 strcpy(szWindowClass2,"Main");
288 HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass);
290 if (GetLastError() == ERROR_ALREADY_EXISTS)
292 HWND oldWin = FindWindow(szWindowClass,NULL);
295 SendMessage(oldWin,WM_SHOWGUI,0,0);
298 SendMessage(oldWin,WM_DESTROY,0,0);
305 copy.dwData = WM_PLAYCHANNEL;
306 copy.cbData = strlen(chanURL)+1; // plus null term
307 copy.lpData = chanURL;
308 SendMessage(oldWin,WM_COPYDATA,NULL,(LPARAM)©);
311 SendMessage(oldWin,WM_SHOWGUI,0,0);
321 MyRegisterClass(hInstance);
322 MyRegisterClass2(hInstance);
324 // Perform application initialization:
325 if (!InitInstance (hInstance, nCmdShow))
328 peercastInst = new MyPeercastInst();
329 peercastApp = new MyPeercastApp();
331 peercastInst->init();
333 LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x");
335 if (peercastApp->clearTemp()) //JP-EX
337 DeleteFile("play.pls");
338 hFind = FindFirstFile("*.asx",&fd);
339 if (hFind != INVALID_HANDLE_VALUE)
343 DeleteFile((char *)&fd.cFileName);
345 while (FindNextFile(hFind,&fd));
354 servMgr->procConnectArgs(chanURL,info);
355 chanMgr->findAndPlayChannel(info,false);
358 hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLE);
360 // setup menu notifes
361 int mask = peercastInst->getNotifyMask();
362 if (mask & ServMgr::NT_PEERCAST)
363 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_PEERCAST,MF_CHECKED|MF_BYCOMMAND);
364 if (mask & ServMgr::NT_BROADCASTERS)
365 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_BROADCASTERS,MF_CHECKED|MF_BYCOMMAND);
366 if (mask & ServMgr::NT_TRACKINFO)
367 CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_TRACKINFO,MF_CHECKED|MF_BYCOMMAND);
369 if (servMgr->startWithGui)
374 // Main message loop:
375 while (GetMessage(&msg, NULL, 0, 0))
377 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
379 TranslateMessage(&msg);
380 DispatchMessage(&msg);
384 Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon);
386 peercastInst->saveSettings();
387 peercastInst->quit();
389 Gdiplus::GdiplusShutdown(gdiplusToken);
397 // FUNCTION: MyRegisterClass()
399 // PURPOSE: Registers the window class.
403 // This function and its usage is only necessary if you want this code
404 // to be compatible with Win32 systems prior to the 'RegisterClassEx'
405 // function that was added to Windows 95. It is important to call this function
406 // so that the application will get 'well formed' small icons associated
409 ATOM MyRegisterClass(HINSTANCE hInstance)
413 wcex.cbSize = sizeof(WNDCLASSEX);
415 wcex.style = CS_HREDRAW | CS_VREDRAW;
416 wcex.lpfnWndProc = (WNDPROC)WndProc;
419 wcex.hInstance = hInstance;
420 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLE);
421 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
422 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
423 // wcex.lpszMenuName = (LPCSTR)IDC_SIMPLE;
424 wcex.lpszMenuName = NULL;
425 wcex.lpszClassName = szWindowClass;
426 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
428 return RegisterClassEx(&wcex);
431 ATOM MyRegisterClass2(HINSTANCE hInstance)
435 wcex.cbSize = sizeof(WNDCLASSEX);
437 wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ;
438 wcex.lpfnWndProc = (WNDPROC)GUIProc;
441 wcex.hInstance = hInstance;
442 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLE);
443 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
444 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
445 // wcex.lpszMenuName = (LPCSTR)IDC_SIMPLE;
446 wcex.lpszMenuName = NULL;
447 wcex.lpszClassName = szWindowClass2;
448 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
450 return RegisterClassEx(&wcex);
453 //-----------------------------
454 void loadIcons(HINSTANCE hInstance, HWND hWnd)
456 icon1 = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL);
457 icon2 = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL2);
459 trayIcon.cbSize = sizeof(trayIcon);
460 trayIcon.hWnd = hWnd;
462 trayIcon.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP;
463 trayIcon.uCallbackMessage = WM_TRAYICON;
464 trayIcon.hIcon = icon1;
465 strcpy(trayIcon.szTip, "PeerCast");
467 Shell_NotifyIcon(NIM_ADD, (NOTIFYICONDATA*)&trayIcon);
469 //ShowWindow(hWnd, nCmdShow);
472 if(!trayMenu) // for PCRaw (tray icon)
473 trayMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_TRAYMENU));
474 if(!ltrayMenu) // for PCRaw (tray icon)
475 ltrayMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_LTRAYMENU));
480 //-----------------------------
482 // FUNCTION: InitInstance(HANDLE, int)
484 // PURPOSE: Saves instance handle and creates main window
488 // In this function, we save the instance handle in a global variable and
489 // create and display the main program window.
491 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
495 hInst = hInstance; // Store instance handle in our global variable
497 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
498 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
507 g_iTaskbarCreated = RegisterWindowMessage("TaskbarCreated"); // for PCRaw (tray icon)
509 loadIcons(hInstance,hWnd);
511 using namespace Gdiplus;
512 GdiplusStartupInput gdiplusStartupInput;
513 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
517 //-----------------------------
518 //static String trackTitle;
519 //static String channelComment;
521 //-----------------------------
522 void channelPopup(const char *title, const char *msg, bool isPopup = true)
526 if (*title == '\0') return;
532 trayIcon.uFlags = NIF_ICON|NIF_TIP;
533 strncpy(trayIcon.szTip, both.cstr(),sizeof(trayIcon.szTip)-1);
534 trayIcon.szTip[sizeof(trayIcon.szTip)-1]=0;
536 if (isPopup) trayIcon.uFlags |= 16;
537 trayIcon.uTimeoutOrVersion = 10000;
538 strncpy(trayIcon.szInfo,msg,sizeof(trayIcon.szInfo)-1);
539 strncpy(trayIcon.szInfoTitle,title,sizeof(trayIcon.szInfoTitle)-1);
541 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
543 //-----------------------------
544 void clearChannelPopup()
546 trayIcon.uFlags = NIF_ICON|16;
547 trayIcon.uTimeoutOrVersion = 10000;
548 strncpy(trayIcon.szInfo,"",sizeof(trayIcon.szInfo)-1);
549 strncpy(trayIcon.szInfoTitle,"",sizeof(trayIcon.szInfoTitle)-1);
550 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
553 //-----------------------------
562 static PopupEntry *PEList = NULL;
565 static void putPopupEntry(PopupEntry *pe)
573 static PopupEntry *getPopupEntry(GnuID id)
576 PopupEntry *pe = PEList;
577 PopupEntry *prev = NULL;
579 if (id.isSame(pe->id)) {
580 if (prev) prev->next = pe->next;
581 else PEList = pe->next;
593 static PopupEntry *getTopPopupEntry()
595 PopupEntry *p = NULL;
599 PEList = PEList->next;
605 //-----------------------------
606 void APICALL MyPeercastApp::channelStart(ChanInfo *info)
609 // lastPlayID = info->id;
611 // if(!isIndexTxt(info)) // for PCRaw (popup)
612 // clearChannelPopup();
614 PopupEntry *pe = getPopupEntry(info->id);
619 if (!isIndexTxt(info))
624 //-----------------------------
625 void APICALL MyPeercastApp::channelStop(ChanInfo *info)
627 // if (info->id.isSame(lastPlayID))
629 // lastPlayID.clear();
631 // if(!isIndexTxt(info)) // for PCRaw (popup)
632 // clearChannelPopup();
635 PopupEntry *pe = getPopupEntry(info->id);
638 pe = getTopPopupEntry();
642 if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
644 String name,track; //JP-Patch
645 name = pe->name; //JP-Patch
646 track = pe->track; //JP-Patch
647 name.convertTo(String::T_SJIS); //JP-Patch
648 track.convertTo(String::T_SJIS); //JP-Patch
650 // channelPopup(info->name.cstr(),trackTitle.cstr());
651 channelPopup(name.cstr(),track.cstr(), false); //JP-Patch
656 //-----------------------------
657 void APICALL MyPeercastApp::channelUpdate(ChanInfo *info)
661 PopupEntry *pe = getPopupEntry(info->id);
665 tmp.append(info->track.artist);
667 tmp.append(info->track.title);
670 if (!tmp.isSame(pe->track))
672 pe->name = info->name;
674 if (ServMgr::NT_TRACKINFO & peercastInst->getNotifyMask())
677 String name,track; //JP-Patch
678 name = info->name; //JP-Patch
679 track = tmp; //JP-Patch
680 name.convertTo(String::T_SJIS); //JP-Patch
681 track.convertTo(String::T_SJIS); //JP-Patch
682 if(!isIndexTxt(info)) // for PCRaw (popup)
685 // channelPopup(info->name.cstr(),trackTitle.cstr());
686 channelPopup(name.cstr(),track.cstr()); //JP-Patch
689 } else if (!info->comment.isSame(pe->comment))
691 pe->name = info->name;
692 pe->comment = info->comment;
693 if (ServMgr::NT_BROADCASTERS & peercastInst->getNotifyMask())
695 //channelComment = info->comment;
696 String name,comment; //JP-Patch
697 name = info->name; //JP-Patch
698 comment = info->comment; //JP-Patch
699 name.convertTo(String::T_SJIS); //JP-Patch
700 comment.convertTo(String::T_SJIS); //JP-Patch
701 if(!isIndexTxt(info)) // for PCRaw (popup)
704 // channelPopup(info->name.cstr(),channelComment.cstr());
705 channelPopup(name.cstr(),comment.cstr());
710 if (!isIndexTxt(info))
716 //-----------------------------
717 void APICALL MyPeercastApp::notifyMessage(ServMgr::NOTIFY_TYPE type, const char *msg)
719 static bool shownUpgradeAlert=false;
725 if (!shownUpgradeAlert)
727 trayIcon.uFlags = NIF_ICON;
729 if (type == ServMgr::NT_UPGRADE)
731 shownUpgradeAlert = true;
732 trayIcon.hIcon = icon2;
735 trayIcon.hIcon = icon1;
739 if (type == ServMgr::NT_UPGRADE)
743 const char *title="";
747 case ServMgr::NT_UPGRADE:
748 title = "Upgrade alert";
750 case ServMgr::NT_PEERCAST:
751 title = "Message from PeerCast:";
756 if (type & peercastInst->getNotifyMask())
758 trayIcon.uFlags |= 16;
759 trayIcon.uTimeoutOrVersion = 10000;
760 strncpy(trayIcon.szInfo,msg,sizeof(trayIcon.szInfo)-1);
761 strncpy(trayIcon.szInfoTitle,title,sizeof(trayIcon.szInfoTitle)-1);
762 Shell_NotifyIcon(NIM_MODIFY, (NOTIFYICONDATA*)&trayIcon);
765 //-----------------------------
769 void createGUI(HWND hWnd)
772 guiWnd = ::CreateWindow(szWindowClass2,
774 WS_OVERLAPPEDWINDOW & ~(WS_MAXIMIZEBOX) /*| WS_VSCROLL | WS_HSCROLL*/,
784 ShowWindow(guiWnd,SW_SHOWNORMAL);
786 //
\8e©
\93®
\82Å
\8dÅ
\91O
\96Ê
787 if (servMgr->topmostGui)
789 ::SetWindowPos(guiWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
795 // addRelayedChannelsMenu(HMENU m)
798 void addRelayedChannelsMenu(HMENU cm)
800 int cnt = GetMenuItemCount(cm);
801 for(int i=0; i<cnt-3; i++)
802 DeleteMenu(cm,0,MF_BYPOSITION);
804 Channel *c = chanMgr->channel;
809 char str[128],name[64];
810 strncpy(name,c->info.name,32);
812 if (strlen(c->info.name) > 32)
816 sprintf(str,"%s (%d kb/s %s)",name,c->info.bitrate,ChanInfo::getTypeStr(c->info.contentType));
817 //InsertMenu(cm,0,MF_BYPOSITION,RELAY_CMD+i,str);
823 typedef int (*COMPARE_FUNC)(const void *,const void *);
825 static int compareHitLists(ChanHitList **c2, ChanHitList **c1)
827 return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());
830 static int compareChannels(Channel **c2, Channel **c1)
832 return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());
836 // addAllChannelsMenu(HMENU m)
839 void addAllChannelsMenu(HMENU cm)
841 int cnt = GetMenuItemCount(cm);
842 /* for(int i=0; i<cnt-2; i++)
843 DeleteMenu(cm,0,MF_BYPOSITION);*/
845 for(int i=0; i<cnt; i++)
846 DeleteMenu(cm,0,MF_BYPOSITION);
848 HMENU yMenu = CreatePopupMenu();
849 if (!servMgr->rootHost2.isEmpty()){
850 InsertMenu(yMenu,0,MF_BYPOSITION,ID_POPUP_YELLOWPAGES2,servMgr->rootHost2);
852 if (!servMgr->rootHost.isEmpty()){
853 InsertMenu(yMenu,0,MF_BYPOSITION,ID_POPUP_YELLOWPAGES1,servMgr->rootHost);
856 InsertMenu(cm,0,MF_BYPOSITION|MF_POPUP,(UINT)yMenu,"
\83C
\83G
\83\8d\81[
\83y
\81[
\83W");
857 InsertMenu(cm,0,MF_BYPOSITION|MF_SEPARATOR,NULL,NULL);
858 // add channels to menu
860 Channel *ch = chanMgr->channel;
863 char str[128],name[64];
864 String sjis; //JP-Patch
865 sjis = ch->info.name; //JP-Patch
866 sjis.convertTo(String::T_SJIS); //JP-Patch
867 strncpy(name,sjis.cstr(),32);
868 //strncpy(name,ch->info.name,32);
870 //if (strlen(ch->info.name) > 32)
871 if (strlen(sjis.cstr()) > 32) //JP-Patch
874 sprintf(str,"%s (%d kb/s %s)",name,ch->info.bitrate,ChanInfo::getTypeStr(ch->info.contentType));
876 HMENU opMenu = CreatePopupMenu();
877 InsertMenu(opMenu,0,MF_BYPOSITION,INFO_CMD+numActive,"Info");
878 if (ch->info.url.isValidURL())
879 InsertMenu(opMenu,0,MF_BYPOSITION,URL_CMD+numActive,"URL");
880 InsertMenu(opMenu,0,MF_BYPOSITION,PLAY_CMD+numActive,"Play");
882 UINT fl = MF_BYPOSITION|MF_POPUP;
884 fl |= (ch->isPlaying()?MF_CHECKED:0);
886 InsertMenu(cm,0,fl,(UINT)opMenu,str);
895 // InsertMenu(cm,0,MF_BYPOSITION,0,"<No channels>");
904 // flipNotifyPopup(id, flag)
905 void flipNotifyPopup(int id, ServMgr::NOTIFY_TYPE nt)
907 int mask = peercastInst->getNotifyMask();
911 CheckMenuItem(trayMenu,id,MF_CHECKED|MF_BYCOMMAND);
913 CheckMenuItem(trayMenu,id,MF_UNCHECKED|MF_BYCOMMAND);
915 peercastInst->setNotifyMask(mask);
916 peercastInst->saveSettings();
920 static void showHTML(const char *file)
923 sprintf(url,"%s/%s",servMgr->htmlPath,file);
925 // sys->callLocalURL(url,servMgr->serverHost.port);
926 sys->callLocalURL(url, // for PCRaw (url)
927 (servMgr->allowServer1&Servent::ALLOW_HTML)?(servMgr->serverHost.port):(servMgr->serverHost.port+1));
930 static ChanInfo getChannelInfo(int index)
932 Channel *c = chanMgr->findChannelByIndex(index);
941 // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
943 // PURPOSE: Processes messages for the main window.
945 // WM_COMMAND - process the application menu
946 // WM_PAINT - Paint the main window
947 // WM_DESTROY - post a quit message and return
950 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
956 if(message == g_iTaskbarCreated) // for PCRaw (tray icon)
957 loadIcons(hInst, hWnd);
971 SendMessage(hWnd,WM_SHOWMENU,2,0);
972 SetForegroundWindow(hWnd);
976 SendMessage(hWnd,WM_SHOWMENU,1,0);
977 SetForegroundWindow(hWnd);
979 case WM_LBUTTONDBLCLK:
987 COPYDATASTRUCT *pc = (COPYDATASTRUCT *)lParam;
988 LOG_DEBUG("URL request: %s",pc->lpData);
989 if (pc->dwData == WM_PLAYCHANNEL)
992 servMgr->procConnectArgs((char *)pc->lpData,info);
993 chanMgr->findAndPlayChannel(info,false);
995 //sys->callLocalURL((const char *)pc->lpData,servMgr->serverHost.port);
998 case WM_GETPORTNUMBER:
1001 port=servMgr->serverHost.port;
1008 if (servMgr->saveGuiPos){
1009 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_CHECKED|MF_BYCOMMAND);
1011 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_UNCHECKED|MF_BYCOMMAND);
1014 //
\8e©
\93®GUI/
\8dÅ
\91O
\96Ê
\8b@
\94\
1015 if (servMgr->topmostGui)
1017 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_CHECKED|MF_BYCOMMAND);
1020 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_UNCHECKED|MF_BYCOMMAND);
1023 if (servMgr->startWithGui)
1025 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_CHECKED|MF_BYCOMMAND);
1028 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_UNCHECKED|MF_BYCOMMAND);
1031 SetForegroundWindow(hWnd);
1032 bool skipMenu=false;
1034 allowTrayMenu = false;
1036 // check for notifications
1037 if (currNotify & ServMgr::NT_UPGRADE)
1039 if (servMgr->downloadURL[0])
1041 if ((sys->getTime()-seenNewVersionTime) > (60*60)) // notify every hour
1043 if (MessageBox(hWnd,"A newer version of PeerCast is available, press OK to upgrade.","PeerCast",MB_OKCANCEL|MB_APPLMODAL|MB_ICONEXCLAMATION) == IDOK)
1044 sys->getURL(servMgr->downloadURL);
1046 seenNewVersionTime=sys->getTime();
1059 SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWnd, 0);
1060 GetCursorPos(&point);
1062 if (point.x < rcWnd.left){
1063 point.x = rcWnd.left;
1064 flg |= TPM_LEFTALIGN;
1066 if (point.x > rcWnd.right){
1067 point.x = rcWnd.right;
1068 flg |= TPM_RIGHTALIGN;
1070 if (point.y < rcWnd.top){
1071 point.y = rcWnd.top;
1072 flg |= TPM_TOPALIGN;
1074 if (point.y > rcWnd.bottom){
1075 point.y = rcWnd.bottom;
1076 flg |= TPM_BOTTOMALIGN;
1079 flg = TPM_RIGHTALIGN;
1085 menu = GetSubMenu(trayMenu,0);
1086 addAllChannelsMenu(GetSubMenu(menu,0));
1087 addRelayedChannelsMenu(GetSubMenu(menu,1));
1090 menu = GetSubMenu(ltrayMenu,0);
1091 addAllChannelsMenu(menu);
1094 if (!TrackPopupMenu(menu,flg,point.x,point.y,0,hWnd,NULL))
1096 LOG_ERROR("Can`t track popup menu: %d",GetLastError());
1098 PostMessage(hWnd,WM_NULL,0,0);
1101 allowTrayMenu = true;
1111 wmId = LOWORD(wParam);
1112 wmEvent = HIWORD(wParam);
1114 if ((wmId >= INFO_CMD) && (wmId < INFO_CMD+MAX_CHANNELS))
1116 int c = wmId - INFO_CMD;
1117 chanInfo = getChannelInfo(c);
1118 chanInfoIsRelayed = false;
1119 if (winDistinctionNT)
1120 DialogBox(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc);
1123 HWND WKDLG; //JP-Patch
1124 WKDLG = CreateDialog(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc); //JP-Patch
1125 ShowWindow(WKDLG,SW_SHOWNORMAL); //JP-Patch
1129 if ((wmId >= URL_CMD) && (wmId < URL_CMD+MAX_CHANNELS))
1131 int c = wmId - URL_CMD;
1132 chanInfo = getChannelInfo(c);
1133 if (chanInfo.url.isValidURL())
1134 sys->getURL(chanInfo.url);
1137 if ((wmId >= PLAY_CMD) && (wmId < PLAY_CMD+MAX_CHANNELS))
1139 int c = wmId - PLAY_CMD;
1140 chanInfo = getChannelInfo(c);
1141 chanMgr->findAndPlayChannel(chanInfo,false);
1144 if ((wmId >= RELAY_CMD) && (wmId < RELAY_CMD+MAX_CHANNELS))
1146 int c = wmId - RELAY_CMD;
1147 chanInfo = getChannelInfo(c);
1148 chanMgr->findAndPlayChannel(chanInfo,true);
1152 // Parse the menu selections:
1155 case ID_POPUP_SHOWMESSAGES_PEERCAST:
1156 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_PEERCAST,ServMgr::NT_PEERCAST);
1158 case ID_POPUP_SHOWMESSAGES_BROADCASTERS:
1159 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_BROADCASTERS,ServMgr::NT_BROADCASTERS);
1161 case ID_POPUP_SHOWMESSAGES_TRACKINFO:
1162 flipNotifyPopup(ID_POPUP_SHOWMESSAGES_TRACKINFO,ServMgr::NT_TRACKINFO);
1165 case ID_POPUP_ABOUT:
1167 DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
1169 case ID_POPUP_SHOWGUI:
1170 case IDM_SETTINGS_GUI:
1171 case ID_POPUP_ADVANCED_SHOWGUI:
1176 case ID_POPUP_YELLOWPAGES:
1177 sys->getURL("http://yp.peercast.org/");
1179 case ID_POPUP_YELLOWPAGES1:
1180 sprintf(buf, "http://%s",servMgr->rootHost.cstr());
1183 case ID_POPUP_YELLOWPAGES2:
1184 sprintf(buf, "http://%s",servMgr->rootHost2.cstr());
1188 case ID_POPUP_ADVANCED_VIEWLOG:
1189 showHTML("viewlog.html");
1191 case ID_POPUP_ADVANCED_SAVESETTINGS:
1192 servMgr->saveSettings(iniFileName.cstr());
1194 case ID_POPUP_ADVANCED_INFORMATION:
1195 showHTML("index.html");
1197 case ID_FIND_CHANNELS:
1198 case ID_POPUP_ADVANCED_ALLCHANNELS:
1199 case ID_POPUP_UPGRADE:
1200 sys->callLocalURL("admin?cmd=upgrade",servMgr->serverHost.port);
1202 case ID_POPUP_ADVANCED_RELAYEDCHANNELS:
1203 case ID_POPUP_FAVORITES_EDIT:
1204 showHTML("relays.html");
1206 case ID_POPUP_ADVANCED_BROADCAST:
1207 showHTML("broadcast.html");
1209 case ID_POPUP_SETTINGS:
1210 showHTML("settings.html");
1212 case ID_POPUP_CONNECTIONS:
1213 showHTML("connections.html");
1216 sys->getURL("http://www.peercast.org/help.php");
1219 case ID_POPUP_SAVE_GUI_POS:
1220 if (servMgr->saveGuiPos){
1221 servMgr->saveGuiPos = false;
1222 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_UNCHECKED|MF_BYCOMMAND);
1224 servMgr->saveGuiPos = true;
1225 CheckMenuItem(trayMenu, ID_POPUP_SAVE_GUI_POS, MF_CHECKED|MF_BYCOMMAND);
1227 peercastInst->saveSettings();
1230 case ID_POPUP_KEEP_DOWNSTREAMS:
1231 if (servMgr->keepDownstreams){
1232 servMgr->keepDownstreams = false;
1233 CheckMenuItem(trayMenu, ID_POPUP_KEEP_DOWNSTREAMS, MF_UNCHECKED|MF_BYCOMMAND);
1235 servMgr->keepDownstreams = true;
1236 CheckMenuItem(trayMenu, ID_POPUP_KEEP_DOWNSTREAMS, MF_CHECKED|MF_BYCOMMAND);
1238 //peercastInst->saveSettings();
1241 case ID_POPUP_TOPMOST:
1242 //
\8dÅ
\91O
\96Ê
\95\
\8e¦
1243 if (servMgr->topmostGui)
1245 servMgr->topmostGui = false;
1246 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_UNCHECKED|MF_BYCOMMAND);
1249 servMgr->topmostGui = true;
1250 CheckMenuItem(trayMenu, ID_POPUP_TOPMOST, MF_CHECKED|MF_BYCOMMAND);
1252 peercastInst->saveSettings();
1255 case ID_POPUP_START_WITH_GUI:
1256 //
\8bN
\93®
\8e\9e\82ÉGUI
\95\
\8e¦
1257 if (servMgr->startWithGui)
1259 servMgr->startWithGui = false;
1260 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_UNCHECKED|MF_BYCOMMAND);
1263 servMgr->startWithGui = true;
1264 CheckMenuItem(trayMenu, ID_POPUP_START_WITH_GUI, MF_CHECKED|MF_BYCOMMAND);
1266 peercastInst->saveSettings();
1269 case ID_POPUP_EXIT_CONFIRM:
1271 DestroyWindow(hWnd);
1274 return DefWindowProc(hWnd, message, wParam, lParam);
1281 return DefWindowProc(hWnd, message, wParam, lParam);
1285 // Mesage handler for about box.
1286 LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1291 //SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENT);
1292 // SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTJP);
1294 SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTEX);
1296 SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENTVP);
1301 switch (LOWORD(wParam))
1305 EndDialog(hDlg, LOWORD(wParam));
1308 sys->getURL("http://www.peercast.org");
1309 EndDialog(hDlg, LOWORD(wParam));
1320 // Mesage handler for chaninfo box
1321 LRESULT CALLBACK ChanInfoProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1328 //strcpy(str,chanInfo.track.artist.cstr());
1329 strcpy(str,chanInfo.track.artist); //JP-Patch
1331 //strcat(str,chanInfo.track.title.cstr());
1332 strcat(str,chanInfo.track.title);
1333 String name,track,comment,desc,genre; //JP-Patch
1334 name = chanInfo.name; //JP-Patch
1335 track = str; //JP-Patch
1336 comment = chanInfo.comment; //JP-Patch
1337 desc = chanInfo.desc; //JP-Patc
1338 genre = chanInfo.genre; //JP-Patch
1339 name.convertTo(String::T_SJIS); //JP-Patc
1340 track.convertTo(String::T_SJIS); //JP-Patch
1341 comment.convertTo(String::T_SJIS); //JP-Patch
1342 desc.convertTo(String::T_SJIS); //JP-Patch
1343 genre.convertTo(String::T_SJIS); //JP-Patch
1345 //SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)chanInfo.name.cstr());
1346 SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)name.cstr()); //JP-Patch
1347 //SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)str);
1348 SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)track.cstr()); //JP-Patch
1349 //SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)chanInfo.comment.cstr());
1350 SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)comment.cstr()); //JP-Patch
1351 //SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)chanInfo.desc.cstr());
1352 SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)desc.cstr()); //JP-Patch
1353 //SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)chanInfo.genre.cstr());
1354 SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)genre.cstr()); //JP-Patch
1356 sprintf(str,"%d kb/s %s",chanInfo.bitrate,ChanInfo::getTypeStr(chanInfo.contentType));
1357 SendDlgItemMessage(hDlg,IDC_FORMAT,WM_SETTEXT,0,(LONG)str);
1360 if (!chanInfo.url.isValidURL())
1361 EnableWindow(GetDlgItem(hDlg,IDC_CONTACT),false);
1363 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1366 SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)ch->getStatusStr());
1367 SendDlgItemMessage(hDlg, IDC_KEEP,BM_SETCHECK, ch->stayConnected, 0);
1369 //
\8c»
\8dÝ
\82Ì
\8cÅ
\97L
\83\8a\83\8c\81[
\8fã
\8cÀ
\90Ý
\92è
\82ð
\95\
\8e¦(0
\82Í
\96³
\8cø)
1370 ::SetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, ch->maxRelays, false);
1373 // index.txt
\82È
\82Ì
\82Å
\96³
\8cø
\82É
1374 ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_MAXRELAYS), false);
1375 ::EnableWindow(::GetDlgItem(hDlg, IDC_APPLY_MAXRELAYS), false);
1379 SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)"OK");
1380 EnableWindow(GetDlgItem(hDlg,IDC_KEEP),false);
1387 HWND hDsk = GetDesktopWindow();
1388 GetWindowRect(hDsk,&drect);
1389 GetWindowRect(hDlg,&rect);
1390 GetCursorPos(&point);
1393 size.x = rect.right-rect.left;
1394 size.y = rect.bottom-rect.top;
1396 if (point.x-drect.left < size.x)
1399 pos.x = point.x-size.x;
1401 if (point.y-drect.top < size.y)
1404 pos.y = point.y-size.y;
1406 SetWindowPos(hDlg,HWND_TOPMOST,pos.x,pos.y,size.x,size.y,0);
1413 char str[1024],idstr[64];
1414 chanInfo.id.toStr(idstr);
1416 switch (LOWORD(wParam))
1420 sys->getURL(chanInfo.url);
1425 sprintf(str,"admin?page=chaninfo&id=%s&relay=%d",idstr,chanInfoIsRelayed);
1426 sys->callLocalURL(str,servMgr->serverHost.port);
1431 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1433 ch->stayConnected = SendDlgItemMessage(hDlg, IDC_KEEP,BM_GETCHECK, 0, 0) == BST_CHECKED;;
1440 chanMgr->findAndPlayChannel(chanInfo,false);
1444 case IDC_APPLY_MAXRELAYS:
1446 //
\83`
\83\83\83\93\83l
\83\8b\8cÅ
\97L
\82Ì
\8dÅ
\91å
\83\8a\83\8c\81[
\90\94\82ð
\90Ý
\92è
1450 //
\93ü
\97Í
\92l
\8eæ
\93¾
1451 mr = ::GetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, &bSucc, false);
1455 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1456 if (ch && !isIndexTxt(ch))
1462 MessageBox(hDlg, "
\93ü
\97Í
\92l
\82ª
\95s
\90³
\82Å
\82·
\81B", "Error", MB_OK|MB_ICONERROR|MB_APPLMODAL);
1463 Channel *ch = chanMgr->findChannelByID(chanInfo.id);
1465 ::SetDlgItemInt(hDlg, IDC_EDIT_MAXRELAYS, ch->maxRelays, false);
1473 if (winDistinctionNT)
1476 DestroyWindow(hDlg); //JP-Patch
1480 if (LOWORD(wParam) == WA_INACTIVE)
1481 if (winDistinctionNT)
1484 DestroyWindow(hDlg); //JP-Patch