📄 plugin.cpp
字号:
WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, lprcPosRect->left, lprcPosRect->top, lprcPosRect->right-lprcPosRect->left, lprcPosRect->bottom-lprcPosRect->top, hwndParent, 0, _p_class->getHInstance(), NULL ); if( NULL == _inplacewnd ) return E_FAIL; SetWindowLongPtr(_inplacewnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); /* change cliprect coordinates system relative to window bounding rect */ OffsetRect(&clipRect, -lprcPosRect->left, -lprcPosRect->top); HRGN clipRgn = CreateRectRgnIndirect(&clipRect); SetWindowRgn(_inplacewnd, clipRgn, TRUE); if( _b_usermode ) { /* will run vlc if not done already */ libvlc_instance_t* p_libvlc; HRESULT result = getVLC(&p_libvlc); if( FAILED(result) ) return result; /* set internal video width and height */ libvlc_video_set_size(p_libvlc, lprcPosRect->right-lprcPosRect->left, lprcPosRect->bottom-lprcPosRect->top, NULL ); /* set internal video parent window */ libvlc_video_set_parent(p_libvlc, reinterpret_cast<libvlc_drawable_t>(_inplacewnd), NULL); if( _b_autoplay & (libvlc_playlist_items_count(p_libvlc, NULL) > 0) ) { libvlc_playlist_play(p_libvlc, 0, 0, NULL, NULL); fireOnPlayEvent(); } } if( isVisible() ) ShowWindow(_inplacewnd, SW_SHOW); return S_OK;};HRESULT VLCPlugin::onInPlaceDeactivate(void){ if( isRunning() ) { libvlc_playlist_stop(_p_libvlc, NULL); fireOnStopEvent(); } DestroyWindow(_inplacewnd); _inplacewnd = NULL; return S_OK;};void VLCPlugin::setVisible(BOOL fVisible){ if( fVisible != _b_visible ) { _b_visible = fVisible; if( isInPlaceActive() ) { ShowWindow(_inplacewnd, fVisible ? SW_SHOW : SW_HIDE); if( fVisible ) InvalidateRect(_inplacewnd, NULL, TRUE); } setDirty(TRUE); firePropChangedEvent(DISPID_Visible); }};void VLCPlugin::setVolume(int volume){ if( volume < 0 ) volume = 0; else if( volume > 200 ) volume = 200; if( volume != _i_volume ) { _i_volume = volume; if( isRunning() ) { libvlc_audio_set_volume(_p_libvlc, _i_volume, NULL); } setDirty(TRUE); }};void VLCPlugin::setBackColor(OLE_COLOR backcolor){ if( _i_backcolor != backcolor ) { _i_backcolor = backcolor; if( isInPlaceActive() ) { } setDirty(TRUE); }};void VLCPlugin::setTime(int seconds){ if( seconds < 0 ) seconds = 0; if( seconds != _i_time ) { setStartTime(_i_time); if( isRunning() ) { libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(_p_libvlc, NULL); if( NULL != p_md ) { libvlc_media_player_set_time(p_md, _i_time, NULL); libvlc_media_player_release(p_md); } } }};void VLCPlugin::setFocus(BOOL fFocus){ if( fFocus ) SetActiveWindow(_inplacewnd);};BOOL VLCPlugin::hasFocus(void){ return GetActiveWindow() == _inplacewnd;};void VLCPlugin::onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev, HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds){ if( isVisible() ) { long width = lprcBounds->right-lprcBounds->left; long height = lprcBounds->bottom-lprcBounds->top; RECT bounds = { lprcBounds->left, lprcBounds->top, lprcBounds->right, lprcBounds->bottom }; if( isUserMode() ) { /* VLC is in user mode, just draw background color */ COLORREF colorref = RGB(0, 0, 0); OleTranslateColor(_i_backcolor, (HPALETTE)GetStockObject(DEFAULT_PALETTE), &colorref); if( colorref != RGB(0, 0, 0) ) { /* custom background */ HBRUSH colorbrush = CreateSolidBrush(colorref); FillRect(hdcDraw, &bounds, colorbrush); DeleteObject((HANDLE)colorbrush); } else { /* black background */ FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(BLACK_BRUSH)); } } else { /* VLC is in design mode, draw the VLC logo */ FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(WHITE_BRUSH)); LPPICTURE pict = getPicture(); if( NULL != pict ) { OLE_XSIZE_HIMETRIC picWidth; OLE_YSIZE_HIMETRIC picHeight; pict->get_Width(&picWidth); pict->get_Height(&picHeight); SIZEL picSize = { picWidth, picHeight }; if( NULL != hicTargetDev ) { DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1); } else if( NULL != (hicTargetDev = CreateDevDC(ptd)) ) { DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1); DeleteDC(hicTargetDev); } if( picSize.cx > width-4 ) picSize.cx = width-4; if( picSize.cy > height-4 ) picSize.cy = height-4; LONG dstX = lprcBounds->left+(width-picSize.cx)/2; LONG dstY = lprcBounds->top+(height-picSize.cy)/2; if( NULL != lprcWBounds ) { RECT wBounds = { lprcWBounds->left, lprcWBounds->top, lprcWBounds->right, lprcWBounds->bottom }; pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy, 0L, picHeight, picWidth, -picHeight, &wBounds); } else pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy, 0L, picHeight, picWidth, -picHeight, NULL); pict->Release(); } SelectObject(hdcDraw, GetStockObject(BLACK_BRUSH)); MoveToEx(hdcDraw, bounds.left, bounds.top, NULL); LineTo(hdcDraw, bounds.left+width-1, bounds.top); LineTo(hdcDraw, bounds.left+width-1, bounds.top+height-1); LineTo(hdcDraw, bounds.left, bounds.top+height-1); LineTo(hdcDraw, bounds.left, bounds.top); } }};void VLCPlugin::onPaint(HDC hdc, const RECT &bounds, const RECT &clipRect){ if( isVisible() ) { /* if VLC is in design mode, draw control logo */ HDC hdcDraw = CreateCompatibleDC(hdc); if( NULL != hdcDraw ) { SIZEL size = getExtent(); DPFromHimetric(hdc, (LPPOINT)&size, 1); RECTL posRect = { 0, 0, size.cx, size.cy }; int width = bounds.right-bounds.left; int height = bounds.bottom-bounds.top; HBITMAP hBitmap = CreateCompatibleBitmap(hdc, width, height); if( NULL != hBitmap ) { HBITMAP oldBmp = (HBITMAP)SelectObject(hdcDraw, hBitmap); if( (size.cx != width) || (size.cy != height) ) { // needs to scale canvas SetMapMode(hdcDraw, MM_ANISOTROPIC); SetWindowExtEx(hdcDraw, size.cx, size.cy, NULL); SetViewportExtEx(hdcDraw, width, height, NULL); } onDraw(NULL, hdc, hdcDraw, &posRect, NULL); SetMapMode(hdcDraw, MM_TEXT); BitBlt(hdc, bounds.left, bounds.top, width, height, hdcDraw, 0, 0, SRCCOPY); SelectObject(hdcDraw, oldBmp); DeleteObject(hBitmap); } DeleteDC(hdcDraw); } }};void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect){ RECT clipRect = *lprcClipRect; //RedrawWindow(GetParent(_inplacewnd), &_posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN); /* ** record keeping of control geometry within container */ _posRect = *lprcPosRect; /* ** change in-place window geometry to match clipping region */ SetWindowPos(_inplacewnd, NULL, lprcPosRect->left, lprcPosRect->top, lprcPosRect->right-lprcPosRect->left, lprcPosRect->bottom-lprcPosRect->top, SWP_NOACTIVATE| SWP_NOCOPYBITS| SWP_NOZORDER| SWP_NOOWNERZORDER ); /* change cliprect coordinates system relative to window bounding rect */ OffsetRect(&clipRect, -lprcPosRect->left, -lprcPosRect->top); HRGN clipRgn = CreateRectRgnIndirect(&clipRect); SetWindowRgn(_inplacewnd, clipRgn, FALSE); //RedrawWindow(_videownd, &posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN); if( isRunning() ) { libvlc_video_set_size(_p_libvlc, lprcPosRect->right-lprcPosRect->left, lprcPosRect->bottom-lprcPosRect->top, NULL ); }};void VLCPlugin::freezeEvents(BOOL freeze){ vlcConnectionPointContainer->freezeEvents(freeze);};void VLCPlugin::firePropChangedEvent(DISPID dispid){ vlcConnectionPointContainer->firePropChangedEvent(dispid);};void VLCPlugin::fireOnPlayEvent(void){ DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0}; vlcConnectionPointContainer->fireEvent(DISPID_PlayEvent, &dispparamsNoArgs);};void VLCPlugin::fireOnPauseEvent(void){ DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0}; vlcConnectionPointContainer->fireEvent(DISPID_PauseEvent, &dispparamsNoArgs);};void VLCPlugin::fireOnStopEvent(void){ DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0}; vlcConnectionPointContainer->fireEvent(DISPID_StopEvent, &dispparamsNoArgs);};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -