Register An appbar (what is An appbar? Using
Application desktop toolbars
), Register the AppBar with the system through shappbarmessage, so that when a program is in full screen
At runtime, the system will send messages to our program, which can be processed in the form wndproc.
Declare the APIs and constants to be used:
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 rect
{
Public int left;
Public int top;
Public int right;
Public int bottom;
}
[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_warrange
}
Public Enum abedge: int
{
Abe_left = 0,
Abe_top,
Abe_right,
Abe_bottom
}
Int ucallbackmsg;
Bool runningfullscreenapp;
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;
Break;
}
Default:
Break;
}
}
Base. wndproc (ref m );
}
Private void form1_load (Object sender, eventargs E)
{
This. registerappbar (false );
}
When the program exits, do not forget the unregister AppBar we registered:
Private void form=formclosed (Object sender, formclosedeventargs E)
{
This. registerappbar (true );
}