求判断是否全屏的方法 我用代码模拟鼠标双击,使得第三方的视频播放器全屏播放或退出全屏,但是有时候会不成功。我现在的做法是如果没有全屏,则再次发送鼠标双击消息,直至成功为止。退出全屏状态时,也是如此。问题是:我怎么判断当前的播放状态是否全屏的呢?播放方式有客户端软件的,也有网页播放的。求高手帮我想一个较稳妥的判断办法,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 全屏本身并没有这样的定义。如果当前窗口的大小和屏幕大小一样,并且没有标题栏,就可以认为是全屏了。用到的APIGetForegroundWindow()GetWindowRect()GetWindowLong() public partial class 监测全屏程序 : Form { public 监测全屏程序() { InitializeComponent(); } private bool RunningFullScreenApp; int uCallBackMsg; public class APIWrapper { [DllImport("SHELL32", CallingConvention = CallingConvention.StdCall)] public static extern uint SHAppBarMessage(int dwMessage, ref APPBARDATA pData); [DllImport("User32.dll", CharSet = CharSet.Auto)] public static extern int RegisterWindowMessage(string msg); } [StructLayout(LayoutKind.Sequential)] public struct APPBARDATA { public int cbSize; public IntPtr hWnd; public int uCallbackMessage; public int uEdge; public RECT rc; public IntPtr lParam; } public enum ABMsg : int { ABM_NEW = 0, ABM_REMOVE, ABM_QUERYPOS, ABM_SETPOS, ABM_GETSTATE, ABM_GETTASKBARPOS, ABM_ACTIVATE, ABM_GETAUTOHIDEBAR, ABM_SETAUTOHIDEBAR, ABM_WINDOWPOSCHANGED, ABM_SETSTATE } public enum ABNotify : int { ABN_STATECHANGE = 0, ABN_POSCHANGED, ABN_FULLSCREENAPP, ABN_WINDOWARRANGE } public enum ABEdge : int { ABE_LEFT = 0, ABE_TOP, ABE_RIGHT, ABE_BOTTOM } [StructLayout(LayoutKind.Sequential)] public struct RECT { public int left; public int top; public int right; public int bottom; public override string ToString() { return "{left=" + left.ToString() + ", " + "top=" + top.ToString() + ", " + "right=" + right.ToString() + ", " + "bottom=" + bottom.ToString() + "}"; } } private void RegisterAppBar(bool registered) { APPBARDATA abd = new APPBARDATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = this.Handle; if (!registered) { //register uCallBackMsg = APIWrapper.RegisterWindowMessage("APPBARMSG_CSDN_HELPER"); abd.uCallbackMessage = uCallBackMsg; uint ret = APIWrapper.SHAppBarMessage((int)ABMsg.ABM_NEW, ref abd); } else { APIWrapper.SHAppBarMessage((int)ABMsg.ABM_REMOVE, ref abd); } } protected override void WndProc(ref System.Windows.Forms.Message m) { if (m.Msg == uCallBackMsg) { switch (m.WParam.ToInt32()) { case (int)ABNotify.ABN_FULLSCREENAPP: { if ((int)m.LParam == 1) this.RunningFullScreenApp = true; else this.RunningFullScreenApp = false; if (RunningFullScreenApp) //发现全屏,自己处理 listBox1.Items.Add(DateTime.Now.ToString()); break; } default: break; } } base.WndProc(ref m); } //开始监测 private void 监测全屏程序_Load(object sender, EventArgs e) { this.RegisterAppBar(false); } //取消监测 private void 监测全屏程序_FormClosing(object sender, FormClosingEventArgs e) { this.RegisterAppBar(true); } } 感谢你提供的准确的API!“并且没有标题栏”,有办法判断吗? GetWindowLong()传递GWL_STYLE判断WS_CAPTION标志有没有。 添加记录时一个奇怪的问题 如何在datagridview的单元格右上方显示一个小图片 在C# web中实现DropDownlist 的 可文本输入可下拉选择 菜鸟的第一个问题:怎么在gridview中显示查询的数据? 随想项目:Linq To Object 用.net做个简单的c/s结构的系统,怎么做的? 求教Com控件DBGrid的使用方法 如何用程序更改时区?请帮忙,谢谢. flashbox如何引用resources中的swf文件? C# 基于Json文件的多语言翻译功能简单实现 数据相似度匹配问题 【webbrowser相关】如何读取到一个网页的实际大小?
GetForegroundWindow()
GetWindowRect()
GetWindowLong()
public partial class 监测全屏程序 : Form
{
public 监测全屏程序()
{
InitializeComponent();
} private bool RunningFullScreenApp;
int uCallBackMsg; public class APIWrapper
{
[DllImport("SHELL32", CallingConvention = CallingConvention.StdCall)]
public static extern uint SHAppBarMessage(int dwMessage, ref APPBARDATA pData); [DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int RegisterWindowMessage(string msg); } [StructLayout(LayoutKind.Sequential)]
public struct APPBARDATA
{
public int cbSize;
public IntPtr hWnd;
public int uCallbackMessage;
public int uEdge;
public RECT rc;
public IntPtr lParam;
} public enum ABMsg : int
{
ABM_NEW = 0,
ABM_REMOVE,
ABM_QUERYPOS,
ABM_SETPOS,
ABM_GETSTATE,
ABM_GETTASKBARPOS,
ABM_ACTIVATE,
ABM_GETAUTOHIDEBAR,
ABM_SETAUTOHIDEBAR,
ABM_WINDOWPOSCHANGED,
ABM_SETSTATE
} public enum ABNotify : int
{
ABN_STATECHANGE = 0,
ABN_POSCHANGED,
ABN_FULLSCREENAPP,
ABN_WINDOWARRANGE
} public enum ABEdge : int
{
ABE_LEFT = 0,
ABE_TOP,
ABE_RIGHT,
ABE_BOTTOM
} [StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom; public override string ToString()
{
return "{left=" + left.ToString() + ", " + "top=" + top.ToString() + ", " +
"right=" + right.ToString() + ", " + "bottom=" + bottom.ToString() + "}";
}
} private void RegisterAppBar(bool registered)
{
APPBARDATA abd = new APPBARDATA();
abd.cbSize = Marshal.SizeOf(abd);
abd.hWnd = this.Handle; if (!registered)
{
//register
uCallBackMsg = APIWrapper.RegisterWindowMessage("APPBARMSG_CSDN_HELPER");
abd.uCallbackMessage = uCallBackMsg;
uint ret = APIWrapper.SHAppBarMessage((int)ABMsg.ABM_NEW, ref abd);
}
else
{
APIWrapper.SHAppBarMessage((int)ABMsg.ABM_REMOVE, ref abd);
}
} protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m.Msg == uCallBackMsg)
{
switch (m.WParam.ToInt32())
{
case (int)ABNotify.ABN_FULLSCREENAPP:
{
if ((int)m.LParam == 1)
this.RunningFullScreenApp = true;
else
this.RunningFullScreenApp = false; if (RunningFullScreenApp) //发现全屏,自己处理
listBox1.Items.Add(DateTime.Now.ToString()); break;
}
default:
break;
}
} base.WndProc(ref m);
} //开始监测
private void 监测全屏程序_Load(object sender, EventArgs e)
{
this.RegisterAppBar(false);
} //取消监测
private void 监测全屏程序_FormClosing(object sender, FormClosingEventArgs e)
{
this.RegisterAppBar(true);
}
}
“并且没有标题栏”,有办法判断吗?
判断WS_CAPTION标志有没有。