WPF captures Windows shutdown events

Source: Internet
Author: User
Tags win32 window

 1  private  const  int  sc_screensave = 0xf140   2  private  const  int  wm_queryendsession = 0x0011  ;  3  private  bool  isscreensave = false   4  private  bool  iswindowstopclosing = false ; 
variables


No nonsense, just paste the code, in the constructor

Public xx{

 1  //  2  IntPtr hwnd = new Windowinterophelper (this  ). Handle;  3   display the contents of WPF in the Win32 window  4  HwndSource src = Hwndsource.fromhwnd (HWND);  5   handler implementation for receiving window messages (based on System.Windows.Interop.HwndSourceHook delegate)  6  Src. Addhook (new  HwndSourceHook (WndProc)); 
Register

}

1     /// <summary>2         ///re-WndProc3         /// </summary>4         /// <param name= "hwnd" >window Handle</param>5         /// <param name= "MSG" >Message ID</param>6         /// <param name= "WParam" >the WParam value of the message</param>7         /// <param name= "LParam" >the LParam value of the message</param>8         /// <param name= "handled" >A value that indicates whether the message has been processed. If the message is processed, set the value to true, otherwise set it to false</param>9         /// <returns></returns>Ten         PrivateINTPTR WndProc (INTPTR hwnd,intMSG, IntPtr WParam, IntPtr LParam,ref BOOLhandled) One         { A             if(msg = =wm_queryendsession) -             { -                 using(varWCF =Newkefuservicesclient ()) the                 { - WCF. Updateuserstate (Mainpanelwindow.clientserviceid, userstates.unline); -                 } -             } +             returnIntPtr.Zero; -}
capturing operating system shutdown events

. NET Technology Exchange Group 199281001. Welcome to join.

Related Article

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.