Context
Hello everybody,
I want to display the state of the keyboard on the status bar of the active application. For this, I have to take into account whether the application is displayed full screen, in which case the status bar of the application is down the screen, otherwise it is above the task bar.
My first idea to get this information, is to pick a point down the screen, and then ask what program opened the window at that point.
My reasoning is that if my point is on the task bar, the associated program is explorer. Then, I shall probably have to take care of the case of an explorer window displayed full screen.
So, I want to know what program opened the window three pixels above the middle of the down side of the screen.
To position my form, I have a function that contains:
So, I am tempted to make an infringement to the rule of "one responsibility, one function", and to optimize a little the code by avoiding to declare these values again.
Maybe, I should put them at the module level.
One thing done. Of course the point is declared at the module level.
On my screen dimensioned 1920x1080, my point is at x=960, y=1077. Somewhere behind the shortcuts to the applications.
In the timer_Tick I have this:
sbfileName is a StringBuilder declared at the module level.
And ... It displays an empty string, which to code properly I should have detected by ret=0.
So, did I choose a bad point, or is my reasoning false?
One precision: hWnd is not null.
Just an out-of-topic aparte: in PositionsForm I can get
In an application that shows the state of the cursor (regarding mainly the caps lock) to the user of a laptop, a previous version was planed with two places allocated on the screen to avoid staying under the mouse cursor, then the click through notion reduced the necessity to move the form.
Then appeared the notion of changing FormBorderStyle to hide the title bar.
The new version is able to be displayed in the status bar of an application.
A further concern remains: the application that has the focus can be displayed full screen, meaning that the Windows task bar is not displayed. The coordinates to display the state of the keyboard must be adjusted accordingly.
Hello everybody,
I want to display the state of the keyboard on the status bar of the active application. For this, I have to take into account whether the application is displayed full screen, in which case the status bar of the application is down the screen, otherwise it is above the task bar.
My first idea to get this information, is to pick a point down the screen, and then ask what program opened the window at that point.
My reasoning is that if my point is on the task bar, the associated program is explorer. Then, I shall probably have to take care of the case of an explorer window displayed full screen.
So, I want to know what program opened the window three pixels above the middle of the down side of the screen.
To position my form, I have a function that contains:
part of the function that positions the form:
int dpix = (int)graphics.DpiX / 96;
int dpiy = (int)graphics.DpiY / 96;
So, I am tempted to make an infringement to the rule of "one responsibility, one function", and to optimize a little the code by avoiding to declare these values again.
Maybe, I should put them at the module level.
C#:
private void PositionsForm()
{
using (Graphics graphics = this.CreateGraphics())
{
int dpix = (int)graphics.DpiX / 96;
int dpiy = (int)graphics.DpiY / 96;
// Here, the instructions that position the form
pt = new Point
(
Screen.PrimaryScreen.Bounds.Width * dpix / 2,
Screen.PrimaryScreen.Bounds.Height * dpiy - 3
);
}
}
One thing done. Of course the point is declared at the module level.
On my screen dimensioned 1920x1080, my point is at x=960, y=1077. Somewhere behind the shortcuts to the applications.
In the timer_Tick I have this:
Trying to get the associated module with the window under the point:
PositionsForm();
IntPtr hWnd = WindowFromPoint(pt);
uint ret = GetWindowModuleFileName(hWnd, sbfileName, 2000);
string strApp = sbfileName.ToString();
Debug.Print(String.Format("The application down the screen is {0}", strApp));
sbfileName is a StringBuilder declared at the module level.
And ... It displays an empty string, which to code properly I should have detected by ret=0.
So, did I choose a bad point, or is my reasoning false?
One precision: hWnd is not null.
Just an out-of-topic aparte: in PositionsForm I can get
hdc=graphics.GetHdc;
Last edited: