日期:2014-05-17 浏览次数:20998 次
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
}
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);
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.RegisterAppBar(false);
}
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;
break;
}
default:
break;
}
}
base.WndProc(ref m);
}