Quickly judge the method whether user is currently in use specified application
Technical field
The invention belongs to computer desktop application, especially need to judge user interface whether rest on specify should
With time in program, the method quickly judged, it is provided that a kind of quick judge whether user interface rests on the application program specified
Method.
Background technology
Along with developing rapidly of cyber-net, the application of long-distance education is more and more extensive, when long-distance education is applied
Time with underage child, generally there is attention due to underage child not enough, the situation such as easily desert, causes result of training to beat
Discount, for this reason, it may be necessary to one judges that student, when using Remote Courseware, quickly judges whether conscientious technology, in order to adopt
Take follow-up.
Summary of the invention
It is an object of the invention to the blank for prior art, it is provided that one quickly judges whether user interface rests on
The method on application program specified.
Concretely comprising the following steps of the inventive method:
Step one, obtains the resolution of screen, is designated as CXScreen, CYScreen, further according to practical situation, arranges one
Grid distance value Interval, by CXScreen, CYScreen all divided by Interval, obtains horizontal and vertical cycle criterion
Number of times, be designated as CXNum, CYNum respectively.
Step 2, initializes a counting variable UseNum=0, then according to CXNum, CYNum, uses one double to follow
Ring, calculates the coordinate Point of the point that the needs in each loop body judge(n,m):
Point(n,m)=(n × Interval, m × Interval)0≤n≤CXNum,0≤m≤CYNum
After the coordinate of point calculates, call the api function that Windows provides, obtain the application program at this place
Mark, then the mark of application program of the mark of this application program with anticipation is compared, if equal, then by counting change
Amount UseNum=UseNum+1.
Step 3, coordinates computed Point(n,m)Fall the ratio on the application program specified, if more than threshold value U, then it is assumed that
User is currently in use this application program.
The detailed description of each step is as follows:
In step one, grid distance value Interval, for determining the distance between the mesh point judged, is traditionally arranged to be
Between 10 to 50 pixels, arrange little then detection precision the highest, arrange the most then detection speed the fastest, according to actual requirement,
An acceptable value is used after test.
In step 2, obtained the window handle at specified point place by the WindowFromPoint in Windows API,
The input parameter of this API is the coordinate figure of a point, and output parameter is the window handle at this place, then uses
GetWindowThreadProcessId obtains the process ID at this window handle place, by the process ID of this application program and need
The process ID of application program to be judged compares, thus obtains whether this point belongs to the application program that needs judge.
In step 3, the computing formula of ratio R atio fallen on the application program specified is as follows:
The codomain of calculated Ratio is [0,1], general when Ratio is in [0.85,1], it is believed that student makes
With application program, also having the spaces such as taskbar by shared by system because general on user's screen, these areas need row
Except outside.
The present invention has the beneficial effect that:
The thought of this method is the power function provided by Windows system, is judged by simple recursive call
Whether some screen position belongs to the application program specified, after getting all of information, according to whether rest on specify should
With the point of program account for ratio a little, it is judged that the application program whether user specifies in use, main innovative point is obstructed
Cross the judgment mode of the window level of complexity, only by the way of directly judging point, accelerate calculating speed, decrease interference
Factor, makes this method can preferably work under various user environments.
Accompanying drawing explanation
Fig. 1 is the embodiment of the present invention.
Detailed description of the invention
The present invention will be further described with embodiment below in conjunction with the accompanying drawings.
Quickly judge whether user interface rests on the method on the application program specified, specifically comprise the following steps that
Step one, obtains the resolution of screen, is designated as CXScreen, CYScreen, further according to practical situation, arranges one
Grid distance value Interval, by CXScreen, CYScreen all divided by Interval, obtains horizontal and vertical cycle criterion
Number of times, be designated as CXNum, CYNum respectively.
Step 2, initializes a counting variable UseNum=0, then according to CXNum, CYNum, uses one double to follow
Ring, calculates the coordinate Point of the point that the needs in each loop body judge(n,m):
Point(n,m)=(n × Interval, m × Interval)0≤n≤CXNum,0≤m≤CYNum
After the coordinate of point calculates, call the api function that Windows provides, obtain the application program at this place
Mark, then the mark of application program of the mark of this application program with anticipation is compared, if equal, then by counting change
Amount UseNum=UseNum+1.
Step 3, coordinates computed Point(n,m)Fall the ratio on the application program specified, if more than threshold value U, then it is assumed that
User is currently in use this application program.
The detailed description of each step is as follows:
In step one, grid distance value Interval, for determining the distance between the mesh point judged, is traditionally arranged to be
Between 10 to 50 pixels, arrange little then detection precision the highest, arrange the most then detection speed the fastest, according to actual requirement,
An acceptable value is used after test.
In step 2, obtained the window handle at specified point place by the WindowFromPoint in Windows API,
The input parameter of this API is the coordinate figure of a point, and output parameter is the window handle at this place, then uses
GetWindowThreadProcessId obtains the process ID at this window handle place, by the process ID of this application program and need
The process ID of application program to be judged compares, thus obtains whether this point belongs to the application program that needs judge.
In step 3, the computing formula of ratio R atio fallen on the application program specified is as follows:
The codomain of calculated Ratio is [0,1], general when Ratio is in [0.85,1], it is believed that student makes
With application program, also having the spaces such as taskbar by shared by system because general on user's screen, these areas need row
Except outside.
Embodiment:
As it is shown in figure 1, be used for judging whether PC is using unlimited precious (blue title bar and the program of frame).The most such as
Under: screen resolution is 1440*900 at present, and grid distance value Interval is set to 200, then screen is divided into longitudinally 5
Point, horizontal 8 points, the cross point of red line i.e. these 40 points on totally 40 point diagrams, the point wherein indicated with blue five-pointed star is judged to
Breaking as belonging to unlimited precious application program, 18 altogether, accounting is 18/40=45%, the threshold value less than 85%, it is determined that be not
Conscientiously using unlimited precious program.