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

📄 events.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 3 页
字号:
    /* We create the window ourself, there is no previous window proc. */    p_vout->p_sys->pf_wndproc = NULL;    /* Get the Icon from the main app */    vlc_icon = NULL;#ifndef UNDER_CE    if( GetModuleFileName( NULL, vlc_path, MAX_PATH ) )    {        vlc_icon = ExtractIcon( hInstance, vlc_path, 0 );    }#endif    /* Fill in the window class structure */    wc.style         = CS_OWNDC|CS_DBLCLKS;          /* style: dbl click */    wc.lpfnWndProc   = (WNDPROC)DirectXEventProc;       /* event handler */    wc.cbClsExtra    = 0;                         /* no extra class data */    wc.cbWndExtra    = 0;                        /* no extra window data */    wc.hInstance     = hInstance;                            /* instance */    wc.hIcon         = vlc_icon;                /* load the vlc big icon */    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);    /* default cursor */    wc.hbrBackground = GetStockObject(BLACK_BRUSH);  /* background color */    wc.lpszMenuName  = NULL;                                  /* no menu */    wc.lpszClassName = _T("VLC DirectX");         /* use a special class */    /* Register the window class */    if( !RegisterClass(&wc) )    {        WNDCLASS wndclass;        if( vlc_icon ) DestroyIcon( vlc_icon );        /* Check why it failed. If it's because one already exists         * then fine, otherwise return with an error. */        if( !GetClassInfo( hInstance, _T("VLC DirectX"), &wndclass ) )        {            msg_Err( p_vout, "DirectXCreateWindow RegisterClass FAILED (err=%lu)", GetLastError() );            return VLC_EGENERIC;        }    }    /* Register the video sub-window class */    wc.lpszClassName = _T("VLC DirectX video"); wc.hIcon = 0;    wc.hbrBackground = NULL; /* no background color */    if( !RegisterClass(&wc) )    {        WNDCLASS wndclass;        /* Check why it failed. If it's because one already exists         * then fine, otherwise return with an error. */        if( !GetClassInfo( hInstance, _T("VLC DirectX video"), &wndclass ) )        {            msg_Err( p_vout, "DirectXCreateWindow RegisterClass FAILED (err=%lu)", GetLastError() );            return VLC_EGENERIC;        }    }    /* When you create a window you give the dimensions you wish it to     * have. Unfortunatly these dimensions will include the borders and     * titlebar. We use the following function to find out the size of     * the window corresponding to the useable surface we want */    rect_window.top    = 10;    rect_window.left   = 10;    rect_window.right  = rect_window.left + p_vout->p_sys->i_window_width;    rect_window.bottom = rect_window.top + p_vout->p_sys->i_window_height;    if( var_GetBool( p_vout, "video-deco" ) )    {        /* Open with window decoration */        AdjustWindowRect( &rect_window, WS_OVERLAPPEDWINDOW|WS_SIZEBOX, 0 );        i_style = WS_OVERLAPPEDWINDOW|WS_SIZEBOX|WS_VISIBLE|WS_CLIPCHILDREN;        i_stylex = 0;    }    else    {        /* No window decoration */        AdjustWindowRect( &rect_window, WS_POPUP, 0 );        i_style = WS_POPUP|WS_VISIBLE|WS_CLIPCHILDREN;        i_stylex = 0; // WS_EX_TOOLWINDOW; Is TOOLWINDOW really needed ?                      // It messes up the fullscreen window.    }    if( p_vout->p_sys->hparent )    {        i_style = WS_VISIBLE|WS_CLIPCHILDREN|WS_CHILD;        i_stylex = 0;    }    p_vout->p_sys->i_window_style = i_style;    /* Create the window */    p_vout->p_sys->hwnd =        CreateWindowEx( WS_EX_NOPARENTNOTIFY | i_stylex,                    _T("VLC DirectX"),               /* name of window class */                    _T(VOUT_TITLE) _T(" (DirectX Output)"),  /* window title */                    i_style,                                 /* window style */                    (p_vout->p_sys->i_window_x < 0) ? CW_USEDEFAULT :                        (UINT)p_vout->p_sys->i_window_x,   /* default X coordinate */                    (p_vout->p_sys->i_window_y < 0) ? CW_USEDEFAULT :                        (UINT)p_vout->p_sys->i_window_y,   /* default Y coordinate */                    rect_window.right - rect_window.left,    /* window width */                    rect_window.bottom - rect_window.top,   /* window height */                    p_vout->p_sys->hparent,                 /* parent window */                    NULL,                          /* no menu in this window */                    hInstance,            /* handle of this program instance */                    (LPVOID)p_vout );            /* send p_vout to WM_CREATE */    if( !p_vout->p_sys->hwnd )    {        msg_Warn( p_vout, "DirectXCreateWindow create window FAILED (err=%lu)", GetLastError() );        return VLC_EGENERIC;    }    if( p_vout->p_sys->hparent )    {        LONG i_style;        /* We don't want the window owner to overwrite our client area */        i_style = GetWindowLong( p_vout->p_sys->hparent, GWL_STYLE );        if( !(i_style & WS_CLIPCHILDREN) )            /* Hmmm, apparently this is a blocking call... */            SetWindowLong( p_vout->p_sys->hparent, GWL_STYLE,                           i_style | WS_CLIPCHILDREN );        /* Create our fullscreen window */        p_vout->p_sys->hfswnd =            CreateWindowEx( WS_EX_APPWINDOW, _T("VLC DirectX"),                            _T(VOUT_TITLE) _T(" (DirectX Output)"),                            WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN|WS_SIZEBOX,                            CW_USEDEFAULT, CW_USEDEFAULT,                            CW_USEDEFAULT, CW_USEDEFAULT,                            NULL, NULL, hInstance, NULL );    }    /* Append a "Always On Top" entry in the system menu */    hMenu = GetSystemMenu( p_vout->p_sys->hwnd, FALSE );    AppendMenu( hMenu, MF_SEPARATOR, 0, _T("") );    AppendMenu( hMenu, MF_STRING | MF_UNCHECKED,                       IDM_TOGGLE_ON_TOP, _T("Always on &Top") );    /* Create video sub-window. This sub window will always exactly match     * the size of the video, which allows us to use crazy overlay colorkeys     * without having them shown outside of the video area. */    p_vout->p_sys->hvideownd =    CreateWindow( _T("VLC DirectX video"), _T(""),   /* window class */        WS_CHILD,                   /* window style, not visible initially */        0, 0,        p_vout->render.i_width,         /* default width */        p_vout->render.i_height,        /* default height */        p_vout->p_sys->hwnd,                    /* parent window */        NULL, hInstance,        (LPVOID)p_vout );            /* send p_vout to WM_CREATE */    if( !p_vout->p_sys->hvideownd )        msg_Warn( p_vout, "can't create video sub-window" );    else        msg_Dbg( p_vout, "created video sub-window" );    /* Now display the window */    ShowWindow( p_vout->p_sys->hwnd, SW_SHOW );    return VLC_SUCCESS;}/***************************************************************************** * DirectXCloseWindow: close the window created by DirectXCreateWindow ***************************************************************************** * This function returns all resources allocated by DirectXCreateWindow. *****************************************************************************/static void DirectXCloseWindow( vout_thread_t *p_vout ){    msg_Dbg( p_vout, "DirectXCloseWindow" );    DestroyWindow( p_vout->p_sys->hwnd );    if( p_vout->p_sys->hfswnd ) DestroyWindow( p_vout->p_sys->hfswnd );    if( p_vout->p_sys->hparent )        vout_ReleaseWindow( p_vout, (void *)p_vout->p_sys->hparent );    p_vout->p_sys->hwnd = NULL;    /* We don't unregister the Window Class because it could lead to race     * conditions and it will be done anyway by the system when the app will     * exit */}/***************************************************************************** * UpdateRects: update clipping rectangles ***************************************************************************** * This function is called when the window position or size are changed, and * its job is to update the source and destination RECTs used to display the * picture. *****************************************************************************/void UpdateRects( vout_thread_t *p_vout, bool b_force ){#define rect_src p_vout->p_sys->rect_src#define rect_src_clipped p_vout->p_sys->rect_src_clipped#define rect_dest p_vout->p_sys->rect_dest#define rect_dest_clipped p_vout->p_sys->rect_dest_clipped    int i_width, i_height, i_x, i_y;    RECT  rect;    POINT point;    /* Retrieve the window size */    GetClientRect( p_vout->p_sys->hwnd, &rect );    /* Retrieve the window position */    point.x = point.y = 0;    ClientToScreen( p_vout->p_sys->hwnd, &point );    /* If nothing changed, we can return */    if( !b_force         && p_vout->p_sys->i_window_width == rect.right         && p_vout->p_sys->i_window_height == rect.bottom         && p_vout->p_sys->i_window_x == point.x         && p_vout->p_sys->i_window_y == point.y )    {        return;    }    /* Update the window position and size */    p_vout->p_sys->i_window_x = point.x;    p_vout->p_sys->i_window_y = point.y;    p_vout->p_sys->i_window_width = rect.right;    p_vout->p_sys->i_window_height = rect.bottom;    vout_PlacePicture( p_vout, rect.right, rect.bottom,                       &i_x, &i_y, &i_width, &i_height );    if( p_vout->p_sys->hvideownd )        SetWindowPos( p_vout->p_sys->hvideownd, 0,                      i_x, i_y, i_width, i_height,                      SWP_NOCOPYBITS|SWP_NOZORDER|SWP_ASYNCWINDOWPOS );    /* Destination image position and dimensions */    rect_dest.left = point.x + i_x;    rect_dest.right = rect_dest.left + i_width;    rect_dest.top = point.y + i_y;    rect_dest.bottom = rect_dest.top + i_height;#ifdef MODULE_NAME_IS_vout_directx    /* Apply overlay hardware constraints */    if( p_vout->p_sys->b_using_overlay )    {        if( p_vout->p_sys->i_align_dest_boundary )            rect_dest.left = ( rect_dest.left +                p_vout->p_sys->i_align_dest_boundary / 2 ) &                ~p_vout->p_sys->i_align_dest_boundary;        if( p_vout->p_sys->i_align_dest_size )            rect_dest.right = (( rect_dest.right - rect_dest.left +                p_vout->p_sys->i_align_dest_size / 2 ) &                ~p_vout->p_sys->i_align_dest_size) + rect_dest.left;    }    /* UpdateOverlay directdraw function doesn't automatically clip to the     * display size so we need to do it otherwise it will fail */    /* Clip the destination window */    if( !IntersectRect( &rect_dest_clipped, &rect_dest,                        &p_vout->p_sys->rect_display ) )    {        SetRectEmpty( &rect_src_clipped );        return;    }#if 0    msg_Dbg( p_vout, "DirectXUpdateRects image_dst_clipped coords:"                     " %i,%i,%i,%i",                     rect_dest_clipped.left, rect_dest_clipped.top,                     rect_dest_clipped.right, rect_dest_clipped.bottom );#endif#else /* MODULE_NAME_IS_vout_directx */    /* AFAIK, there are no clipping constraints in Direct3D, OpenGL and GDI */    rect_dest_clipped = rect_dest;#endif    /* the 2 following lines are to fix a bug when clicking on the desktop */    if( (rect_dest_clipped.right - rect_dest_clipped.left)==0 ||        (rect_dest_clipped.bottom - rect_dest_clipped.top)==0 )    {        SetRectEmpty( &rect_src_clipped );        return;    }    /* src image dimensions */    rect_src.left = 0;    rect_src.top = 0;    rect_src.right = p_vout->render.i_width;    rect_src.bottom = p_vout->render.i_height;    /* Clip the source image */    rect_src_clipped.left = p_vout->fmt_out.i_x_offset +      (rect_dest_clipped.left - rect_dest.left) *      p_vout->fmt_out.i_visible_width / (rect_dest.right - rect_dest.left);    rect_src_clipped.right = p_vout->fmt_out.i_x_offset +      p_vout->fmt_out.i_visible_width -      (rect_dest.right - rect_dest_clipped.right) *      p_vout->fmt_out.i_visible_width / (rect_dest.right - rect_dest.left);    rect_src_clipped.top = p_vout->fmt_out.i_y_offset +      (rect_dest_clipped.top - rect_dest.top) *      p_vout->fmt_out.i_visible_height / (rect_dest.bottom - rect_dest.top);    rect_src_clipped.bottom = p_vout->fmt_out.i_y_offset +      p_vout->fmt_out.i_visible_height -      (rect_dest.bottom - rect_dest_clipped.bottom) *      p_vout->fmt_out.i_visible_height / (rect_dest.bottom - rect_dest.top);#ifdef MODULE_NAME_IS_vout_directx    /* Apply overlay hardware constraints */    if( p_vout->p_sys->b_using_overlay )    {        if( p_vout->p_sys->i_align_src_boundary )            rect_src_clipped.left = ( rect_src_clipped.left +                p_vout->p_sys->i_align_src_boundary / 2 ) &                ~p_vout->p_sys->i_align_src_boundary;        if( p_vout->p_sys->i_align_src_size )            rect_src_clipped.right = (( rect_src_clipped.right -                rect_src_clipped.left +                p_vout->p_sys->i_align_src_size / 2 ) &                ~p_vout->p_sys->i_align_src_size) + rect_src_clipped.left;    }#endif#if 0    msg_Dbg( p_vout, "DirectXUpdateRects image_src_clipped"                     " coords: %i,%i,%i,%i",                     rect_src_clipped.left, rect_src_clipped.top,                     rect_src_clipped.right, rect_src_clipped.bottom );#endif#ifdef MODULE_NAME_IS_vout_directx    /* The destination coordinates need to be relative to the current     * directdraw primary surface (display) */    rect_dest_clipped.left -= p_vout->p_sys->rect_display.left;    rect_dest_clipped.right -= p_vout->p_sys->rect_display.left;    rect_dest_clipped.top -= p_vout->p_sys->rect_display.top;    rect_dest_clipped.bottom -= p_vout->p_sys->rect_display.top;    if( p_vout->p_sys->b_using_overlay )        DirectDrawUpdateOverlay( p_vout );#endif    /* Signal the change in size/position */    p_vout->p_sys->i_changes |= DX_POSITION_CHANGE;#undef rect_src#undef rect_src_clipped#undef rect_dest#undef rect_dest_clipped}/***************************************************************************** * DirectXEventProc: This is the window event processing function. ***************************************************************************** * On Windows, when you create a window you have to attach an event processing * function to it. The aim of this function is to manage "Queued Messages" and * "Nonqueued Messages". * Queued Messages are those picked up and retransmitted by vout_Manage * (using the GetMessage and DispatchMessage functions). * Nonqueued Messages are those that Windows will send directly to this * procedure (like WM_DESTROY, WM_WINDOWPOSCHANGED...) *****************************************************************************/static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,                                         WPARAM wParam, LPARAM lParam ){    vout_thread_t *p_vout;    if( message == WM_CREATE )    {        /* Store p_vout for future use */        p_vout = (vout_thread_t *)((CREATESTRUCT *)lParam)->lpCreateParams;        SetWindowLongPtr( hwnd, GWLP_USERDATA, (LONG_PTR)p_vout );        return TRUE;    }    else    {        p_vout = (vout_thread_t *)GetWindowLongPtr( hwnd, GWLP_USERDATA );        if( !p_vout )        {            /* Hmmm mozilla does manage somehow to save the pointer to our             * windowproc and still calls it after the vout has been closed. */            return DefWindowProc(hwnd, message, wParam, lParam);        }    }#ifndef UNDER_CE    /* Catch the screensaver and the monitor turn-off */    if( message == WM_SYSCOMMAND &&        ( (wParam & 0xFFF0) == SC_SCREENSAVE || (wParam & 0xFFF0) == SC_MONITORPOWER ) )    {        //if( p_vout ) msg_Dbg( p_vout, "WinProc WM_SYSCOMMAND screensaver" );        return 0; /* this stops them from happening */    }#endif    if( hwnd == p_vout->p_sys->hvideownd )    {        switch( message )        {#ifdef MODULE_NAME_IS_vout_directx        case WM_ERASEBKGND:        /* For overlay, we need to erase background */            return !p_vout->p_sys->b_using_overlay ?                1 : DefWindowProc(hwnd, message, wParam, lParam);        case WM_PAINT:        /*        ** For overlay, DefWindowProc() will erase dirty regions

⌨️ 快捷键说明

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