Original link http://blog.csdn.net/sytzz/article/details/25372103
The currently activated window will always lose focus every few seconds, over 0.5~1 seconds focus back, resulting in the input does not work properly, seriously affect the use of mood and efficiency.
Window loses focus, nothing but other window will focus on the past, if you can find what program has preempted the window focus, disable it can be resolved.
Because it is a solution to Windows problems, use Microsoft's own C # to solve the problem.
Open vs Create C # Windows Application project, use a lable display information, a timer to get the current activation window (millisecond level), and display the information to lable. The current window focus changes, and you can see the current foreground program from the lable.
Attached to the monitoring program part of the logic code (not using any coding specifications, without any comments), window code using the window designer can be generated.
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Runtime.InteropServices;namespacewindowsformsapplication1{ Public Partial classForm1:form {[DllImport ("user32.dll", CharSet = CharSet.Auto, exactspelling =true)] Public Static externIntPtr GetForegroundWindow ();//get the current activation window[DllImport ("User32", SetLastError =true)] Public Static extern intGetWindowText (IntPtr hWnd,//window HandleStringBuilder lpstring,//title intnMaxCount//Maximum Value ); [DllImport ("user32.dll")] Private Static extern intGetClassName (IntPtr hWnd,// HandleStringBuilder lpstring,//class name intnMaxCount//Maximum Value ); PublicForm1 () {InitializeComponent (); Timer1. Start (); }Private voidTimer1_Tick (Objectsender, EventArgs e) {INTPTR myptr=GetForegroundWindow (); //Window TitleStringBuilder title =NewStringBuilder (255); GetWindowText (myptr, title, title. capacity); //window class nameStringBuilder ClassName =NewStringBuilder ( the); GetClassName (Myptr, ClassName, classname.capacity); Label1. Text= myptr.tostring () +"\ n"+ title. ToString () +"\ n"+classname.tostring (); } }}
Discover the program that robbed you of focus, turn it off.
[Turn] who robbed me of the focus