Determine whether a full screen program is running (C #)

Source: Internet
Author: User

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 );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.