ttrayicon.cpp.svn-base
来自「ffshow源码」· SVN-BASE 代码 · 共 553 行 · 第 1/2 页
SVN-BASE
553 行
/* * Copyright (c) 2002-2006 Milan Cutka * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "stdafx.h"#include <shellapi.h>#include <shlwapi.h>#include "TtrayIcon.h"#include "resource.h"#include "IffdshowBase.h"#include "IffdshowDec.h"#include "IffdshowDecVideo.h"#include "TsubtitlesFile.h"#include "TfilterSettings.h"#include "IffdshowEnc.h"#include "IffdshowDecAudio.h"#include "Tconfig.h"#include "Ttranslate.h"#include "TSpecifyPropertyPagesVE.h"#include "dsutil.h"//==================================== TtrayIconBase =====================================unsigned int TtrayIconBase::run(CAMEvent *ev,HWND *hwndRef){ init(); if (h) { *hwndRef=h; ev->Set(); MSG msg; while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } hide(); } else ev->Set(); delete this; _endthreadex(0); return 0; }TtrayIconBase::TtrayIconBase(IffdshowBase *Ideci):deci(Ideci){ randomize(); deci->getInstance(&hi); deci->getConfig(&config); mode=deci->getParam2(IDFF_filterMode); at=(ATOM)NULL;h=NULL; visible=false; strcpy(classname,_l("ffdshow unknown")); tr=NULL;}TtrayIconBase::~TtrayIconBase(){ if (visible) Shell_NotifyIcon(NIM_DELETE,(::NOTIFYICONDATA*)&nid); if (h) DestroyWindow(h); if (at) UnregisterClass(classname,hi); if (tr) tr->release();}HMENU TtrayIconBase::createMenu(int &ord){ if (!tr) deci->getTranslator(&tr); return CreatePopupMenu();}void TtrayIconBase::insertSeparator(HMENU hm,int &ord){ MENUITEMINFO mii; mii.cbSize=sizeof(mii); mii.fMask=MIIM_TYPE; mii.fType=MFT_SEPARATOR; InsertMenuItem(hm,ord++,TRUE,&mii);}void TtrayIconBase::insertSubmenu(HMENU hm,int &ord,const char_t *caption,bool translate,HMENU subMenu){ MENUITEMINFO mii; mii.cbSize=sizeof(mii); mii.fMask=MIIM_TYPE|MIIM_SUBMENU; mii.fType=MFT_STRING; mii.hSubMenu=subMenu; mii.dwTypeData=LPTSTR(translate?tr->translate(caption):caption); mii.cch=(UINT)strlen(mii.dwTypeData); InsertMenuItem(hm,ord++,TRUE,&mii);}int TtrayIconBase::insertMenuItem(HMENU hm,int &ord,int id,const char_t *caption,bool translate,bool checked,bool enabled){ MENUITEMINFO mii; mii.cbSize=sizeof(mii); mii.fMask=MIIM_ID|MIIM_STATE|MIIM_TYPE; mii.fType=MFT_STRING; mii.wID=id; mii.fState=(checked?MFS_CHECKED:0)|(!enabled?MFS_DISABLED:0); mii.dwTypeData=LPTSTR(translate?tr->translate(caption):caption); mii.cch=(UINT)strlen(mii.dwTypeData); InsertMenuItem(hm,ord++,TRUE,&mii); return mii.wID;}LRESULT CALLBACK TtrayIconBase::trayWndProc(HWND hwnd, UINT msg, WPARAM wprm, LPARAM lprm){ TtrayIconBase *ti=(TtrayIconBase*)GetWindowLongPtr(hwnd,GWLP_USERDATA); switch (msg) { case WM_CREATE: SetTimer(hwnd,TMR_TRAYICON,500,NULL); break; case WM_DESTROY: KillTimer(hwnd,TMR_TRAYICON); if (ti) ti->h=NULL; PostQuitMessage(0); break; case WM_TIMER: if (ti->deci->getParam2(IDFF_trayIcon)) ti->show(); else ti->hide(); return 0; case MSG_TRAYICON: if (!ti) return 0; else { if (!ti->tr) ti->deci->getTranslator(&ti->tr); return ti->processTrayMsg(hwnd,wprm,lprm); } } return DefWindowProc(hwnd,msg,wprm,lprm);}LRESULT TtrayIconBase::processTrayMsg(HWND hwnd,WPARAM wprm,LPARAM lprm){ switch (lprm) { case WM_MOUSEMOVE: if (deci->getParam2(IDFF_trayIconExt)) { char_t in[64];if (FAILED(deci->getInCodecString(in,64))) in[0]='\0'; char_t out[64];if (FAILED(deci->getOutCodecString(out,64))) out[0]='\0'; char_t *tipptr;int tiplen;char_t inputS[40],outputS[40]; const char_t *sep1,*sep2; if (nid.cbSize==sizeof(nid)) { tipptr=nid.szTip; tiplen=128; tsnprintf(inputS,40,_l("%s: "),tr->translate(_l("Input"))); tsnprintf(outputS,40,_l("%s: "),tr->translate(_l("Output"))); sep1=sep2=_l("\n"); } else { tipptr=nid.szTip; tiplen=64; inputS[0]=outputS[0]='\0';sep1=_l("");sep2=_l("->"); in[26]='\0';out[26]='\0'; } if (in[0] && out[0]) tsnprintf(tipptr,tiplen,_l("%s: %s%s%s%s%s%s"),tip,sep1,inputS,in,sep2,outputS,out); else if (in[0]) tsnprintf(tipptr,tiplen,_l("%s: %s"),tip,in); else tsnprintf(tipptr,tiplen,_l("%s"),tip); nid.szTip[tiplen-1]='\0'; Shell_NotifyIcon(NIM_MODIFY,(NOTIFYICONDATA*)&nid); } break; case WM_LBUTTONDBLCLK: deci->showCfgDlg(NULL); break; case WM_RBUTTONUP: case WM_CONTEXTMENU: { if (deci->getCfgDlgHwnd()) break; POINT p; GetCursorPos(&p); SetForegroundWindow(hwnd); int ord=0; HMENU hm=createMenu(ord); int cmd=TrackPopupMenu(hm,TPM_RIGHTALIGN|TPM_BOTTOMALIGN|TPM_RETURNCMD,p.x,p.y,0,hwnd,NULL); PostMessage(hwnd,WM_NULL,0,0); processCmd(hm,cmd); DestroyMenu(hm); return TRUE; } } return 0;}void TtrayIconBase::processCmd(HMENU hm,int cmd){}int TtrayIconBase::cfgGet(int i){ return deci->getParam2(i);}int TtrayIconBase::cfgSet(int i,int val){ deci->putParam(i,val); return val;}void TtrayIconBase::init(void){ h=createInvisibleWindow(hi,classname,classname,trayWndProc,0,&at); SetWindowLongPtr(h,GWLP_USERDATA,LONG_PTR(this)); memset(&nid,0,sizeof(nid)); nid.cbSize=config->getShellVersion()<(5<<24)?88:sizeof(nid); nid.hWnd=h; nid.uID=TRAYICON; nid.uFlags=NIF_ICON|NIF_TIP|NIF_MESSAGE;//|(nid.cbSize==sizeof(nid)?NIF_INFO:0); nid.hIcon=LoadIcon(hi,MAKEINTRESOURCE(icon)); nid.uCallbackMessage=MSG_TRAYICON; strcpy(nid.szTip,tip);}void TtrayIconBase::show(void){ if (!visible) { if (!h) init(); Shell_NotifyIcon(NIM_ADD,(::NOTIFYICONDATA*)&nid); visible=true; }}void TtrayIconBase::hide(void){ if (visible) { Shell_NotifyIcon(NIM_DELETE,(::NOTIFYICONDATA*)&nid); visible=false; }}//==================================== TtrayIconDec ========================================TtrayIconDec::TtrayIconDec(IffdshowBase *Ideci):TtrayIconBase(Ideci),deciD(Ideci){}void TtrayIconDec::insertMenuItemFilter(HMENU hm,int &ord,const TfilterIDFF *f){ insertMenuItem(hm,ord,IDC_FIRST_FILTER+f->is,stringreplace(ffstring(tr->translate(NULL,f->dlgId,0,f->name)),_l("&"),_l("&&"),rfReplaceAll).c_str(),false,!!cfgGet(f->is),true);}HMENU TtrayIconDec::createMenu(int &ord){ HMENU hm=TtrayIconBase::createMenu(ord); IFilterGraph *m_pGraph;deciD->getGraph(&m_pGraph); if (m_pGraph) { int i=0; comptr<IEnumFilters> eff; if (m_pGraph->EnumFilters(&eff)==S_OK) { eff->Reset(); for (comptr<IBaseFilter> bff;eff->Next(1,&bff,NULL)==S_OK;bff=NULL) { char_t name[MAX_PATH],filtername[MAX_PATH]; getFilterName(bff,name,filtername); char_t compactname[41]; PathCompactPathEx(compactname,name,40,0); graphnames[insertMenuItem(hm,ord,IDC_FIRST_GRAPH+(i++),compactname,false,false,!!comptrQ<ISpecifyPropertyPages>(bff))]=filtername;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?