From 0a9bb7686ad80fb95467c6c08e159467f4e4b2fd Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 17 Dec 2006 13:17:13 +0000 Subject: [PATCH] Windows updates --- dssourcepin.cc | 36 ++++++++++++++----- remotewin.cc | 20 +++++++++++ vompreswin.h | 14 ++++++++ vompwin.rc | 51 ++++++++++++++++++++++++++- winmain.cc | 93 ++++++++++++++++++++++++++++++++++++++++++++++---- 5 files changed, 198 insertions(+), 16 deletions(-) diff --git a/dssourcepin.cc b/dssourcepin.cc index f6893c7..5d440a7 100644 --- a/dssourcepin.cc +++ b/dssourcepin.cc @@ -60,8 +60,11 @@ HRESULT STDMETHODCALLTYPE DsSFEnumMediaTypes::Next(ULONG numpin, AM_MEDIA_TYPE * for (i=0;(iGetMediaType(curpos+i,pins[i])!=S_OK) return S_FALSE; - curpos++; + if (parent->GetMediaType(curpos+i,pins[i])!=S_OK) { + CoTaskMemFree(pins[i]); + pins[i]=NULL; + return S_FALSE; + } curpos++; if (fetched!=NULL) (*fetched)++; } return S_OK; @@ -194,14 +197,14 @@ HRESULT STDMETHODCALLTYPE DsSourcePin::Connect(IPin *pinempf,const AM_MEDIA_TYPE LeaveCriticalSection(&m_pFilter->filterlock); } else { LeaveCriticalSection(&m_pFilter->filterlock); - CoTaskMemFree(mtype->pbFormat); + if (mtype->pbFormat!=NULL) CoTaskMemFree(mtype->pbFormat); pinempf->Release(); return VFW_E_TYPE_NOT_ACCEPTED; } } else { LeaveCriticalSection(&m_pFilter->filterlock); - CoTaskMemFree(mtype->pbFormat); + if (mtype->pbFormat!=NULL) CoTaskMemFree(mtype->pbFormat); return VFW_E_TYPE_NOT_ACCEPTED; } CoTaskMemFree(mtype->pbFormat); @@ -213,17 +216,31 @@ HRESULT STDMETHODCALLTYPE DsSourcePin::Connect(IPin *pinempf,const AM_MEDIA_TYPE pinempf->AddRef(); while (emt->Next(1,&emtype,&fetched)==S_OK) { if (CheckMediaType(emtype)==S_OK){ +/* PIN_INFO pini; + pinempf->QueryPinInfo(&pini); + if (pini.pFilter!=NULL) { + FILTER_INFO filti; + pini.pFilter->QueryFilterInfo(&filti); + + if (filti.pGraph!=NULL) filti.pGraph->Release(); + char buffer[MAX_FILTER_NAME*2]; + wcstombs(buffer,filti.achName,MAX_FILTER_NAME*2); + MessageBox(0,buffer,"Filter",0); + pini.pFilter->Release(); + }*/ + if (pinempf->ReceiveConnection((IPin*)this,emtype)==S_OK) { connected=pinempf; CopyMType(&medtype,emtype); - CoTaskMemFree(emtype->pbFormat); + if (emtype->pbFormat!=NULL) CoTaskMemFree(emtype->pbFormat); + CoTaskMemFree(emtype); gotmt=true; break; } } - CoTaskMemFree(emtype->pbFormat); + if (emtype->pbFormat!=NULL) CoTaskMemFree(emtype->pbFormat); CoTaskMemFree(emtype); } emt->Release(); @@ -234,14 +251,14 @@ HRESULT STDMETHODCALLTYPE DsSourcePin::Connect(IPin *pinempf,const AM_MEDIA_TYPE if (pinempf->ReceiveConnection((IPin*)this,emtype)==S_OK) { connected=pinempf; CopyMType(&medtype,emtype); - CoTaskMemFree(emtype->pbFormat); + if (emtype->pbFormat!=NULL) CoTaskMemFree(emtype->pbFormat); CoTaskMemFree(emtype); gotmt=true; break; } } - CoTaskMemFree(emtype->pbFormat); + if (emtype->pbFormat!=NULL) CoTaskMemFree(emtype->pbFormat); CoTaskMemFree(emtype); } emt->Release(); @@ -340,7 +357,7 @@ HRESULT STDMETHODCALLTYPE DsSourcePin::ReceiveConnection(IPin *connect, CopyMType(mtype,&medtype); return S_OK; } else { - ZeroMemory(mtype,sizeof(mtype)); + ZeroMemory(mtype,sizeof(*mtype)); return VFW_E_NOT_CONNECTED; } } @@ -425,6 +442,7 @@ HRESULT DsSourcePin::GetMediaType(int iPosition, AM_MEDIA_TYPE *pmt) wfe.wfx.nAvgBytesPerSec=32000; wfe.wfx.nBlockAlign=768; wfe.wfx.wFormatTag=WAVE_FORMAT_MPEG; + wfe.wfx.wBitsPerSample=0; wfe.fwHeadLayer=2; wfe.dwHeadBitrate=256000; wfe.fwHeadMode=ACM_MPEG_STEREO; diff --git a/remotewin.cc b/remotewin.cc index f0aed8f..28d6abd 100644 --- a/remotewin.cc +++ b/remotewin.cc @@ -199,6 +199,26 @@ int RemoteWin::ReceiveButtonAP(UINT button) { pb=VOLUMEDOWN;break; case APPCOMMAND_VOLUME_UP: pb=VOLUMEUP;break; + case VOMP_YELLOW: + pb=YELLOW; break; + case VOMP_BLUE: + pb=BLUE;break; + case VOMP_RED: + pb=RED;break; + case VOMP_GREEN: + pb=GREEN;break; + case VOMP_ENTER: + pb=OK;break; + case VOMP_CANCEL: + pb=BACK;break; + case VOMP_UP: + pb=UP;break; + case VOMP_DOWN: + pb=DOWN;break; + case VOMP_LEFT: + pb=LEFT;break; + case VOMP_RIGHT: + pb=RIGHT;break; }; if (pb==NA_NONE) return 0; curevent=pb; diff --git a/vompreswin.h b/vompreswin.h index 1178760..fdb13b9 100644 --- a/vompreswin.h +++ b/vompreswin.h @@ -25,7 +25,21 @@ #include #include #define VOMPACCELERATOR 1 +#define VOMPMENU 2 #define VOMP_FULL_SCREEN 101 +#define VOMP_YELLOW 102 +#define VOMP_BLUE 103 +#define VOMP_RED 104 +#define VOMP_GREEN 105 +#define VOMP_ENTER 106 +#define VOMP_CANCEL 107 +#define VOMP_UP 108 +#define VOMP_DOWN 109 +#define VOMP_LEFT 110 +#define VOMP_RIGHT 111 +#define VOMP_CURSORUPDATE 112 +#define VOMP_TOPMOST 113 + #define VOMPRESWIN_H #endif diff --git a/vompwin.rc b/vompwin.rc index b4620a3..80c0db5 100644 --- a/vompwin.rc +++ b/vompwin.rc @@ -44,7 +44,56 @@ vdr.jpg RCDATA other\vdr.jpg wallpaperNTSC.jpg RCDATA other\wallpaperNTSC.jpg wallpaperPAL.jpg RCDATA other\wallpaperPAL.jpg - +VOMPMENU MENU +BEGIN + POPUP "Dummy" + BEGIN + MENUITEM "&Play \t Shift+Ctrl+P", APPCOMMAND_MEDIA_PLAY + MENUITEM "Pause\t Ctrl+P", APPCOMMAND_MEDIA_PAUSE + MENUITEM "&Stop\tCtrl+S", APPCOMMAND_MEDIA_STOP + MENUITEM "Record\tCtrl+R", APPCOMMAND_MEDIA_RECORD + MENUITEM SEPARATOR + MENUITEM "Rewind\t Shift+Ctrl+B", APPCOMMAND_MEDIA_REWIND + MENUITEM "Fast Forward\t Shift+Ctrl+F", APPCOMMAND_MEDIA_FAST_FORWARD + MENUITEM SEPARATOR + MENUITEM "Skip Backward\tCtrl+B", APPCOMMAND_MEDIA_PREVIOUSTRACK + MENUITEM "Skip Forward\tCtrl+F", APPCOMMAND_MEDIA_NEXTTRACK + MENUITEM SEPARATOR + POPUP "&Menu" + BEGIN + MENUITEM "&OK\tEnter", VOMP_ENTER + MENUITEM "&Cancel\t Backspace", VOMP_CANCEL + MENUITEM SEPARATOR + MENUITEM "&Up", VOMP_UP + MENUITEM "&Down", VOMP_DOWN + MENUITEM SEPARATOR + MENUITEM "&Left", VOMP_LEFT + MENUITEM "&Right", VOMP_RIGHT + END + MENUITEM SEPARATOR + POPUP "Volume" + BEGIN + MENUITEM "Volume &Up\tF10", APPCOMMAND_VOLUME_UP + MENUITEM "Volume &Down\t F9", APPCOMMAND_VOLUME_DOWN + MENUITEM "Volume &Mute\tF8", APPCOMMAND_VOLUME_MUTE + END + MENUITEM SEPARATOR + POPUP "&Buttons" + BEGIN + MENUITEM "&Yellow", VOMP_YELLOW + MENUITEM "&Blue", VOMP_BLUE + MENUITEM "&Green", VOMP_GREEN + MENUITEM "&Red", VOMP_RED + END + MENUITEM SEPARATOR + MENUITEM "Channel &Up\t Page Up", APPCOMMAND_MEDIA_CHANNEL_UP + MENUITEM "Channel &Down\t Page Down", APPCOMMAND_MEDIA_CHANNEL_DOWN + MENUITEM SEPARATOR + MENUITEM "&Fullscreen\t Alt+Enter", VOMP_FULL_SCREEN + MENUITEM SEPARATOR + MENUITEM "&Always on Top", VOMP_TOPMOST + END +END diff --git a/winmain.cc b/winmain.cc index 3a95f25..92982a6 100644 --- a/winmain.cc +++ b/winmain.cc @@ -59,11 +59,13 @@ VDR* vdr; Video* video; Audio* audio; bool wnd_fullscreen=false; +bool wnd_topmost=false; RECT wnd_fs_rect={20,20,768+20,576+20}; RECT wnd_fs_rect_client={0,0,768,576}; //OSVERSIONINFO windows_ver; //attempt to distigsh windows versions bool remotefnc=false; - +HINSTANCE hinstance; +bool cmenu=false; HMODULE user32dll; typedef UINT (WINAPI *GETRAWINPUTDATAFNC) (HRAWINPUT,UINT,LPVOID,PUINT,UINT); @@ -72,6 +74,7 @@ typedef UINT (WINAPI *REGISTERRAWINPUTDEVICEFNC) (PCRAWINPUTDEVICE,UINT,UINT); GETRAWINPUTDATAFNC dynGetRawInputData=NULL; REGISTERRAWINPUTDEVICEFNC dynRegisterRawInputDevices=NULL; +DWORD lastmousemove; void MILLISLEEP(ULONG a) { @@ -108,6 +111,7 @@ HACCEL acc; #define ERROR_MSG(str) MessageBox(win_main,str,"Error!",MB_OK|MB_ICONWARNING) INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmdshow) { + hinstance=hinst; //On Windows we have to init a window, we use DXUT LoadRemoteFunctions(); if (!InitApp(hinst,cmdshow)) return false; @@ -309,7 +313,7 @@ INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmd // Run main loop --------------------------------------------------------------------------------------------------- // Ok, all major device components and other bits are loaded and ready - + lastmousemove=timeGetTime(); HANDLE commandthread; commandthread= CreateThread(NULL, 0, commandthreadStart, NULL,0, NULL); @@ -439,7 +443,7 @@ void ToggleFullscreen() { |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX); SetWindowPos(win_main,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); - SetWindowPos(win_main,HWND_TOP,wnd_fs_rect.left,wnd_fs_rect.top, + SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_TOP,wnd_fs_rect.left,wnd_fs_rect.top, wnd_fs_rect.right-wnd_fs_rect.left, wnd_fs_rect.bottom-wnd_fs_rect.top, SWP_DRAWFRAME | SWP_FRAMECHANGED); @@ -457,7 +461,7 @@ void ToggleFullscreen() { moninfo.cbSize=sizeof(moninfo); wnd_fullscreen=true; if (!GetMonitorInfo(monitor,&moninfo)) return ; - SetWindowPos(win_main,HWND_TOP,moninfo.rcMonitor.left,moninfo.rcMonitor.top, + SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_TOP,moninfo.rcMonitor.left,moninfo.rcMonitor.top, moninfo.rcMonitor.right,moninfo.rcMonitor.bottom,SWP_FRAMECHANGED); AdjustWindow(); @@ -467,6 +471,57 @@ void ToggleFullscreen() { } +void ToggleTopmost() { + wnd_topmost=!wnd_topmost; + SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_NOTOPMOST,0,0, + 0,0,SWP_NOMOVE | SWP_NOSIZE); +} + +void CursorUpdate() { + POINT cursorpos; + GetCursorPos(&cursorpos); + HWND asswind; + asswind=WindowFromPoint(cursorpos); + if (asswind!=win_main && asswind!=win) { + return ; //not our responsibility + } + if ((timeGetTime()-lastmousemove)<4000 || cmenu) { + SetCursor(LoadCursor(NULL,IDC_ARROW)); + } else { + SetCursor(NULL); + } +} + +bool ContextMenu(HWND wind,int x,int y) { + POINT p={x,y}; + RECT clientrect; + ScreenToClient(wind,&p); + GetClientRect(wind,&clientrect); + if (!PtInRect(&clientrect,p)) return false; + ClientToScreen(wind,&p); + HMENU menu; + HMENU popup; + menu=LoadMenu(hinstance,MAKEINTRESOURCE(VOMPMENU)); + popup=GetSubMenu(menu,0); + if (wnd_fullscreen) { + CheckMenuItem(popup,VOMP_FULL_SCREEN,MF_BYCOMMAND|MF_CHECKED); + } else { + CheckMenuItem(popup,VOMP_FULL_SCREEN,MF_BYCOMMAND|MF_UNCHECKED); + } + if (wnd_topmost) { + CheckMenuItem(popup,VOMP_TOPMOST,MF_BYCOMMAND|MF_CHECKED); + } else { + CheckMenuItem(popup,VOMP_TOPMOST,MF_BYCOMMAND|MF_UNCHECKED); + } + cmenu=true; + TrackPopupMenu(popup,TPM_RIGHTBUTTON|TPM_LEFTALIGN,x,y,0,wind, NULL); + cmenu=false; + + + DestroyMenu(menu); + return true; +} + LONG FAR PASCAL WindowProc(HWND wind, UINT msg, WPARAM wparam, LPARAM lparam) { @@ -540,6 +595,10 @@ LONG FAR PASCAL WindowProc(HWND wind, UINT msg, WPARAM wparam, LPARAM lparam) ToggleFullscreen(); return 0; } + if (LOWORD(wparam)==VOMP_TOPMOST) { + ToggleTopmost(); + return 0; + } if (((RemoteWin*)remote)->ReceiveButtonAP(LOWORD(wparam))){ return 0; //yes we process that message } else { @@ -549,7 +608,7 @@ LONG FAR PASCAL WindowProc(HWND wind, UINT msg, WPARAM wparam, LPARAM lparam) break; case WM_SETCURSOR: if (((HANDLE)wparam)==win) { - SetCursor(NULL); + CursorUpdate(); return 1; } else { return DefWindowProc(wind, msg, wparam, lparam); @@ -563,6 +622,28 @@ LONG FAR PASCAL WindowProc(HWND wind, UINT msg, WPARAM wparam, LPARAM lparam) return DefWindowProc(wind,msg,wparam, lparam); } break; + case WM_MOUSEMOVE: + lastmousemove=timeGetTime(); + SetCursor(LoadCursor(NULL,IDC_ARROW)); + SetTimer(wind,VOMP_CURSORUPDATE,4500,NULL); + return 0; + //return DefWindowProc(wind,msg,wparam, lparam); + break; + case WM_TIMER: + if (wparam==VOMP_CURSORUPDATE) { + CursorUpdate(); + return 0; + } + return DefWindowProc(wind, msg, wparam, lparam); + + break; + case WM_CONTEXTMENU: + if (!ContextMenu(wind,GET_X_LPARAM(lparam),GET_Y_LPARAM(lparam))) { + return DefWindowProc(wind, msg, wparam, lparam); + } else { + return 0; + } + default: return DefWindowProc(wind, msg, wparam, lparam); } @@ -600,7 +681,7 @@ bool InitApp(HINSTANCE hinst,int cmdshow) { /* in order to handle letterboxing we use a child window */ WNDCLASS child_wcs; child_wcs.style = CS_HREDRAW | CS_VREDRAW; - child_wcs.lpfnWndProc = DefWindowProc; + child_wcs.lpfnWndProc = WindowProc; child_wcs.cbClsExtra = 0; child_wcs.cbWndExtra = sizeof(DWORD); child_wcs.hInstance = hinst; -- 2.39.5