📄 simple.cpp
字号:
char str[128],name[64]; strncpy(name,c->info.name,32); name[32]=0; if (strlen(c->info.name) > 32) strcat(name,"..."); sprintf(str,"%s (%d kb/s %s)",name,c->info.bitrate,ChanInfo::getTypeStr(c->info.contentType)); //InsertMenu(cm,0,MF_BYPOSITION,RELAY_CMD+i,str); } }}typedef int (*COMPARE_FUNC)(const void *,const void *);static int compareHitLists(ChanHitList **c2, ChanHitList **c1){ return stricmp(c1[0]->info.name.cstr(),c2[0]->info.name.cstr());}// // addAllChannelsMenu(HMENU m)// //void addAllChannelsMenu(HMENU cm){ int cnt = GetMenuItemCount(cm); for(int i=0; i<cnt-3; i++) DeleteMenu(cm,0,MF_BYPOSITION); int numActive=0; // sort channels into alphabetical order ChanHitList *lists[ChanMgr::MAX_HITLISTS]; int numLists=0; for(i=0; i<ChanMgr::MAX_HITLISTS; i++) if (chanMgr->hitlists[i].isUsed()) lists[numLists++]=&chanMgr->hitlists[i]; qsort(lists,numLists,sizeof(ChanHitList*),(COMPARE_FUNC)compareHitLists); // add channels to menu for(i=0; i<numLists; i++) { ChanHitList *chl = lists[i]; { char str[128],name[64]; strncpy(name,chl->info.name,32); name[32]=0; if (strlen(chl->info.name) > 32) strcat(name,"..."); sprintf(str,"%s (%d kb/s %s)",name,chl->info.bitrate,ChanInfo::getTypeStr(chl->info.contentType)); HMENU opMenu = CreatePopupMenu(); InsertMenu(opMenu,0,MF_BYPOSITION,INFO_CMD+chl->index,"Info"); if (chl->info.url.isValidURL()) InsertMenu(opMenu,0,MF_BYPOSITION,URL_CMD+chl->index,"URL"); InsertMenu(opMenu,0,MF_BYPOSITION,PLAY_CMD+chl->index,"Play"); UINT fl = MF_BYPOSITION|MF_POPUP; Channel *ch = chanMgr->findChannelByID(chl->info.id); if (ch) fl |= (ch->isPlaying()?MF_CHECKED:0); if (!chl->isAvailable()) fl |= MF_GRAYED; InsertMenu(cm,0,fl,(UINT)opMenu,str); numActive++; } } if (!numActive) InsertMenu(cm,0,MF_BYPOSITION,0,"<No channels>");}// // flipNotifyPopup(id, flag)void flipNotifyPopup(int id, ServMgr::NOTIFY_TYPE nt){ int mask = peercastInst->getNotifyMask(); mask ^= nt; if (mask & nt) CheckMenuItem(trayMenu,id,MF_CHECKED|MF_BYCOMMAND); else CheckMenuItem(trayMenu,id,MF_UNCHECKED|MF_BYCOMMAND); peercastInst->setNotifyMask(mask); peercastInst->saveSettings();} //// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)//// PURPOSE: Processes messages for the main window.//// WM_COMMAND - process the application menu// WM_PAINT - Paint the main window// WM_DESTROY - post a quit message and return////LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ int wmId, wmEvent; POINT point; switch (message) { case WM_SHOWGUI: createGUI(hWnd); break; case WM_TRAYICON: switch((UINT)lParam) { case WM_LBUTTONDOWN: if (allowTrayMenu) SendMessage(hWnd,WM_SHOWMENU,2,0); SetForegroundWindow(hWnd); break; case WM_RBUTTONDOWN: if (allowTrayMenu) SendMessage(hWnd,WM_SHOWMENU,1,0); SetForegroundWindow(hWnd); break; } break; case WM_COPYDATA: { GnuID id; COPYDATASTRUCT *pc = (COPYDATASTRUCT *)lParam; if (pc->dwData == WM_PLAYCHANNEL) { id.fromStr((const char *)pc->lpData); chanMgr->playChannel(id,false); } //LOG("URL request: %s",pc->lpData); //sys->callLocalURL((const char *)pc->lpData,servMgr->serverHost.port); } break; case WM_GETPORTNUMBER: { int port; port=servMgr->serverHost.port; LOG("PORT request: %d",port); ReplyMessage(port); } break; case WM_SHOWMENU: { SetForegroundWindow(hWnd); bool skipMenu=false; allowTrayMenu = false; // check for notifications if (currNotify & ServMgr::NT_UPGRADE) { if (servMgr->downloadURL[0]) { if ((sys->getTime()-seenNewVersionTime) > (60*60)) // notify every hour { if (MessageBox(hWnd,"A newer version of PeerCast is available, press OK to upgrade.","PeerCast",MB_OKCANCEL|MB_APPLMODAL|MB_ICONEXCLAMATION) == IDOK) sys->getURL(servMgr->downloadURL); seenNewVersionTime=sys->getTime(); skipMenu=true; } } } if (!skipMenu) { GetCursorPos(&point); HMENU menu; switch (wParam) { case 1: menu = GetSubMenu(trayMenu,0); addAllChannelsMenu(GetSubMenu(menu,0)); addRelayedChannelsMenu(GetSubMenu(menu,1)); break; case 2: menu = GetSubMenu(ltrayMenu,0); addAllChannelsMenu(menu); break; } TrackPopupMenu(menu,TPM_RIGHTALIGN,point.x,point.y,0,hWnd,NULL); PostMessage(hWnd,WM_NULL,0,0); } allowTrayMenu = true; } break; case WM_CREATE: if (showGUI) createGUI(hWnd); break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); if ((wmId >= INFO_CMD) && (wmId < INFO_CMD+ChanMgr::MAX_HITLISTS)) { int c = wmId - INFO_CMD; chanInfo = chanMgr->hitlists[c].info; chanInfoIsRelayed = false; DialogBox(hInst, (LPCTSTR)IDD_CHANINFO, hWnd, (DLGPROC)ChanInfoProc); return 0; } if ((wmId >= URL_CMD) && (wmId < URL_CMD+ChanMgr::MAX_HITLISTS)) { int c = wmId - URL_CMD; if (chanMgr->hitlists[c].info.url.isValidURL()) sys->getURL(chanMgr->hitlists[c].info.url); return 0; } if ((wmId >= PLAY_CMD) && (wmId < PLAY_CMD+ChanMgr::MAX_HITLISTS)) { int c = wmId - PLAY_CMD; chanMgr->playChannel(chanMgr->hitlists[c].info.id,false); return 0; } if ((wmId >= RELAY_CMD) && (wmId < RELAY_CMD+ChanMgr::MAX_HITLISTS)) { int c = wmId - RELAY_CMD; chanMgr->playChannel(chanMgr->hitlists[c].info.id,true); return 0; } // Parse the menu selections: switch (wmId) { case ID_POPUP_SHOWMESSAGES_PEERCAST: flipNotifyPopup(ID_POPUP_SHOWMESSAGES_PEERCAST,ServMgr::NT_PEERCAST); break; case ID_POPUP_SHOWMESSAGES_BROADCASTERS: flipNotifyPopup(ID_POPUP_SHOWMESSAGES_BROADCASTERS,ServMgr::NT_BROADCASTERS); break; case ID_POPUP_SHOWMESSAGES_TRACKINFO: flipNotifyPopup(ID_POPUP_SHOWMESSAGES_TRACKINFO,ServMgr::NT_TRACKINFO); break; case ID_POPUP_ABOUT: case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case ID_POPUP_SHOWGUI: case IDM_SETTINGS_GUI: { createGUI(hWnd); break; } case ID_POPUP_YELLOWPAGES: sys->getURL("http://yp.peercast.org"); break; case ID_POPUP_ADVANCED_VIEWLOG: sys->callLocalURL("admin?page=viewlog",servMgr->serverHost.port); break; case ID_POPUP_ADVANCED_SAVESETTINGS: servMgr->saveSettings(iniFileName.cstr()); break; case ID_POPUP_ADVANCED_INFORMATION: sys->callLocalURL("admin?",servMgr->serverHost.port); break; case ID_FIND_CHANNELS: case ID_POPUP_ADVANCED_ALLCHANNELS: case ID_POPUP_ALLCHANNELS: sys->callLocalURL("admin?page=chans",servMgr->serverHost.port); break; case ID_POPUP_UPGRADE: sys->callLocalURL("admin?cmd=upgrade",servMgr->serverHost.port); break; case ID_POPUP_ADVANCED_RELAYEDCHANNELS: case ID_POPUP_FAVORITES_EDIT: sys->callLocalURL("admin?page=mychans",servMgr->serverHost.port); break; case ID_POPUP_ADVANCED_BROADCAST: sys->callLocalURL("admin?page=broadcast",servMgr->serverHost.port); break; case ID_POPUP_FAVORITES_PLAYALL: { Channel *clist[ChanMgr::MAX_CHANNELS]; ChanInfo info; int num = chanMgr->findChannels(info,clist,ChanMgr::MAX_CHANNELS); if (num) chanMgr->playChannels(clist,num); } break; case ID_POPUP_SETTINGS: sys->callLocalURL("admin?page=settings",servMgr->serverHost.port); break; case ID_POPUP_CONNECTIONS: sys->callLocalURL("admin?page=connections",servMgr->serverHost.port); break; case ID_POPUP_HELP: sys->getURL("http://www.peercast.org/help.php"); break; case ID_POPUP_EXIT_CONFIRM: case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0;}// Mesage handler for about box.LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){ switch (message) { case WM_INITDIALOG: SendDlgItemMessage(hDlg,IDC_ABOUTVER,WM_SETTEXT,0,(LONG)PCX_AGENT); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: case IDCANCEL: EndDialog(hDlg, LOWORD(wParam)); return TRUE; case IDC_BUTTON1: sys->getURL("http://www.peercast.org"); EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; case WM_DESTROY: break; } return FALSE;}// Mesage handler for chaninfo boxLRESULT CALLBACK ChanInfoProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){ switch (message) { case WM_INITDIALOG: { char str[1024]; strcpy(str,chanInfo.track.artist.cstr()); strcat(str," - "); strcat(str,chanInfo.track.title.cstr()); SendDlgItemMessage(hDlg,IDC_EDIT_NAME,WM_SETTEXT,0,(LONG)chanInfo.name.cstr()); SendDlgItemMessage(hDlg,IDC_EDIT_PLAYING,WM_SETTEXT,0,(LONG)str); SendDlgItemMessage(hDlg,IDC_EDIT_MESSAGE,WM_SETTEXT,0,(LONG)chanInfo.comment.cstr()); SendDlgItemMessage(hDlg,IDC_EDIT_DESC,WM_SETTEXT,0,(LONG)chanInfo.desc.cstr()); SendDlgItemMessage(hDlg,IDC_EDIT_GENRE,WM_SETTEXT,0,(LONG)chanInfo.genre.cstr()); sprintf(str,"%d kb/s %s",chanInfo.bitrate,ChanInfo::getTypeStr(chanInfo.contentType)); SendDlgItemMessage(hDlg,IDC_FORMAT,WM_SETTEXT,0,(LONG)str); ChanHitList *chl = chanMgr->findHitListByID(chanInfo.id); if (chl) { sprintf(str,"%d",chl->numListeners()); SendDlgItemMessage(hDlg,IDC_EDIT_LISTENERS,WM_SETTEXT,0,(LONG)str); unsigned int nh = chl->numHits(); sprintf(str,"%d/%d",nh-chl->numBusy(),nh); SendDlgItemMessage(hDlg,IDC_EDIT_HOSTS,WM_SETTEXT,0,(LONG)str); }else{ SendDlgItemMessage(hDlg,IDC_EDIT_LISTENERS,WM_SETTEXT,0,(LONG)"-"); SendDlgItemMessage(hDlg,IDC_EDIT_HOSTS,WM_SETTEXT,0,(LONG)"-"); } if (!chanInfo.url.isValidURL()) EnableWindow(GetDlgItem(hDlg,IDC_CONTACT),false); Channel *ch = chanMgr->findChannelByID(chanInfo.id); if (ch) { SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)ch->getStatusStr()); SendDlgItemMessage(hDlg, IDC_KEEP,BM_SETCHECK, ch->stayConnected, 0); }else { SendDlgItemMessage(hDlg,IDC_EDIT_STATUS,WM_SETTEXT,0,(LONG)"OK"); EnableWindow(GetDlgItem(hDlg,IDC_KEEP),false); } POINT point; RECT rect,drect; HWND hDsk = GetDesktopWindow(); GetWindowRect(hDsk,&drect); GetWindowRect(hDlg,&rect); GetCursorPos(&point); POINT pos,size; size.x = rect.right-rect.left; size.y = rect.bottom-rect.top; if (point.x-drect.left < size.x) pos.x = point.x; else pos.x = point.x-size.x; if (point.y-drect.top < size.y) pos.y = point.y; else pos.y = point.y-size.y; SetWindowPos(hDlg,HWND_TOPMOST,pos.x,pos.y,size.x,size.y,0); chWnd = hDlg; } return TRUE; case WM_COMMAND: { char str[1024],idstr[64]; chanInfo.id.toStr(idstr); switch (LOWORD(wParam)) { case IDC_CONTACT: { sys->getURL(chanInfo.url); return TRUE; } case IDC_DETAILS: { sprintf(str,"admin?page=chaninfo&id=%s&relay=%d",idstr,chanInfoIsRelayed); sys->callLocalURL(str,servMgr->serverHost.port); return TRUE; } case IDC_KEEP: { Channel *ch = chanMgr->findChannelByID(chanInfo.id); if (ch) ch->stayConnected = SendDlgItemMessage(hDlg, IDC_KEEP,BM_GETCHECK, 0, 0) == BST_CHECKED;; return TRUE; } case IDC_PLAY: { chanMgr->playChannel(chanInfo.id,false); return TRUE; } //case IDC_CLOSE: //{ // EndDialog(hDlg, 0); // return TRUE; //} } } break; case WM_CLOSE: EndDialog(hDlg, 0); break; case WM_ACTIVATE: if (LOWORD(wParam) == WA_INACTIVE) EndDialog(hDlg, 0); break; case WM_DESTROY: chWnd = NULL; break; } return FALSE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -