çªä½æ§ä»¶è¿å ¥å ¨å±æ¨¡å¼åéåºå ¨å±æ¨¡å¼ï¼è§é¢ææ¾çæ¶åç¨å°æ¤åè½ã
å·¥å ·ç±»ä»£ç
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CvNetVideo.Play
{
class FullScreenHelper
{
bool m_bFullScreen = false;
IntPtr m_OldWndParent = IntPtr.Zero;
WINDOWPLACEMENT m_OldWndPlacement = new WINDOWPLACEMENT();
Control m_control = null;
public FullScreenHelper(Control c)
{
m_control = c;
}
struct POINT
{
int x;
int y;
};
struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
};
//éå®æå®çªå£ï¼ç¦æ¢å®æ´æ°ãåæ¶åªè½æä¸ä¸ªçªå£å¤äºéå®ç¶æãéå®æå®çªå£ï¼ç¦æ¢å®æ´æ°ãåæ¶åªè½æä¸ä¸ªçªå£å¤äºéå®ç¶æ
       [DllImport("User32.dll")]
       public static extern bool LockWindowUpdate(IntPtr hWndLock);
       //å½æ°æ¥è®¾ç½®å¼¹åºå¼çªå£ï¼å±å çªå£æåçªå£çç¶çªå£ãæ°ççªå£ä¸çªå£å¿
é¡»å±äºåä¸åºç¨ç¨åº
       [DllImport("User32.dll")]
       public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
       //å½æ°è®¾ç½®æå®çªå£çæ¾ç¤ºç¶æåæ¢å¤ï¼æ大åï¼æå°åä½ç½®ãå½æ°åè½ï¼Â å½ååå Â
       [DllImport("User32.dll")]
       public static extern bool SetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
       //å½æ°å°å建æå®çªå£ç线ç¨è®¾ç½®å°åå°ï¼å¹¶ä¸æ¿æ´»è¯¥çªå£ãé®çè¾å
¥è½¬å该çªå£ï¼å¹¶ä¸ºç¨æ·æ¹åç§å¯è§çè®°å·
       [DllImport("User32.dll")]
       public static extern bool SetForegroundWindow(IntPtr hWnd);
       //该å½æ°è¿åæ¡é¢çªå£çå¥æãæ¡é¢çªå£è¦çæ´ä¸ªå±å¹ãæ¡é¢çªå£æ¯ä¸ä¸ªè¦å¨å
¶ä¸ç»å¶ææçå¾æ åå
¶ä»çªå£çåºå
       [DllImport("User32.dll")]
       public static extern IntPtr GetDesktopWindow();
       //å½æ°åã该å½æ°è¿åæå®çªå£çæ¾ç¤ºç¶æ以å被æ¢å¤çãæ大åçåæå°åççªå£ä½ç½®
       [DllImport("User32.dll")]
       public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
       //æ¯ç¨äºå¾å°è¢«å®ä¹çç³»ç»æ°æ®æè
ç³»ç»é
置信æ¯çä¸ä¸ªä¸æåè¯Â
       [DllImport("User32.dll")]
       public static extern int GetSystemMetrics(int nIndex);
       [DllImport("user32.dll", EntryPoint = "GetParent", SetLastError = true)]
       public static extern IntPtr GetParent(IntPtr hWnd);
       [DllImport("user32.dll", CharSet = CharSet.Auto)]
       public static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);
       [DllImport("user32.dll", CharSet = CharSet.Auto)]
       public static extern System.IntPtr GetForegroundWindow();
       [DllImport("user32")]
       public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
       [DllImport("user32.dll")]
       public static extern uint ScreenToClient(IntPtr hwnd, ref POINT p);
        public void FullScreen(bool flag)
{
m_bFullScreen = flag;
if (!m_bFullScreen)
{
LockWindowUpdate(m_control.Handle);
SetParent(m_control.Handle, m_OldWndParent);
SetWindowPlacement(m_control.Handle, ref m_OldWndPlacement);
SetForegroundWindow(m_OldWndParent);
LockWindowUpdate(IntPtr.Zero);
}
else
{
GetWindowPlacement(m_control.Handle, ref m_OldWndPlacement);
int nScreenWidth = GetSystemMetrics(0);
int nScreenHeight = GetSystemMetrics(1);
m_OldWndParent = GetParent(m_control.Parent.Handle);
SetParent(m_control.Handle, GetDesktopWindow());
WINDOWPLACEMENT wp1 = new WINDOWPLACEMENT();
wp1.length = (uint)Marshal.SizeOf(wp1);
wp1.showCmd = 1;
wp1.rcNormalPosition.left = 0;
wp1.rcNormalPosition.top = 0;
wp1.rcNormalPosition.right = nScreenWidth;
wp1.rcNormalPosition.bottom = nScreenHeight;
SetWindowPlacement(m_control.Handle, ref wp1);
SetForegroundWindow(GetDesktopWindow());
SetForegroundWindow(m_control.Handle);
}
m_bFullScreen = !m_bFullScreen;
}
struct WINDOWPLACEMENT
{
public uint length;
public uint flags;
public uint showCmd;
public POINT ptMinPosition;
public POINT ptMaxPosition;
public RECT rcNormalPosition;
};
}
}
è°ç¨æ¹å¼
/// <summary>
/// å
¨å±äºä»¶
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void UCVideo_DoubleClick(object sender, EventArgs e)
{
//å
¨å±è®¾ç½®
//sdlVideo.SDL_MaximizeWindow();
fullScreenHelper = new CvNetVideo.Play.FullScreenHelper(this);
fullScreenHelper.FullScreen(true);
Console.WriteLine("Entrance FullScreen Mode");
}
/// <summary>
/// æé®å¼¹èµ·äºä»¶
/// </summary>
private void UCVideo_KeyUp(object sender, KeyEventArgs e)
{
// ESC éåºå
¨å±
if (e.KeyCode == Keys.Escape&& fullScreenHelper!=null)
{
fullScreenHelper.FullScreen(false);
fullScreenHelper = null;
Console.WriteLine("Exit FullScreen Mode");
}
}
æµè¯ææå¾
注æï¼å¨ä½¿ç¨SDLçå ¨å±æä½è¿ç¨ä¸è®¾ç½®æ¯æ æçï¼ææ¾è§é¢è¿ç¨ä¸ä¸è½å®ç°ä¿®æ¹ã代ç å¦ä¸ï¼
public void SDL_MaximizeWindow()
{
Console.WriteLine("设置å
¨å±");
SDL.SDL_MaximizeWindow(screen);
SDL.SDL_SetWindowFullscreen(screen, SDL.SDL_GetWindowFlags(screen));
SDL.SDL_ShowWindow(screen);
//int width, height;
è·åæ大çªå£å¼
//SDL2.SDL.SDL_GetWindowMaximumSize(screen, out width, out height);
设置æ大çªå£å¼
//if (width>0&&height>0)
//{
// SDL2.SDL.SDL_SetWindowMaximumSize(screen, width, height);
// Console.WriteLine("设置å
¨å±......æå!width=" + width + ",height=" + height);
//}
//else
//{
// Console.WriteLine("设置å
¨å±......失败!width=" + width + ",height=" + height);
// SDL2.SDL.SDL_SetWindowMaximumSize(screen, w, h);
//}
}
å·¥å ·ä»£ç åè½æ¹è¿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CvNetVideo.Play
{
/// <summary>
/// å®ä¹å
¨å±æ½è±¡ç±»
/// </summary>
public abstract class FullScreenObject
{
public abstract void FullScreen(bool flag);
}
/// <summary>
/// æ¡é¢å
¨å±
/// </summary>
public unsafe class FullScreenHelper: FullScreenObject
{
bool m_bFullScreen = false;
WINDOWPLACEMENT m_OldWndPlacement = new WINDOWPLACEMENT();
UCVideo m_control = null;
public FullScreenHelper(UCVideo control)
{
m_control = control;
}
private IntPtr m_OldWndParent = IntPtr.Zero;
DockStyle old_docker_style;
int old_left;
int old_width;
int old_height;
int old_top;
public override void FullScreen(bool flag)
{
m_bFullScreen = flag;
if (!m_bFullScreen)
{
#region æ¹å¼ä¸ï¼çªä½å®¹ç§¯æ¹åæ¶ä¸è½å
¨å±ï¼æªè½è§£å³IEå
¨å±æ¾ç¤ºä¸å
¨é®é¢
//ShellSDK.LockWindowUpdate(m_control.Handle);
//ShellSDK.SetParent(m_control.Handle, m_OldWndParent);
//ShellSDK.SetWindowPlacement(m_control.Handle, ref m_OldWndPlacement);
//ShellSDK.SetForegroundWindow(m_OldWndParent);
//ShellSDK.LockWindowUpdate(IntPtr.Zero);
#endregion
#region æ¹å¼äºï¼å¨å®¹å¨æ¹åæ¶å¯ä»¥å®ç°å
¨å±ï¼æªè½è§£å³IEå
¨å±æ¾ç¤ºä¸å
¨é®é¢
// åæ¶å
¨å±è®¾ç½®
m_control.Dock = old_docker_style;
m_control.Left = old_left;
m_control.Top = old_top;
m_control.Width = old_width;
m_control.Height = old_height;
ShellSDK.SetParent(m_control.Handle, m_OldWndParent);
#endregion
}
else
{
#region æ¹å¼ä¸ï¼çªä½å®¹ç§¯æ¹åæ¶ä¸è½å
¨å±ï¼æªè½è§£å³IEå
¨å±æ¾ç¤ºä¸å
¨é®é¢
//ShellSDK.GetWindowPlacement(m_control.Handle, ref m_OldWndPlacement);
//int nScreenWidth = ShellSDK.GetSystemMetrics(0);
//int nScreenHeight = ShellSDK.GetSystemMetrics(1);
//m_OldWndParent = ShellSDK.GetParent(m_control.Handle);
//ShellSDK.SetParent(m_control.Handle, ShellSDK.GetDesktopWindow());
//WINDOWPLACEMENT wp1 = new WINDOWPLACEMENT();
//wp1.length = (uint)Marshal.SizeOf(wp1);
//wp1.showCmd = 1;
//wp1.rcNormalPosition.left = 0;
//wp1.rcNormalPosition.top = 0;
//wp1.rcNormalPosition.right = Screen.PrimaryScreen.Bounds.Width/*nScreenWidth*/;
//wp1.rcNormalPosition.bottom = Screen.PrimaryScreen.WorkingArea.Height/* nScreenHeight*/;
//ShellSDK.SetWindowPlacement(m_control.Handle, ref wp1);
//ShellSDK.SetForegroundWindow(ShellSDK.GetDesktopWindow());
//ShellSDK.SetForegroundWindow(m_control.Handle);
#endregion
#region æ¹å¼äºï¼å¨å®¹å¨æ¹åæ¶å¯ä»¥å®ç°å
¨å±ï¼æªè½è§£å³IEå
¨å±æ¾ç¤ºä¸å
¨é®é¢
// è®°å½åæ¥çæ°æ®
old_docker_style = m_control.Dock;
old_left = m_control.Left;
old_width = m_control.Width;
old_height = m_control.Height;
old_top = m_control.Top;
m_OldWndParent = ShellSDK.GetParent(m_control.Handle);
// 设置å
¨å±æ°æ®
int nScreenWidth = ShellSDK.GetSystemMetrics(0);
int nScreenHeight = ShellSDK.GetSystemMetrics(1);
m_control.Dock = DockStyle.None;
m_control.Left = 0;
m_control.Top = 0;
m_control.Width = nScreenWidth;
m_control.Height = nScreenHeight;
ShellSDK.SetParent(m_control.Handle, ShellSDK.GetDesktopWindow());
ShellSDK.SetWindowPos(m_control.Handle, -1, 0, 0, m_control.Right - m_control.Left, m_control.Bottom - m_control.Top, 0);
#endregion
}
m_bFullScreen = !m_bFullScreen;
}
}
/// <summary>
/// å¨å®¹å¨å
é¨å
¨å±
/// </summary>
public class FullScreenInContainerHelper : FullScreenObject
{
bool m_bFullScreen = false;
Control m_control = null;
public FullScreenInContainerHelper(Control control)
{
m_control = control;
}
private IntPtr m_OldWndParent = IntPtr.Zero;
private IntPtr m_father_hwnd;
private RECT m_rect = new RECT();
public override void FullScreen(bool flag)
{
m_bFullScreen = flag;
if (!m_bFullScreen)
{
ShellSDK.SetParent(m_control.Handle, m_father_hwnd);
ShellSDK.SetWindowPos(m_control.Handle, 0, m_rect.left, m_rect.top, m_rect.right - m_rect.left, m_rect.bottom - m_rect.top, 0);
ShellSDK.SetForegroundWindow(m_father_hwnd);
}
else
{
m_father_hwnd = ShellSDK.GetParent(m_control.Handle);
ShellSDK.GetWindowRect(m_control.Handle, out RECT rect);
POINT pt = new POINT();
pt.x = rect.left;
pt.y = rect.top;
ShellSDK.ScreenToClient(m_father_hwnd, ref pt);
rect.right = rect.right - rect.left + pt.x;
rect.bottom = rect.bottom - rect.top + pt.y;
rect.left = pt.x;
rect.top = pt.y;
m_rect = rect;
ShellSDK.GetWindowRect(m_father_hwnd, out RECT rect_fature);
ShellSDK.SetWindowPos(m_control.Handle, 0, 0, 0, rect_fature.right - rect_fature.left, rect_fature.bottom - rect_fature.top, 0);
}
m_bFullScreen = !m_bFullScreen;
}
}
/// <summary>
/// Windowsç³»ç»API-SDK
/// </summary>
public class ShellSDK
{
//éå®æå®çªå£ï¼ç¦æ¢å®æ´æ°ãåæ¶åªè½æä¸ä¸ªçªå£å¤äºéå®ç¶æãéå®æå®çªå£ï¼ç¦æ¢å®æ´æ°ãåæ¶åªè½æä¸ä¸ªçªå£å¤äºéå®ç¶æ
[DllImport("User32.dll")]
public static extern bool LockWindowUpdate(IntPtr hWndLock);
//å½æ°æ¥è®¾ç½®å¼¹åºå¼çªå£ï¼å±å çªå£æåçªå£çç¶çªå£ãæ°ççªå£ä¸çªå£å¿
é¡»å±äºåä¸åºç¨ç¨åº
[DllImport("User32.dll")]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
//å½æ°è®¾ç½®æå®çªå£çæ¾ç¤ºç¶æåæ¢å¤ï¼æ大åï¼æå°åä½ç½®ãå½æ°åè½ï¼Â å½ååå  Â
[DllImport("User32.dll")]
public static extern bool SetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
//å½æ°å°å建æå®çªå£ç线ç¨è®¾ç½®å°åå°ï¼å¹¶ä¸æ¿æ´»è¯¥çªå£ãé®çè¾å
¥è½¬å该çªå£ï¼å¹¶ä¸ºç¨æ·æ¹åç§å¯è§çè®°å·
[DllImport("User32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
//该å½æ°è¿åæ¡é¢çªå£çå¥æãæ¡é¢çªå£è¦çæ´ä¸ªå±å¹ãæ¡é¢çªå£æ¯ä¸ä¸ªè¦å¨å
¶ä¸ç»å¶ææçå¾æ åå
¶ä»çªå£çåºå
[DllImport("User32.dll")]
public static extern IntPtr GetDesktopWindow();
//å½æ°åã该å½æ°è¿åæå®çªå£çæ¾ç¤ºç¶æ以å被æ¢å¤çãæ大åçåæå°åççªå£ä½ç½®
[DllImport("User32.dll")]
public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
//æ¯ç¨äºå¾å°è¢«å®ä¹çç³»ç»æ°æ®æè
ç³»ç»é
置信æ¯çä¸ä¸ªä¸æåè¯Â Â
[DllImport("User32.dll")]
public static extern int GetSystemMetrics(int nIndex);
[DllImport("user32.dll", EntryPoint = "GetParent", SetLastError = true)]
public static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern System.IntPtr GetForegroundWindow();
[DllImport("user32")]
public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
[DllImport("user32.dll")]
public static extern uint ScreenToClient(IntPtr hwnd, ref POINT p);
}
/// <summary>
/// å¾ååºå对象
/// </summary>
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
/// <summary>
/// å¾åç¹ä½ä½ç½®
/// </summary>
public struct POINT
{
public int x;
public int y;
}
/// <summary>
/// å¾åçªå£å¯¹è±¡
/// </summary>
public struct WINDOWPLACEMENT
{
public uint length;
public uint flags;
public uint showCmd;
public POINT ptMinPosition;
public POINT ptMaxPosition;
public RECT rcNormalPosition;
}
}
æ´å¤sdlçªå£æä½åè:
SDL_Window ï¼http://blog.csdn.net/leixiaohua1020/article/details/40701203
SDL å¤çº¿ç¨çªå£ : http://blog.csdn.net/x_iya/article/details/52198688