events.c
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:42k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * events.c: Windows DirectX video output events handler
  3.  *****************************************************************************
  4.  * Copyright (C) 2001-2009 the VideoLAN team
  5.  * $Id: 53760a335c4b9b00d205fbc3989cc64d7b6b0908 $
  6.  *
  7.  * Authors: Gildas Bazin <gbazin@videolan.org>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  22.  *****************************************************************************/
  23. /*****************************************************************************
  24.  * Preamble: This file contains the functions related to the creation of
  25.  *             a window and the handling of its messages (events).
  26.  *****************************************************************************/
  27. #ifdef HAVE_CONFIG_H
  28. # include "config.h"
  29. #endif
  30. #include <errno.h>                                                 /* ENOMEM */
  31. #include <ctype.h>                                              /* tolower() */
  32. #ifndef _WIN32_WINNT
  33. #   define _WIN32_WINNT 0x0500
  34. #endif
  35. #include <vlc_common.h>
  36. #include <vlc_interface.h>
  37. #include <vlc_playlist.h>
  38. #include <vlc_vout.h>
  39. #include <vlc_window.h>
  40. #include <windows.h>
  41. #include <tchar.h>
  42. #include <windowsx.h>
  43. #include <shellapi.h>
  44. #ifdef MODULE_NAME_IS_vout_directx
  45. #include <ddraw.h>
  46. #endif
  47. #ifdef MODULE_NAME_IS_direct3d
  48. #include <d3d9.h>
  49. #endif
  50. #ifdef MODULE_NAME_IS_glwin32
  51. #include <GL/gl.h>
  52. #endif
  53. #include "vlc_keys.h"
  54. #include "vout.h"
  55. #ifdef UNDER_CE
  56. #include <aygshell.h>
  57.     //WINSHELLAPI BOOL WINAPI SHFullScreen(HWND hwndRequester, DWORD dwState);
  58. #endif
  59. /*#if defined(UNDER_CE) && !defined(__PLUGIN__) --FIXME*/
  60. /*#   define SHFS_SHOWSIPBUTTON 0x0004
  61. #   define SHFS_HIDESIPBUTTON 0x0008
  62. #   define MENU_HEIGHT 26
  63.     BOOL SHFullScreen(HWND hwndRequester, DWORD dwState);
  64. #endif*/
  65. /*****************************************************************************
  66.  * Local prototypes.
  67.  *****************************************************************************/
  68. static int  DirectXCreateWindow( vout_thread_t *p_vout );
  69. static void DirectXCloseWindow ( vout_thread_t *p_vout );
  70. static long FAR PASCAL DirectXEventProc( HWND, UINT, WPARAM, LPARAM );
  71. static int Control( vout_thread_t *p_vout, int i_query, va_list args );
  72. static int vaControlParentWindow( vout_thread_t *, int, va_list );
  73. static void DirectXPopupMenu( event_thread_t *p_event, bool b_open )
  74. {
  75.     vlc_value_t val;
  76.     val.b_bool = b_open;
  77.     var_Set( p_event->p_libvlc, "intf-popupmenu", val );
  78. }
  79. static int DirectXConvertKey( int i_key );
  80. /*****************************************************************************
  81.  * EventThread: Create video window & handle its messages
  82.  *****************************************************************************
  83.  * This function creates a video window and then enters an infinite loop
  84.  * that handles the messages sent to that window.
  85.  * The main goal of this thread is to isolate the Win32 PeekMessage function
  86.  * because this one can block for a long time.
  87.  *****************************************************************************/
  88. void* EventThread( vlc_object_t *p_this )
  89. {
  90.     event_thread_t *p_event = (event_thread_t *)p_this;
  91.     MSG msg;
  92.     POINT old_mouse_pos = {0,0}, mouse_pos;
  93.     vlc_value_t val;
  94.     unsigned int i_width, i_height, i_x, i_y;
  95.     HMODULE hkernel32;
  96.     int canc = vlc_savecancel ();
  97.     /* Initialisation */
  98.     p_event->p_vout->pf_control = Control;
  99.     /* Create a window for the video */
  100.     /* Creating a window under Windows also initializes the thread's event
  101.      * message queue */
  102.     if( DirectXCreateWindow( p_event->p_vout ) )
  103.     {
  104.         vlc_restorecancel (canc);
  105.         return NULL;
  106.     }
  107.     /* Signal the creation of the window */
  108.     SetEvent( p_event->window_ready );
  109. #ifndef UNDER_CE
  110.     /* Set power management stuff */
  111.     if( (hkernel32 = GetModuleHandle( _T("KERNEL32") ) ) )
  112.     {
  113.         ULONG (WINAPI* OurSetThreadExecutionState)( ULONG );
  114.         OurSetThreadExecutionState = (ULONG (WINAPI*)( ULONG ))
  115.             GetProcAddress( hkernel32, _T("SetThreadExecutionState") );
  116.         if( OurSetThreadExecutionState )
  117.             /* Prevent monitor from powering off */
  118.             OurSetThreadExecutionState( ES_DISPLAY_REQUIRED | ES_CONTINUOUS );
  119.         else
  120.             msg_Dbg( p_event, "no support for SetThreadExecutionState()" );
  121.     }
  122. #endif
  123.     /* Main loop */
  124.     /* GetMessage will sleep if there's no message in the queue */
  125.     while( vlc_object_alive (p_event) && GetMessage( &msg, 0, 0, 0 ) )
  126.     {
  127.         /* Check if we are asked to exit */
  128.         if( !vlc_object_alive (p_event) )
  129.             break;
  130.         switch( msg.message )
  131.         {
  132.         case WM_MOUSEMOVE:
  133.             vout_PlacePicture( p_event->p_vout,
  134.                                p_event->p_vout->p_sys->i_window_width,
  135.                                p_event->p_vout->p_sys->i_window_height,
  136.                                &i_x, &i_y, &i_width, &i_height );
  137.             if( msg.hwnd == p_event->p_vout->p_sys->hvideownd )
  138.             {
  139.                 /* Child window */
  140.                 i_x = i_y = 0;
  141.             }
  142.             if( i_width && i_height )
  143.             {
  144.                 val.i_int = ( GET_X_LPARAM(msg.lParam) - i_x ) *
  145.                     p_event->p_vout->fmt_in.i_visible_width / i_width +
  146.                     p_event->p_vout->fmt_in.i_x_offset;
  147.                 var_Set( p_event->p_vout, "mouse-x", val );
  148.                 val.i_int = ( GET_Y_LPARAM(msg.lParam) - i_y ) *
  149.                     p_event->p_vout->fmt_in.i_visible_height / i_height +
  150.                     p_event->p_vout->fmt_in.i_y_offset;
  151.                 var_Set( p_event->p_vout, "mouse-y", val );
  152.                 var_SetBool( p_event->p_vout, "mouse-moved", true );
  153.             }
  154.         case WM_NCMOUSEMOVE:
  155.             GetCursorPos( &mouse_pos );
  156.             if( (abs(mouse_pos.x - old_mouse_pos.x) > 2 ||
  157.                 (abs(mouse_pos.y - old_mouse_pos.y)) > 2 ) )
  158.             {
  159.                 GetCursorPos( &old_mouse_pos );
  160.                 p_event->p_vout->p_sys->i_lastmoved = mdate();
  161.                 if( p_event->p_vout->p_sys->b_cursor_hidden )
  162.                 {
  163.                     p_event->p_vout->p_sys->b_cursor_hidden = 0;
  164.                     ShowCursor( TRUE );
  165.                 }
  166.             }
  167.             break;
  168.         case WM_VLC_HIDE_MOUSE:
  169.             if( p_event->p_vout->p_sys->b_cursor_hidden ) break;
  170.             p_event->p_vout->p_sys->b_cursor_hidden = true;
  171.             GetCursorPos( &old_mouse_pos );
  172.             ShowCursor( FALSE );
  173.             break;
  174.         case WM_VLC_SHOW_MOUSE:
  175.             if( !p_event->p_vout->p_sys->b_cursor_hidden ) break;
  176.             p_event->p_vout->p_sys->b_cursor_hidden = false;
  177.             GetCursorPos( &old_mouse_pos );
  178.             ShowCursor( TRUE );
  179.             break;
  180.         case WM_LBUTTONDOWN:
  181.             var_Get( p_event->p_vout, "mouse-button-down", &val );
  182.             val.i_int |= 1;
  183.             var_Set( p_event->p_vout, "mouse-button-down", val );
  184.             DirectXPopupMenu( p_event, false );
  185.             break;
  186.         case WM_LBUTTONUP:
  187.             var_Get( p_event->p_vout, "mouse-button-down", &val );
  188.             val.i_int &= ~1;
  189.             var_Set( p_event->p_vout, "mouse-button-down", val );
  190.             var_SetBool( p_event->p_vout, "mouse-clicked", true );
  191.             break;
  192.         case WM_LBUTTONDBLCLK:
  193.             p_event->p_vout->p_sys->i_changes |= VOUT_FULLSCREEN_CHANGE;
  194.             break;
  195.         case WM_MBUTTONDOWN:
  196.             var_Get( p_event->p_vout, "mouse-button-down", &val );
  197.             val.i_int |= 2;
  198.             var_Set( p_event->p_vout, "mouse-button-down", val );
  199.             DirectXPopupMenu( p_event, false );
  200.             break;
  201.         case WM_MBUTTONUP:
  202.             var_Get( p_event->p_vout, "mouse-button-down", &val );
  203.             val.i_int &= ~2;
  204.             var_Set( p_event->p_vout, "mouse-button-down", val );
  205.             break;
  206.         case WM_RBUTTONDOWN:
  207.             var_Get( p_event->p_vout, "mouse-button-down", &val );
  208.             val.i_int |= 4;
  209.             var_Set( p_event->p_vout, "mouse-button-down", val );
  210.             DirectXPopupMenu( p_event, false );
  211.             break;
  212.         case WM_RBUTTONUP:
  213.             var_Get( p_event->p_vout, "mouse-button-down", &val );
  214.             val.i_int &= ~4;
  215.             var_Set( p_event->p_vout, "mouse-button-down", val );
  216.             DirectXPopupMenu( p_event, true );
  217.             break;
  218.         case WM_KEYDOWN:
  219.         case WM_SYSKEYDOWN:
  220.             /* The key events are first processed here and not translated
  221.              * into WM_CHAR events because we need to know the status of the
  222.              * modifier keys. */
  223.             val.i_int = DirectXConvertKey( msg.wParam );
  224.             if( !val.i_int )
  225.             {
  226.                 /* This appears to be a "normal" (ascii) key */
  227.                 val.i_int = tolower( MapVirtualKey( msg.wParam, 2 ) );
  228.             }
  229.             if( val.i_int )
  230.             {
  231.                 if( GetKeyState(VK_CONTROL) & 0x8000 )
  232.                 {
  233.                     val.i_int |= KEY_MODIFIER_CTRL;
  234.                 }
  235.                 if( GetKeyState(VK_SHIFT) & 0x8000 )
  236.                 {
  237.                     val.i_int |= KEY_MODIFIER_SHIFT;
  238.                 }
  239.                 if( GetKeyState(VK_MENU) & 0x8000 )
  240.                 {
  241.                     val.i_int |= KEY_MODIFIER_ALT;
  242.                 }
  243.                 var_Set( p_event->p_libvlc, "key-pressed", val );
  244.             }
  245.             break;
  246.         case WM_MOUSEWHEEL:
  247.             if( GET_WHEEL_DELTA_WPARAM( msg.wParam ) > 0 )
  248.             {
  249.                 val.i_int = KEY_MOUSEWHEELUP;
  250.             }
  251.             else
  252.             {
  253.                 val.i_int = KEY_MOUSEWHEELDOWN;
  254.             }
  255.             if( val.i_int )
  256.             {
  257.                 if( GetKeyState(VK_CONTROL) & 0x8000 )
  258.                 {
  259.                     val.i_int |= KEY_MODIFIER_CTRL;
  260.                 }
  261.                 if( GetKeyState(VK_SHIFT) & 0x8000 )
  262.                 {
  263.                     val.i_int |= KEY_MODIFIER_SHIFT;
  264.                 }
  265.                 if( GetKeyState(VK_MENU) & 0x8000 )
  266.                 {
  267.                     val.i_int |= KEY_MODIFIER_ALT;
  268.                 }
  269.                 var_Set( p_event->p_libvlc, "key-pressed", val );
  270.             }
  271.             break;
  272.         case WM_VLC_CHANGE_TEXT:
  273.             var_Get( p_event->p_vout, "video-title", &val );
  274.             if( !val.psz_string || !*val.psz_string ) /* Default video title */
  275.             {
  276.                 free( val.psz_string );
  277. #ifdef MODULE_NAME_IS_wingdi
  278.                 val.psz_string = strdup( VOUT_TITLE " (WinGDI output)" );
  279. #endif
  280. #ifdef MODULE_NAME_IS_wingapi
  281.                 val.psz_string = strdup( VOUT_TITLE " (WinGAPI output)" );
  282. #endif
  283. #ifdef MODULE_NAME_IS_glwin32
  284.                 val.psz_string = strdup( VOUT_TITLE " (OpenGL output)" );
  285. #endif
  286. #ifdef MODULE_NAME_IS_direct3d
  287.                 val.psz_string = strdup( VOUT_TITLE " (Direct3D output)" );
  288. #endif
  289. #ifdef MODULE_NAME_IS_vout_directx
  290.                 if( p_event->p_vout->p_sys->b_using_overlay ) val.psz_string =
  291.                     strdup( VOUT_TITLE " (hardware YUV overlay DirectX output)" );
  292.                 else if( p_event->p_vout->p_sys->b_hw_yuv ) val.psz_string =
  293.                     strdup( VOUT_TITLE " (hardware YUV DirectX output)" );
  294.                 else val.psz_string =
  295.                     strdup( VOUT_TITLE " (software RGB DirectX output)" );
  296. #endif
  297.             }
  298. #ifdef UNICODE
  299.             {
  300.                 wchar_t *psz_title = malloc( strlen(val.psz_string) * 2 + 2 );
  301.                 if( psz_title )
  302.                 {
  303.                     mbstowcs( psz_title, val.psz_string, strlen(val.psz_string)*2);
  304.                     psz_title[strlen(val.psz_string)] = 0;
  305.                     free( val.psz_string ); val.psz_string = (char *)psz_title;
  306.                 }
  307.             }
  308. #endif
  309.             SetWindowText( p_event->p_vout->p_sys->hwnd,
  310.                            (LPCTSTR)val.psz_string );
  311.             if( p_event->p_vout->p_sys->hfswnd )
  312.                 SetWindowText( p_event->p_vout->p_sys->hfswnd,
  313.                                (LPCTSTR)val.psz_string );
  314.             free( val.psz_string );
  315.             break;
  316.         default:
  317.             /* Messages we don't handle directly are dispatched to the
  318.              * window procedure */
  319.             TranslateMessage(&msg);
  320.             DispatchMessage(&msg);
  321.             break;
  322.         } /* End Switch */
  323.     } /* End Main loop */
  324.     /* Check for WM_QUIT if we created the window */
  325.     if( !p_event->p_vout->p_sys->hparent && msg.message == WM_QUIT )
  326.     {
  327.         msg_Warn( p_event, "WM_QUIT... should not happen!!" );
  328.         p_event->p_vout->p_sys->hwnd = NULL; /* Window already destroyed */
  329.     }
  330.     msg_Dbg( p_event, "DirectXEventThread terminating" );
  331.     /* clear the changes formerly signaled */
  332.     p_event->p_vout->p_sys->i_changes = 0;
  333.     DirectXCloseWindow( p_event->p_vout );
  334.     vlc_restorecancel (canc);
  335.     return NULL;
  336. }
  337. /* following functions are local */
  338. /*****************************************************************************
  339.  * DirectXCreateWindow: create a window for the video.
  340.  *****************************************************************************
  341.  * Before creating a direct draw surface, we need to create a window in which
  342.  * the video will be displayed. This window will also allow us to capture the
  343.  * events.
  344.  *****************************************************************************/
  345. static int DirectXCreateWindow( vout_thread_t *p_vout )
  346. {
  347.     HINSTANCE  hInstance;
  348.     HMENU      hMenu;
  349.     RECT       rect_window;
  350.     WNDCLASS   wc;                            /* window class components */
  351.     HICON      vlc_icon = NULL;
  352.     char       vlc_path[MAX_PATH+1];
  353.     int        i_style, i_stylex;
  354.     msg_Dbg( p_vout, "DirectXCreateWindow" );
  355.     /* Get this module's instance */
  356.     hInstance = GetModuleHandle(NULL);
  357.     /* If an external window was specified, we'll draw in it. */
  358.     p_vout->p_sys->parent_window =
  359.         vout_RequestHWND( p_vout, &p_vout->p_sys->i_window_x,
  360.                             &p_vout->p_sys->i_window_y,
  361.                             &p_vout->p_sys->i_window_width,
  362.                             &p_vout->p_sys->i_window_height );
  363.     if( p_vout->p_sys->parent_window )
  364.         p_vout->p_sys->hparent = p_vout->p_sys->parent_window->handle.hwnd;
  365.     /* We create the window ourself, there is no previous window proc. */
  366.     p_vout->p_sys->pf_wndproc = NULL;
  367.     /* Get the Icon from the main app */
  368.     vlc_icon = NULL;
  369. #ifndef UNDER_CE
  370.     if( GetModuleFileName( NULL, vlc_path, MAX_PATH ) )
  371.     {
  372.         vlc_icon = ExtractIcon( hInstance, vlc_path, 0 );
  373.     }
  374. #endif
  375.     /* Fill in the window class structure */
  376.     wc.style         = CS_OWNDC|CS_DBLCLKS;          /* style: dbl click */
  377.     wc.lpfnWndProc   = (WNDPROC)DirectXEventProc;       /* event handler */
  378.     wc.cbClsExtra    = 0;                         /* no extra class data */
  379.     wc.cbWndExtra    = 0;                        /* no extra window data */
  380.     wc.hInstance     = hInstance;                            /* instance */
  381.     wc.hIcon         = vlc_icon;                /* load the vlc big icon */
  382.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);    /* default cursor */
  383.     wc.hbrBackground = GetStockObject(BLACK_BRUSH);  /* background color */
  384.     wc.lpszMenuName  = NULL;                                  /* no menu */
  385.     wc.lpszClassName = _T("VLC DirectX");         /* use a special class */
  386.     /* Register the window class */
  387.     if( !RegisterClass(&wc) )
  388.     {
  389.         WNDCLASS wndclass;
  390.         if( vlc_icon ) DestroyIcon( vlc_icon );
  391.         /* Check why it failed. If it's because one already exists
  392.          * then fine, otherwise return with an error. */
  393.         if( !GetClassInfo( hInstance, _T("VLC DirectX"), &wndclass ) )
  394.         {
  395.             msg_Err( p_vout, "DirectXCreateWindow RegisterClass FAILED (err=%lu)", GetLastError() );
  396.             return VLC_EGENERIC;
  397.         }
  398.     }
  399.     /* Register the video sub-window class */
  400.     wc.lpszClassName = _T("VLC DirectX video"); wc.hIcon = 0;
  401.     wc.hbrBackground = NULL; /* no background color */
  402.     if( !RegisterClass(&wc) )
  403.     {
  404.         WNDCLASS wndclass;
  405.         /* Check why it failed. If it's because one already exists
  406.          * then fine, otherwise return with an error. */
  407.         if( !GetClassInfo( hInstance, _T("VLC DirectX video"), &wndclass ) )
  408.         {
  409.             msg_Err( p_vout, "DirectXCreateWindow RegisterClass FAILED (err=%lu)", GetLastError() );
  410.             return VLC_EGENERIC;
  411.         }
  412.     }
  413.     /* When you create a window you give the dimensions you wish it to
  414.      * have. Unfortunatly these dimensions will include the borders and
  415.      * titlebar. We use the following function to find out the size of
  416.      * the window corresponding to the useable surface we want */
  417.     rect_window.top    = 10;
  418.     rect_window.left   = 10;
  419.     rect_window.right  = rect_window.left + p_vout->p_sys->i_window_width;
  420.     rect_window.bottom = rect_window.top + p_vout->p_sys->i_window_height;
  421.     if( var_GetBool( p_vout, "video-deco" ) )
  422.     {
  423.         /* Open with window decoration */
  424.         AdjustWindowRect( &rect_window, WS_OVERLAPPEDWINDOW|WS_SIZEBOX, 0 );
  425.         i_style = WS_OVERLAPPEDWINDOW|WS_SIZEBOX|WS_VISIBLE|WS_CLIPCHILDREN;
  426.         i_stylex = 0;
  427.     }
  428.     else
  429.     {
  430.         /* No window decoration */
  431.         AdjustWindowRect( &rect_window, WS_POPUP, 0 );
  432.         i_style = WS_POPUP|WS_VISIBLE|WS_CLIPCHILDREN;
  433.         i_stylex = 0; // WS_EX_TOOLWINDOW; Is TOOLWINDOW really needed ?
  434.                       // It messes up the fullscreen window.
  435.     }
  436.     if( p_vout->p_sys->hparent )
  437.     {
  438.         i_style = WS_VISIBLE|WS_CLIPCHILDREN|WS_CHILD;
  439.         i_stylex = 0;
  440.     }
  441.     p_vout->p_sys->i_window_style = i_style;
  442.     /* Create the window */
  443.     p_vout->p_sys->hwnd =
  444.         CreateWindowEx( WS_EX_NOPARENTNOTIFY | i_stylex,
  445.                     _T("VLC DirectX"),               /* name of window class */
  446.                     _T(VOUT_TITLE) _T(" (DirectX Output)"),  /* window title */
  447.                     i_style,                                 /* window style */
  448.                     (p_vout->p_sys->i_window_x < 0) ? CW_USEDEFAULT :
  449.                         (UINT)p_vout->p_sys->i_window_x,   /* default X coordinate */
  450.                     (p_vout->p_sys->i_window_y < 0) ? CW_USEDEFAULT :
  451.                         (UINT)p_vout->p_sys->i_window_y,   /* default Y coordinate */
  452.                     rect_window.right - rect_window.left,    /* window width */
  453.                     rect_window.bottom - rect_window.top,   /* window height */
  454.                     p_vout->p_sys->hparent,                 /* parent window */
  455.                     NULL,                          /* no menu in this window */
  456.                     hInstance,            /* handle of this program instance */
  457.                     (LPVOID)p_vout );            /* send p_vout to WM_CREATE */
  458.     if( !p_vout->p_sys->hwnd )
  459.     {
  460.         msg_Warn( p_vout, "DirectXCreateWindow create window FAILED (err=%lu)", GetLastError() );
  461.         return VLC_EGENERIC;
  462.     }
  463.     if( p_vout->p_sys->hparent )
  464.     {
  465.         LONG i_style;
  466.         /* We don't want the window owner to overwrite our client area */
  467.         i_style = GetWindowLong( p_vout->p_sys->hparent, GWL_STYLE );
  468.         if( !(i_style & WS_CLIPCHILDREN) )
  469.             /* Hmmm, apparently this is a blocking call... */
  470.             SetWindowLong( p_vout->p_sys->hparent, GWL_STYLE,
  471.                            i_style | WS_CLIPCHILDREN );
  472.         /* Create our fullscreen window */
  473.         p_vout->p_sys->hfswnd =
  474.             CreateWindowEx( WS_EX_APPWINDOW, _T("VLC DirectX"),
  475.                             _T(VOUT_TITLE) _T(" (DirectX Output)"),
  476.                             WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN|WS_SIZEBOX,
  477.                             CW_USEDEFAULT, CW_USEDEFAULT,
  478.                             CW_USEDEFAULT, CW_USEDEFAULT,
  479.                             NULL, NULL, hInstance, NULL );
  480.     }
  481.     /* Append a "Always On Top" entry in the system menu */
  482.     hMenu = GetSystemMenu( p_vout->p_sys->hwnd, FALSE );
  483.     AppendMenu( hMenu, MF_SEPARATOR, 0, _T("") );
  484.     AppendMenu( hMenu, MF_STRING | MF_UNCHECKED,
  485.                        IDM_TOGGLE_ON_TOP, _T("Always on &Top") );
  486.     /* Create video sub-window. This sub window will always exactly match
  487.      * the size of the video, which allows us to use crazy overlay colorkeys
  488.      * without having them shown outside of the video area. */
  489.     p_vout->p_sys->hvideownd =
  490.     CreateWindow( _T("VLC DirectX video"), _T(""),   /* window class */
  491.         WS_CHILD,                   /* window style, not visible initially */
  492.         0, 0,
  493.         p_vout->render.i_width,         /* default width */
  494.         p_vout->render.i_height,        /* default height */
  495.         p_vout->p_sys->hwnd,                    /* parent window */
  496.         NULL, hInstance,
  497.         (LPVOID)p_vout );            /* send p_vout to WM_CREATE */
  498.     if( !p_vout->p_sys->hvideownd )
  499.         msg_Warn( p_vout, "can't create video sub-window" );
  500.     else
  501.         msg_Dbg( p_vout, "created video sub-window" );
  502.     /* Now display the window */
  503.     ShowWindow( p_vout->p_sys->hwnd, SW_SHOW );
  504.     return VLC_SUCCESS;
  505. }
  506. /*****************************************************************************
  507.  * DirectXCloseWindow: close the window created by DirectXCreateWindow
  508.  *****************************************************************************
  509.  * This function returns all resources allocated by DirectXCreateWindow.
  510.  *****************************************************************************/
  511. static void DirectXCloseWindow( vout_thread_t *p_vout )
  512. {
  513.     msg_Dbg( p_vout, "DirectXCloseWindow" );
  514.     DestroyWindow( p_vout->p_sys->hwnd );
  515.     if( p_vout->p_sys->hfswnd ) DestroyWindow( p_vout->p_sys->hfswnd );
  516.     vout_ReleaseWindow( p_vout->p_sys->parent_window );
  517.     p_vout->p_sys->hwnd = NULL;
  518.     /* We don't unregister the Window Class because it could lead to race
  519.      * conditions and it will be done anyway by the system when the app will
  520.      * exit */
  521. }
  522. /*****************************************************************************
  523.  * UpdateRects: update clipping rectangles
  524.  *****************************************************************************
  525.  * This function is called when the window position or size are changed, and
  526.  * its job is to update the source and destination RECTs used to display the
  527.  * picture.
  528.  *****************************************************************************/
  529. void UpdateRects( vout_thread_t *p_vout, bool b_force )
  530. {
  531. #define rect_src p_vout->p_sys->rect_src
  532. #define rect_src_clipped p_vout->p_sys->rect_src_clipped
  533. #define rect_dest p_vout->p_sys->rect_dest
  534. #define rect_dest_clipped p_vout->p_sys->rect_dest_clipped
  535.     int i_width, i_height, i_x, i_y;
  536.     RECT  rect;
  537.     POINT point;
  538.     /* Retrieve the window size */
  539.     GetClientRect( p_vout->p_sys->hwnd, &rect );
  540.     /* Retrieve the window position */
  541.     point.x = point.y = 0;
  542.     ClientToScreen( p_vout->p_sys->hwnd, &point );
  543.     /* If nothing changed, we can return */
  544.     if( !b_force
  545.          && p_vout->p_sys->i_window_width == rect.right
  546.          && p_vout->p_sys->i_window_height == rect.bottom
  547.          && p_vout->p_sys->i_window_x == point.x
  548.          && p_vout->p_sys->i_window_y == point.y )
  549.     {
  550.         return;
  551.     }
  552.     /* Update the window position and size */
  553.     p_vout->p_sys->i_window_x = point.x;
  554.     p_vout->p_sys->i_window_y = point.y;
  555.     p_vout->p_sys->i_window_width = rect.right;
  556.     p_vout->p_sys->i_window_height = rect.bottom;
  557.     vout_PlacePicture( p_vout, rect.right, rect.bottom,
  558.                        &i_x, &i_y, &i_width, &i_height );
  559.     if( p_vout->p_sys->hvideownd )
  560.         SetWindowPos( p_vout->p_sys->hvideownd, 0,
  561.                       i_x, i_y, i_width, i_height,
  562.                       SWP_NOCOPYBITS|SWP_NOZORDER|SWP_ASYNCWINDOWPOS );
  563.     /* Destination image position and dimensions */
  564. #if defined(MODULE_NAME_IS_direct3d)
  565.     rect_dest.left   = 0;
  566.     rect_dest.right  = i_width;
  567.     rect_dest.top    = 0;
  568.     rect_dest.bottom = i_height;
  569. #else
  570.     rect_dest.left = point.x + i_x;
  571.     rect_dest.right = rect_dest.left + i_width;
  572.     rect_dest.top = point.y + i_y;
  573.     rect_dest.bottom = rect_dest.top + i_height;
  574. #ifdef MODULE_NAME_IS_vout_directx
  575.     /* Apply overlay hardware constraints */
  576.     if( p_vout->p_sys->b_using_overlay )
  577.     {
  578.         if( p_vout->p_sys->i_align_dest_boundary )
  579.             rect_dest.left = ( rect_dest.left +
  580.                 p_vout->p_sys->i_align_dest_boundary / 2 ) &
  581.                 ~p_vout->p_sys->i_align_dest_boundary;
  582.         if( p_vout->p_sys->i_align_dest_size )
  583.             rect_dest.right = (( rect_dest.right - rect_dest.left +
  584.                 p_vout->p_sys->i_align_dest_size / 2 ) &
  585.                 ~p_vout->p_sys->i_align_dest_size) + rect_dest.left;
  586.     }
  587. #endif
  588. #endif
  589. #if defined(MODULE_NAME_IS_directx) || defined(MODULE_NAME_IS_direct3d)
  590.     /* UpdateOverlay directdraw function doesn't automatically clip to the
  591.      * display size so we need to do it otherwise it will fail
  592.      * It is also needed for d3d to avoid exceding our surface size */
  593.     /* Clip the destination window */
  594.     if( !IntersectRect( &rect_dest_clipped, &rect_dest,
  595.                         &p_vout->p_sys->rect_display ) )
  596.     {
  597.         SetRectEmpty( &rect_src_clipped );
  598.         return;
  599.     }
  600. #if 0
  601.     msg_Dbg( p_vout, "DirectXUpdateRects image_dst_clipped coords:"
  602.                      " %i,%i,%i,%i",
  603.                      rect_dest_clipped.left, rect_dest_clipped.top,
  604.                      rect_dest_clipped.right, rect_dest_clipped.bottom );
  605. #endif
  606. #else
  607.     /* AFAIK, there are no clipping constraints in Direct3D, OpenGL and GDI */
  608.     rect_dest_clipped = rect_dest;
  609. #endif
  610.     /* the 2 following lines are to fix a bug when clicking on the desktop */
  611.     if( (rect_dest_clipped.right - rect_dest_clipped.left)==0 ||
  612.         (rect_dest_clipped.bottom - rect_dest_clipped.top)==0 )
  613.     {
  614.         SetRectEmpty( &rect_src_clipped );
  615.         return;
  616.     }
  617.     /* src image dimensions */
  618.     rect_src.left = 0;
  619.     rect_src.top = 0;
  620.     rect_src.right = p_vout->render.i_width;
  621.     rect_src.bottom = p_vout->render.i_height;
  622.     /* Clip the source image */
  623.     rect_src_clipped.left = p_vout->fmt_out.i_x_offset +
  624.       (rect_dest_clipped.left - rect_dest.left) *
  625.       p_vout->fmt_out.i_visible_width / (rect_dest.right - rect_dest.left);
  626.     rect_src_clipped.right = p_vout->fmt_out.i_x_offset +
  627.       p_vout->fmt_out.i_visible_width -
  628.       (rect_dest.right - rect_dest_clipped.right) *
  629.       p_vout->fmt_out.i_visible_width / (rect_dest.right - rect_dest.left);
  630.     rect_src_clipped.top = p_vout->fmt_out.i_y_offset +
  631.       (rect_dest_clipped.top - rect_dest.top) *
  632.       p_vout->fmt_out.i_visible_height / (rect_dest.bottom - rect_dest.top);
  633.     rect_src_clipped.bottom = p_vout->fmt_out.i_y_offset +
  634.       p_vout->fmt_out.i_visible_height -
  635.       (rect_dest.bottom - rect_dest_clipped.bottom) *
  636.       p_vout->fmt_out.i_visible_height / (rect_dest.bottom - rect_dest.top);
  637. #ifdef MODULE_NAME_IS_vout_directx
  638.     /* Apply overlay hardware constraints */
  639.     if( p_vout->p_sys->b_using_overlay )
  640.     {
  641.         if( p_vout->p_sys->i_align_src_boundary )
  642.             rect_src_clipped.left = ( rect_src_clipped.left +
  643.                 p_vout->p_sys->i_align_src_boundary / 2 ) &
  644.                 ~p_vout->p_sys->i_align_src_boundary;
  645.         if( p_vout->p_sys->i_align_src_size )
  646.             rect_src_clipped.right = (( rect_src_clipped.right -
  647.                 rect_src_clipped.left +
  648.                 p_vout->p_sys->i_align_src_size / 2 ) &
  649.                 ~p_vout->p_sys->i_align_src_size) + rect_src_clipped.left;
  650.     }
  651. #elif defined(MODULE_NAME_IS_direct3d)
  652.     /* Needed at least with YUV content */
  653.     rect_src_clipped.left &= ~1;
  654.     rect_src_clipped.right &= ~1;
  655.     rect_src_clipped.top &= ~1;
  656.     rect_src_clipped.bottom &= ~1;
  657. #endif
  658. #if 0
  659.     msg_Dbg( p_vout, "DirectXUpdateRects image_src_clipped"
  660.                      " coords: %i,%i,%i,%i",
  661.                      rect_src_clipped.left, rect_src_clipped.top,
  662.                      rect_src_clipped.right, rect_src_clipped.bottom );
  663. #endif
  664. #ifdef MODULE_NAME_IS_vout_directx
  665.     /* The destination coordinates need to be relative to the current
  666.      * directdraw primary surface (display) */
  667.     rect_dest_clipped.left -= p_vout->p_sys->rect_display.left;
  668.     rect_dest_clipped.right -= p_vout->p_sys->rect_display.left;
  669.     rect_dest_clipped.top -= p_vout->p_sys->rect_display.top;
  670.     rect_dest_clipped.bottom -= p_vout->p_sys->rect_display.top;
  671.     if( p_vout->p_sys->b_using_overlay )
  672.         DirectDrawUpdateOverlay( p_vout );
  673. #endif
  674.     /* Signal the change in size/position */
  675.     p_vout->p_sys->i_changes |= DX_POSITION_CHANGE;
  676. #undef rect_src
  677. #undef rect_src_clipped
  678. #undef rect_dest
  679. #undef rect_dest_clipped
  680. }
  681. /*****************************************************************************
  682.  * DirectXEventProc: This is the window event processing function.
  683.  *****************************************************************************
  684.  * On Windows, when you create a window you have to attach an event processing
  685.  * function to it. The aim of this function is to manage "Queued Messages" and
  686.  * "Nonqueued Messages".
  687.  * Queued Messages are those picked up and retransmitted by vout_Manage
  688.  * (using the GetMessage and DispatchMessage functions).
  689.  * Nonqueued Messages are those that Windows will send directly to this
  690.  * procedure (like WM_DESTROY, WM_WINDOWPOSCHANGED...)
  691.  *****************************************************************************/
  692. static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message,
  693.                                          WPARAM wParam, LPARAM lParam )
  694. {
  695.     vout_thread_t *p_vout;
  696.     if( message == WM_CREATE )
  697.     {
  698.         /* Store p_vout for future use */
  699.         p_vout = (vout_thread_t *)((CREATESTRUCT *)lParam)->lpCreateParams;
  700.         SetWindowLongPtr( hwnd, GWLP_USERDATA, (LONG_PTR)p_vout );
  701.         return TRUE;
  702.     }
  703.     else
  704.     {
  705.         p_vout = (vout_thread_t *)GetWindowLongPtr( hwnd, GWLP_USERDATA );
  706.         if( !p_vout )
  707.         {
  708.             /* Hmmm mozilla does manage somehow to save the pointer to our
  709.              * windowproc and still calls it after the vout has been closed. */
  710.             return DefWindowProc(hwnd, message, wParam, lParam);
  711.         }
  712.     }
  713. #ifndef UNDER_CE
  714.     /* Catch the screensaver and the monitor turn-off */
  715.     if( message == WM_SYSCOMMAND &&
  716.         ( (wParam & 0xFFF0) == SC_SCREENSAVE || (wParam & 0xFFF0) == SC_MONITORPOWER ) )
  717.     {
  718.         //if( p_vout ) msg_Dbg( p_vout, "WinProc WM_SYSCOMMAND screensaver" );
  719.         return 0; /* this stops them from happening */
  720.     }
  721. #endif
  722.     if( hwnd == p_vout->p_sys->hvideownd )
  723.     {
  724.         switch( message )
  725.         {
  726. #ifdef MODULE_NAME_IS_vout_directx
  727.         case WM_ERASEBKGND:
  728.         /* For overlay, we need to erase background */
  729.             return !p_vout->p_sys->b_using_overlay ?
  730.                 1 : DefWindowProc(hwnd, message, wParam, lParam);
  731.         case WM_PAINT:
  732.         /*
  733.         ** For overlay, DefWindowProc() will erase dirty regions
  734.         ** with colorkey.
  735.         ** For non-overlay, vout will paint the whole window at
  736.         ** regular interval, therefore dirty regions can be ignored
  737.         ** to minimize repaint.
  738.         */
  739.             if( !p_vout->p_sys->b_using_overlay )
  740.             {
  741.                 ValidateRect(hwnd, NULL);
  742.             }
  743.             // fall through to default
  744. #else
  745.         /*
  746.         ** For OpenGL and Direct3D, vout will update the whole
  747.         ** window at regular interval, therefore dirty region
  748.         ** can be ignored to minimize repaint.
  749.         */
  750.         case WM_ERASEBKGND:
  751.             /* nothing to erase */
  752.             return 1;
  753.         case WM_PAINT:
  754.             /* nothing to repaint */
  755.             ValidateRect(hwnd, NULL);
  756.             // fall through
  757. #endif
  758.         default:
  759.             return DefWindowProc(hwnd, message, wParam, lParam);
  760.         }
  761.     }
  762.     switch( message )
  763.     {
  764.     case WM_WINDOWPOSCHANGED:
  765.         UpdateRects( p_vout, true );
  766.         return 0;
  767.     /* the user wants to close the window */
  768.     case WM_CLOSE:
  769.     {
  770.         playlist_t * p_playlist = pl_Hold( p_vout );
  771.         if( p_playlist )
  772.         {
  773.             playlist_Stop( p_playlist );
  774.             pl_Release( p_vout );
  775.         }
  776.         return 0;
  777.     }
  778.     /* the window has been closed so shut down everything now */
  779.     case WM_DESTROY:
  780.         msg_Dbg( p_vout, "WinProc WM_DESTROY" );
  781.         /* just destroy the window */
  782.         PostQuitMessage( 0 );
  783.         return 0;
  784.     case WM_SYSCOMMAND:
  785.         switch (wParam)
  786.         {
  787.             case IDM_TOGGLE_ON_TOP:            /* toggle the "on top" status */
  788.             {
  789.                 vlc_value_t val;
  790.                 msg_Dbg( p_vout, "WinProc WM_SYSCOMMAND: IDM_TOGGLE_ON_TOP");
  791.                 /* Change the current value */
  792.                 var_Get( p_vout, "video-on-top", &val );
  793.                 val.b_bool = !val.b_bool;
  794.                 var_Set( p_vout, "video-on-top", val );
  795.                 return 0;
  796.             }
  797.         }
  798.         break;
  799.     case WM_PAINT:
  800.     case WM_NCPAINT:
  801.     case WM_ERASEBKGND:
  802.         return DefWindowProc(hwnd, message, wParam, lParam);
  803.     case WM_KILLFOCUS:
  804. #ifdef MODULE_NAME_IS_wingapi
  805.         p_vout->p_sys->b_focus = false;
  806.         if( !p_vout->p_sys->b_parent_focus ) GXSuspend();
  807. #endif
  808. #ifdef UNDER_CE
  809.         if( hwnd == p_vout->p_sys->hfswnd )
  810.         {
  811.             HWND htbar = FindWindow( _T("HHTaskbar"), NULL );
  812.             ShowWindow( htbar, SW_SHOW );
  813.         }
  814.         if( !p_vout->p_sys->hparent ||
  815.             hwnd == p_vout->p_sys->hfswnd )
  816.         {
  817.             SHFullScreen( hwnd, SHFS_SHOWSIPBUTTON );
  818.         }
  819. #endif
  820.         return 0;
  821.     case WM_SETFOCUS:
  822. #ifdef MODULE_NAME_IS_wingapi
  823.         p_vout->p_sys->b_focus = true;
  824.         GXResume();
  825. #endif
  826. #ifdef UNDER_CE
  827.         if( p_vout->p_sys->hparent &&
  828.             hwnd != p_vout->p_sys->hfswnd && p_vout->b_fullscreen )
  829.             p_vout->p_sys->i_changes |= VOUT_FULLSCREEN_CHANGE;
  830.         if( hwnd == p_vout->p_sys->hfswnd )
  831.         {
  832.             HWND htbar = FindWindow( _T("HHTaskbar"), NULL );
  833.             ShowWindow( htbar, SW_HIDE );
  834.         }
  835.         if( !p_vout->p_sys->hparent ||
  836.             hwnd == p_vout->p_sys->hfswnd )
  837.         {
  838.             SHFullScreen( hwnd, SHFS_HIDESIPBUTTON );
  839.         }
  840. #endif
  841.         return 0;
  842.     default:
  843.         //msg_Dbg( p_vout, "WinProc WM Default %i", message );
  844.         break;
  845.     }
  846.     /* Let windows handle the message */
  847.     return DefWindowProc(hwnd, message, wParam, lParam);
  848. }
  849. static struct
  850. {
  851.     int i_dxkey;
  852.     int i_vlckey;
  853. } dxkeys_to_vlckeys[] =
  854. {
  855.     { VK_F1, KEY_F1 }, { VK_F2, KEY_F2 }, { VK_F3, KEY_F3 }, { VK_F4, KEY_F4 },
  856.     { VK_F5, KEY_F5 }, { VK_F6, KEY_F6 }, { VK_F7, KEY_F7 }, { VK_F8, KEY_F8 },
  857.     { VK_F9, KEY_F9 }, { VK_F10, KEY_F10 }, { VK_F11, KEY_F11 },
  858.     { VK_F12, KEY_F12 },
  859.     { VK_RETURN, KEY_ENTER },
  860.     { VK_SPACE, KEY_SPACE },
  861.     { VK_ESCAPE, KEY_ESC },
  862.     { VK_LEFT, KEY_LEFT },
  863.     { VK_RIGHT, KEY_RIGHT },
  864.     { VK_UP, KEY_UP },
  865.     { VK_DOWN, KEY_DOWN },
  866.     { VK_HOME, KEY_HOME },
  867.     { VK_END, KEY_END },
  868.     { VK_PRIOR, KEY_PAGEUP },
  869.     { VK_NEXT, KEY_PAGEDOWN },
  870.     { VK_INSERT, KEY_INSERT },
  871.     { VK_DELETE, KEY_DELETE },
  872.     { VK_CONTROL, 0 },
  873.     { VK_SHIFT, 0 },
  874.     { VK_MENU, 0 },
  875.     { VK_BROWSER_BACK, KEY_BROWSER_BACK },
  876.     { VK_BROWSER_FORWARD, KEY_BROWSER_FORWARD },
  877.     { VK_BROWSER_REFRESH, KEY_BROWSER_REFRESH },
  878.     { VK_BROWSER_STOP, KEY_BROWSER_STOP },
  879.     { VK_BROWSER_SEARCH, KEY_BROWSER_SEARCH },
  880.     { VK_BROWSER_FAVORITES, KEY_BROWSER_FAVORITES },
  881.     { VK_BROWSER_HOME, KEY_BROWSER_HOME },
  882.     { VK_VOLUME_MUTE, KEY_VOLUME_MUTE },
  883.     { VK_VOLUME_DOWN, KEY_VOLUME_DOWN },
  884.     { VK_VOLUME_UP, KEY_VOLUME_UP },
  885.     { VK_MEDIA_NEXT_TRACK, KEY_MEDIA_NEXT_TRACK },
  886.     { VK_MEDIA_PREV_TRACK, KEY_MEDIA_PREV_TRACK },
  887.     { VK_MEDIA_STOP, KEY_MEDIA_STOP },
  888.     { VK_MEDIA_PLAY_PAUSE, KEY_MEDIA_PLAY_PAUSE },
  889.     { 0, 0 }
  890. };
  891. static int DirectXConvertKey( int i_key )
  892. {
  893.     int i;
  894.     for( i = 0; dxkeys_to_vlckeys[i].i_dxkey != 0; i++ )
  895.     {
  896.         if( dxkeys_to_vlckeys[i].i_dxkey == i_key )
  897.         {
  898.             return dxkeys_to_vlckeys[i].i_vlckey;
  899.         }
  900.     }
  901.     return 0;
  902. }
  903. /*****************************************************************************
  904.  * Control: control facility for the vout
  905.  *****************************************************************************/
  906. static int Control( vout_thread_t *p_vout, int i_query, va_list args )
  907. {
  908.     unsigned int *pi_width, *pi_height;
  909. bool b_bool;
  910.     RECT rect_window;
  911.     POINT point;
  912.     switch( i_query )
  913.     {
  914.     case VOUT_SET_SIZE:
  915.         if( p_vout->p_sys->parent_window )
  916.             return vaControlParentWindow( p_vout, i_query, args );
  917.         /* Update dimensions */
  918.         rect_window.top = rect_window.left = 0;
  919.         rect_window.right  = va_arg( args, unsigned int );
  920.         rect_window.bottom = va_arg( args, unsigned int );
  921.         if( !rect_window.right ) rect_window.right = p_vout->i_window_width;
  922.         if( !rect_window.bottom ) rect_window.bottom = p_vout->i_window_height;
  923.         AdjustWindowRect( &rect_window, p_vout->p_sys->i_window_style, 0 );
  924.         SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0,
  925.                       rect_window.right - rect_window.left,
  926.                       rect_window.bottom - rect_window.top, SWP_NOMOVE );
  927.         return VLC_SUCCESS;
  928.     case VOUT_SET_STAY_ON_TOP:
  929.         if( p_vout->p_sys->hparent && !var_GetBool( p_vout, "fullscreen" ) )
  930.             return vaControlParentWindow( p_vout, i_query, args );
  931.         p_vout->p_sys->b_on_top_change = true;
  932.         return VLC_SUCCESS;
  933.     default:
  934.         return VLC_EGENERIC;
  935.     }
  936. }
  937. /* Internal wrapper over GetWindowPlacement */
  938. static WINDOWPLACEMENT getWindowState(HWND hwnd)
  939. {
  940.     WINDOWPLACEMENT window_placement;
  941.     window_placement.length = sizeof(WINDOWPLACEMENT);
  942.     GetWindowPlacement( hwnd, &window_placement );
  943.     return window_placement;
  944. }
  945. /* Internal wrapper to call vout_ControlWindow for hparent */
  946. static int vaControlParentWindow( vout_thread_t *p_vout, int i_query,
  947.                                    va_list args )
  948. {
  949.     return vout_ControlWindow( p_vout->p_sys->parent_window, i_query, args );
  950. }
  951. static int ControlParentWindow( vout_thread_t *p_vout, int i_query, ... )
  952. {
  953.     va_list args;
  954.     int ret;
  955.     va_start( args, i_query );
  956.     ret = vaControlParentWindow( p_vout, i_query, args );
  957.     va_end( args );
  958.     return ret;
  959. }
  960. void Win32ToggleFullscreen( vout_thread_t *p_vout )
  961. {
  962.     HWND hwnd = (p_vout->p_sys->hparent && p_vout->p_sys->hfswnd) ?
  963.         p_vout->p_sys->hfswnd : p_vout->p_sys->hwnd;
  964.     /* Save the current windows placement/placement to restore
  965.        when fullscreen is over */
  966.     WINDOWPLACEMENT window_placement = getWindowState( hwnd );
  967.     p_vout->b_fullscreen = ! p_vout->b_fullscreen;
  968.     /* We want to go to Fullscreen */
  969.     if( p_vout->b_fullscreen )
  970.     {
  971.         msg_Dbg( p_vout, "entering fullscreen mode" );
  972.         /* Change window style, no borders and no title bar */
  973.         int i_style = WS_CLIPCHILDREN | WS_VISIBLE;
  974.         SetWindowLong( hwnd, GWL_STYLE, i_style );
  975.         if( p_vout->p_sys->hparent )
  976.         {
  977. #ifdef UNDER_CE
  978.             POINT point = {0,0};
  979.             RECT rect;
  980.             ClientToScreen( p_vout->p_sys->hwnd, &point );
  981.             GetClientRect( p_vout->p_sys->hwnd, &rect );
  982.             SetWindowPos( hwnd, 0, point.x, point.y,
  983.                           rect.right, rect.bottom,
  984.                           SWP_NOZORDER|SWP_FRAMECHANGED );
  985. #else
  986.             /* Retrieve current window position so fullscreen will happen
  987.             *on the right screen */
  988.             HMONITOR hmon = MonitorFromWindow(p_vout->p_sys->hparent,
  989.                                             MONITOR_DEFAULTTONEAREST);
  990.             MONITORINFO mi = {sizeof(mi)};
  991.             if (GetMonitorInfo(hmon, &mi))
  992.             SetWindowPos( hwnd, 0,
  993.                             mi.rcMonitor.left,
  994.                             mi.rcMonitor.top,
  995.                             mi.rcMonitor.right - mi.rcMonitor.left,
  996.                             mi.rcMonitor.bottom - mi.rcMonitor.top,
  997.                             SWP_NOZORDER|SWP_FRAMECHANGED );
  998. #endif
  999.         }
  1000.         else
  1001.         {
  1002.             /* Maximize non embedded window */
  1003.             ShowWindow( hwnd, SW_SHOWMAXIMIZED );
  1004.         }
  1005.         if( p_vout->p_sys->hparent )
  1006.         {
  1007.             /* Hide the previous window */
  1008.             RECT rect;
  1009.             GetClientRect( hwnd, &rect );
  1010.             SetParent( p_vout->p_sys->hwnd, hwnd );
  1011.             SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0,
  1012.                           rect.right, rect.bottom,
  1013.                           SWP_NOZORDER|SWP_FRAMECHANGED );
  1014. #ifdef UNDER_CE
  1015.             HWND topLevelParent = GetParent( p_vout->p_sys->hparent );
  1016. #else
  1017.             HWND topLevelParent = GetAncestor( p_vout->p_sys->hparent, GA_ROOT );
  1018. #endif
  1019.             ShowWindow( topLevelParent, SW_HIDE );
  1020.         }
  1021.         SetForegroundWindow( hwnd );
  1022.     }
  1023.     else
  1024.     {
  1025.         msg_Dbg( p_vout, "leaving fullscreen mode" );
  1026.         /* Change window style, no borders and no title bar */
  1027.         SetWindowLong( hwnd, GWL_STYLE, p_vout->p_sys->i_window_style );
  1028.         if( p_vout->p_sys->hparent )
  1029.         {
  1030.             RECT rect;
  1031.             GetClientRect( p_vout->p_sys->hparent, &rect );
  1032.             SetParent( p_vout->p_sys->hwnd, p_vout->p_sys->hparent );
  1033.             SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0,
  1034.                           rect.right, rect.bottom,
  1035.                           SWP_NOZORDER|SWP_FRAMECHANGED );
  1036. #ifdef UNDER_CE
  1037.             HWND topLevelParent = GetParent( p_vout->p_sys->hparent );
  1038. #else
  1039.             HWND topLevelParent = GetAncestor( p_vout->p_sys->hparent, GA_ROOT );
  1040. #endif
  1041.             ShowWindow( topLevelParent, SW_SHOW );
  1042.             SetForegroundWindow( p_vout->p_sys->hparent );
  1043.             ShowWindow( hwnd, SW_HIDE );
  1044.         }
  1045.         else
  1046.         {
  1047.             /* return to normal window for non embedded vout */
  1048.             SetWindowPlacement( hwnd, &window_placement );
  1049.             ShowWindow( hwnd, SW_SHOWNORMAL );
  1050.         }
  1051.         /* Make sure the mouse cursor is displayed */
  1052.         PostMessage( p_vout->p_sys->hwnd, WM_VLC_SHOW_MOUSE, 0, 0 );
  1053.     }
  1054.     /* Update the object variable and trigger callback */
  1055.     var_SetBool( p_vout, "fullscreen", p_vout->b_fullscreen );
  1056. }