⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 events.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** * events.c: Windows DirectX video output events handler ***************************************************************************** * Copyright (C) 2001-2004 the VideoLAN team * $Id: 4edb568c4921a0a9f7de83d98d64105455fa1006 $ * * Authors: Gildas Bazin <gbazin@videolan.org> * * 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 Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble: This file contains the functions related to the creation of *             a window and the handling of its messages (events). *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <errno.h>                                                 /* ENOMEM */#include <ctype.h>                                              /* tolower() */#ifndef _WIN32_WINNT#   define _WIN32_WINNT 0x0500#endif#include <vlc_common.h>#include <vlc_interface.h>#include <vlc_playlist.h>#include <vlc_vout.h>#include <windows.h>#include <windowsx.h>#include <shellapi.h>#ifdef MODULE_NAME_IS_vout_directx#include <ddraw.h>#endif#ifdef MODULE_NAME_IS_direct3d#include <d3d9.h>#endif#ifdef MODULE_NAME_IS_glwin32#include <GL/gl.h>#endif#include "vlc_keys.h"#include "vout.h"#if defined(UNDER_CE) && !defined(__PLUGIN__) /*FIXME*/#   define SHFS_SHOWSIPBUTTON 0x0004#   define SHFS_HIDESIPBUTTON 0x0008#   define MENU_HEIGHT 26    BOOL SHFullScreen(HWND hwndRequester, DWORD dwState);#endif/***************************************************************************** * Local prototypes. *****************************************************************************/static int  DirectXCreateWindow( vout_thread_t *p_vout );static void DirectXCloseWindow ( vout_thread_t *p_vout );static long FAR PASCAL DirectXEventProc( HWND, UINT, WPARAM, LPARAM );static int Control( vout_thread_t *p_vout, int i_query, va_list args );static void DirectXPopupMenu( event_thread_t *p_event, bool b_open ){    vlc_value_t val;    val.b_bool = b_open;    var_Set( p_event->p_libvlc, "intf-popupmenu", val );}static int DirectXConvertKey( int i_key );/***************************************************************************** * EventThread: Create video window & handle its messages ***************************************************************************** * This function creates a video window and then enters an infinite loop * that handles the messages sent to that window. * The main goal of this thread is to isolate the Win32 PeekMessage function * because this one can block for a long time. *****************************************************************************/void* EventThread( vlc_object_t *p_this ){    event_thread_t *p_event = (event_thread_t *)p_this;    MSG msg;    POINT old_mouse_pos = {0,0}, mouse_pos;    vlc_value_t val;    unsigned int i_width, i_height, i_x, i_y;    HMODULE hkernel32;    /* Initialisation */    p_event->p_vout->pf_control = Control;    /* Create a window for the video */    /* Creating a window under Windows also initializes the thread's event     * message queue */    if( DirectXCreateWindow( p_event->p_vout ) )        p_event->b_dead = true;    /* Signal the creation of the window */    vlc_thread_ready( p_event );#ifndef UNDER_CE    /* Set power management stuff */    if( (hkernel32 = GetModuleHandle( _T("KERNEL32") ) ) )    {        ULONG (WINAPI* OurSetThreadExecutionState)( ULONG );        OurSetThreadExecutionState = (ULONG (WINAPI*)( ULONG ))            GetProcAddress( hkernel32, _T("SetThreadExecutionState") );        if( OurSetThreadExecutionState )            /* Prevent monitor from powering off */            OurSetThreadExecutionState( ES_DISPLAY_REQUIRED | ES_CONTINUOUS );        else            msg_Dbg( p_event, "no support for SetThreadExecutionState()" );    }#endif    /* Main loop */    /* GetMessage will sleep if there's no message in the queue */    while( vlc_object_alive (p_event) && GetMessage( &msg, 0, 0, 0 ) )    {        /* Check if we are asked to exit */        if( !vlc_object_alive (p_event) )            break;        switch( msg.message )        {        case WM_MOUSEMOVE:            vout_PlacePicture( p_event->p_vout,                               p_event->p_vout->p_sys->i_window_width,                               p_event->p_vout->p_sys->i_window_height,                               &i_x, &i_y, &i_width, &i_height );            if( msg.hwnd == p_event->p_vout->p_sys->hvideownd )            {                /* Child window */                i_x = i_y = 0;            }            if( i_width && i_height )            {                val.i_int = ( GET_X_LPARAM(msg.lParam) - i_x ) *                    p_event->p_vout->fmt_in.i_visible_width / i_width +                    p_event->p_vout->fmt_in.i_x_offset;                var_Set( p_event->p_vout, "mouse-x", val );                val.i_int = ( GET_Y_LPARAM(msg.lParam) - i_y ) *                    p_event->p_vout->fmt_in.i_visible_height / i_height +                    p_event->p_vout->fmt_in.i_y_offset;                var_Set( p_event->p_vout, "mouse-y", val );                val.b_bool = true;                var_Set( p_event->p_vout, "mouse-moved", val );            }        case WM_NCMOUSEMOVE:            GetCursorPos( &mouse_pos );            if( (abs(mouse_pos.x - old_mouse_pos.x) > 2 ||                (abs(mouse_pos.y - old_mouse_pos.y)) > 2 ) )            {                GetCursorPos( &old_mouse_pos );                p_event->p_vout->p_sys->i_lastmoved = mdate();                if( p_event->p_vout->p_sys->b_cursor_hidden )                {                    p_event->p_vout->p_sys->b_cursor_hidden = 0;                    ShowCursor( TRUE );                }            }            break;        case WM_VLC_HIDE_MOUSE:            if( p_event->p_vout->p_sys->b_cursor_hidden ) break;            p_event->p_vout->p_sys->b_cursor_hidden = true;            GetCursorPos( &old_mouse_pos );            ShowCursor( FALSE );            break;        case WM_VLC_SHOW_MOUSE:            if( !p_event->p_vout->p_sys->b_cursor_hidden ) break;            p_event->p_vout->p_sys->b_cursor_hidden = false;            GetCursorPos( &old_mouse_pos );            ShowCursor( TRUE );            break;        case WM_LBUTTONDOWN:            var_Get( p_event->p_vout, "mouse-button-down", &val );            val.i_int |= 1;            var_Set( p_event->p_vout, "mouse-button-down", val );            DirectXPopupMenu( p_event, false );            break;        case WM_LBUTTONUP:            var_Get( p_event->p_vout, "mouse-button-down", &val );            val.i_int &= ~1;            var_Set( p_event->p_vout, "mouse-button-down", val );            val.b_bool = true;            var_Set( p_event->p_vout, "mouse-clicked", val );            break;        case WM_LBUTTONDBLCLK:            p_event->p_vout->p_sys->i_changes |= VOUT_FULLSCREEN_CHANGE;            break;        case WM_MBUTTONDOWN:            var_Get( p_event->p_vout, "mouse-button-down", &val );            val.i_int |= 2;            var_Set( p_event->p_vout, "mouse-button-down", val );            DirectXPopupMenu( p_event, false );            break;        case WM_MBUTTONUP:            var_Get( p_event->p_vout, "mouse-button-down", &val );            val.i_int &= ~2;            var_Set( p_event->p_vout, "mouse-button-down", val );            break;        case WM_RBUTTONDOWN:            var_Get( p_event->p_vout, "mouse-button-down", &val );            val.i_int |= 4;            var_Set( p_event->p_vout, "mouse-button-down", val );            DirectXPopupMenu( p_event, false );            break;        case WM_RBUTTONUP:            var_Get( p_event->p_vout, "mouse-button-down", &val );            val.i_int &= ~4;            var_Set( p_event->p_vout, "mouse-button-down", val );            DirectXPopupMenu( p_event, true );            break;        case WM_KEYDOWN:        case WM_SYSKEYDOWN:            /* The key events are first processed here and not translated             * into WM_CHAR events because we need to know the status of the             * modifier keys. */            val.i_int = DirectXConvertKey( msg.wParam );            if( !val.i_int )            {                /* This appears to be a "normal" (ascii) key */                val.i_int = tolower( MapVirtualKey( msg.wParam, 2 ) );            }            if( val.i_int )            {                if( GetKeyState(VK_CONTROL) & 0x8000 )                {                    val.i_int |= KEY_MODIFIER_CTRL;                }                if( GetKeyState(VK_SHIFT) & 0x8000 )                {                    val.i_int |= KEY_MODIFIER_SHIFT;                }                if( GetKeyState(VK_MENU) & 0x8000 )                {                    val.i_int |= KEY_MODIFIER_ALT;                }                var_Set( p_event->p_libvlc, "key-pressed", val );            }            break;        case WM_MOUSEWHEEL:            if( GET_WHEEL_DELTA_WPARAM( msg.wParam ) > 0 )            {                val.i_int = KEY_MOUSEWHEELUP;            }            else            {                val.i_int = KEY_MOUSEWHEELDOWN;            }            if( val.i_int )            {                if( GetKeyState(VK_CONTROL) & 0x8000 )                {                    val.i_int |= KEY_MODIFIER_CTRL;                }                if( GetKeyState(VK_SHIFT) & 0x8000 )                {                    val.i_int |= KEY_MODIFIER_SHIFT;                }                if( GetKeyState(VK_MENU) & 0x8000 )                {                    val.i_int |= KEY_MODIFIER_ALT;                }                var_Set( p_event->p_libvlc, "key-pressed", val );            }            break;        case WM_VLC_CHANGE_TEXT:            var_Get( p_event->p_vout, "video-title", &val );            if( !val.psz_string || !*val.psz_string ) /* Default video title */            {                free( val.psz_string );#ifdef MODULE_NAME_IS_wingdi                val.psz_string = strdup( VOUT_TITLE " (WinGDI output)" );#endif#ifdef MODULE_NAME_IS_wingapi                val.psz_string = strdup( VOUT_TITLE " (WinGAPI output)" );#endif#ifdef MODULE_NAME_IS_glwin32                val.psz_string = strdup( VOUT_TITLE " (OpenGL output)" );#endif#ifdef MODULE_NAME_IS_direct3d                val.psz_string = strdup( VOUT_TITLE " (Direct3D output)" );#endif#ifdef MODULE_NAME_IS_vout_directx                if( p_event->p_vout->p_sys->b_using_overlay ) val.psz_string =                    strdup( VOUT_TITLE " (hardware YUV overlay DirectX output)" );                else if( p_event->p_vout->p_sys->b_hw_yuv ) val.psz_string =                    strdup( VOUT_TITLE " (hardware YUV DirectX output)" );                else val.psz_string =                    strdup( VOUT_TITLE " (software RGB DirectX output)" );#endif            }#ifdef UNICODE            {                wchar_t *psz_title = malloc( strlen(val.psz_string) * 2 + 2 );                if( psz_title )                {                    mbstowcs( psz_title, val.psz_string, strlen(val.psz_string)*2);                    psz_title[strlen(val.psz_string)] = 0;                    free( val.psz_string ); val.psz_string = (char *)psz_title;                }            }#endif            SetWindowText( p_event->p_vout->p_sys->hwnd,                           (LPCTSTR)val.psz_string );            if( p_event->p_vout->p_sys->hfswnd )                SetWindowText( p_event->p_vout->p_sys->hfswnd,                               (LPCTSTR)val.psz_string );            free( val.psz_string );            break;        default:            /* Messages we don't handle directly are dispatched to the             * window procedure */            TranslateMessage(&msg);            DispatchMessage(&msg);            break;        } /* End Switch */    } /* End Main loop */    /* Check for WM_QUIT if we created the window */    if( !p_event->p_vout->p_sys->hparent && msg.message == WM_QUIT )    {        msg_Warn( p_event, "WM_QUIT... should not happen!!" );        p_event->p_vout->p_sys->hwnd = NULL; /* Window already destroyed */    }    msg_Dbg( p_event, "DirectXEventThread terminating" );    /* clear the changes formerly signaled */    p_event->p_vout->p_sys->i_changes = 0;    DirectXCloseWindow( p_event->p_vout );    return NULL;}/* following functions are local *//***************************************************************************** * DirectXCreateWindow: create a window for the video. ***************************************************************************** * Before creating a direct draw surface, we need to create a window in which * the video will be displayed. This window will also allow us to capture the * events. *****************************************************************************/static int DirectXCreateWindow( vout_thread_t *p_vout ){    HINSTANCE  hInstance;    HMENU      hMenu;    RECT       rect_window;    WNDCLASS   wc;                            /* window class components */    HICON      vlc_icon = NULL;    char       vlc_path[MAX_PATH+1];    int        i_style, i_stylex;    msg_Dbg( p_vout, "DirectXCreateWindow" );    /* Get this module's instance */    hInstance = GetModuleHandle(NULL);    /* If an external window was specified, we'll draw in it. */    p_vout->p_sys->hparent =        vout_RequestWindow( p_vout, &p_vout->p_sys->i_window_x,                            &p_vout->p_sys->i_window_y,                            &p_vout->p_sys->i_window_width,                            &p_vout->p_sys->i_window_height );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -