C # net calls API enumeration system monitor, display

Source: Internet
Author: User

Using system;
Using system. runtime. interopservices;
Namespace opticaltouch
{
Public Delegate bool monitorenumproc (intptr hmonitor, intptr hdcmonitor, intptr lprcmonitor, intptr dwdata );
[Structlayout (layoutkind. Sequential, size = 8)]
Public struct rect
{
Public int left;
Public int top;
Public int right;
Public int bottom;
}
[Structlayout (layoutkind. Sequential, size = 8)]
Public struct monitorinfos
{
[Financialas (unmanagedtype. byvalarray, sizeconst = 256)]
Public rect [] rects;
Public int count;
}
Public class monitorhelper
{
Private monitorenumproc;
Public monitorhelper ()
{
Monitorenumproc = monitorenumproc;
}
Public monitorinfos enummonitors ()
{
Monitorinfos MIS = new monitorinfos ();
Mis. rects = new rect [256];
Mis. Count = 0;
Intptr dwdata = marshal. allochglobal (marshal. sizeof (typeof (monitorinfos )));
Marshal. structuretoptr (MIS, dwdata, true );
Enumdisplaymonitors (intptr. Zero, intptr. Zero, monitorenumproc, dwdata );
MIS = (monitorinfos) Marshal. ptrtostructure (dwdata, typeof (monitorinfos ));
Marshal. freehglobal (dwdata );
Return MIS;
}
Private bool monitorenumproc (intptr hmonitor, intptr hdcmonitor, intptr lprcmonitor, intptr dwdata)
{
Rect = (rect) Marshal. ptrtostructure (lprcmonitor, typeof (rect ));
Monitorinfos MIS = (monitorinfos) Marshal. ptrtostructure (dwdata, typeof (monitorinfos ));
Mis. rects [mis. Count]. Left = rect. Left;
Mis. rects [mis. Count]. Top = rect. Top;
Mis. rects [mis. Count]. Right = rect. Right;
Mis. rects [mis. Count]. Bottom = rect. bottom;
Mis. Count ++;
Marshal. structuretoptr (MIS, dwdata, true );
Return true;
}
[Dllimport ("user32.dll")]
Private Static extern bool enumdisplaymonitors (intptr HDC, intptr pprcclip, monitorenumproc, intptr dwdata );
}
}
I haven't written much. Read msdn and check the code.

 

Transferred from:

Http://hi.baidu.com/%CE%E2%D6%BE%C7%BF/blog/item/bd517d3193cde60eeac4af26.html

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.