Stop app window overlapping Windows start bar - c++

On my Win7 PC I have the start-bar running vertically, it's about 60px wide. In my win32 application, the created window always appears overlapping the start bar, which looks bad - I just use (0,0) as the top-left position for the window.
How should I be doing it to get (0,0) relative to the desktop, taking the Start Bar into account? Is there a flag, or do I manually need to look up a metric?

There are a few problems here. You don't want to use a hard-coded value like (0,0). That might not even be visible on a multi-monitor system. As you have discovered, you should try to avoid overlapping with the taskbar or other appbars. If there are multiple monitors you should try and start on the monitor where the user has most recently interacted.
There is a simple way to make much of this happen for free. Pass CW_USEDEFAULT as the x and y coordinates when you call CreateWindow. This will let the window manager do the hard work of making your window appear in a sensible location.
You can get the system to tell you the coordinates of the work area. The work area is that part of the desktop that does not contain the taskbar or other appbars. Call SystemParametersInfo passing SPI_GETWORKAREA.
Retrieves the size of the work area on the primary display monitor. The work area is the portion of the screen not obscured by the system taskbar or by application desktop toolbars. The pvParam parameter must point to a RECT structure that receives the coordinates of the work area, expressed in virtual screen coordinates.
To get the work area of a monitor other than the primary display monitor, call the GetMonitorInfo function.

Use SetWindowPlacement. The (0,0) for that function excludes the taskbar and any other appbars.

Related

How to determine if any part of the window is visible to Screen?

I have an application that needs all the windows which are visible to the screen.
If a window is hidden by other windows then we ignore that. If any part of the windows is visible to the screen then only we need those windows.
So is there any way to find only those windows which are Actually visible to the screen?
Thank you so much.
Platform: Windows
EnumWindows to get all the top level windows
GetWindowRect - to get the screen coordinates of each window.
GetWindow - to compare z-orders so you can detect which window is occluded by another. You many not need this if you just rely on the behavior of EnumWindow to return handles in z-order priority.
GetDesktopWindow - combined with GetWindowRect, you can get the screen coordinates.
Between these four functions and some math to detect rectangle intersections, you can probably find all the top-level windows that aren't occluded by another window or are positioned off screen.

Force Qt-Window to specific screen

I have a Windows-system with two monitors connected to it that itself expand the Windows-desktop. Now I want to start two Qt-applications but need to force each of them to a specific monitor, means application A always has to open it's window on monitor 1, application B always has to open it's window on monitor 2 (no matter where they have been opened the last time and no matter where the mouse is located at the moment).
How can this be done automatically? Can it only be done via the screen-coordinates of the desktop? If yes: how can I force my QWidget-based window to a specific coordinate? If no: how else can this be done?
To get the number of screens at runtime you can use:
int screenCount = QApplication::desktop()->screenCount();
To get the geometry of a screen, you can use:
QRect screenRect = QApplication::desktop()->screenGeometry(1); // 0-indexed, so this would get the second screen
Moving a window to that position (or resizing it) is then trivial:
yourWindow->move(QPoint(screenRect.x(), screenRect.y()));

Detect when window gets overlapped by another window from the same or different process

Background
We are running our application in XenDesktop mode and our window shows some real time information. But if some other application is also launched in that XenDekstop and that application is overlapping our window then we want to stop rendering. And once its moved out of our window then we want to start rendering again. Unfortunately, right now these kind of notifications are not supported by Citrix.
Question
How can we detect when a part or the whole of the application window has been overlapped by other windows, and also detect when that's no longer the case?
I found the WindowFromPoint family of functions when Googling, however, that is not practical for my purpose because I'd need to keep polling all co-ordinates that my window covers.
Bonus points: For a start, it's enough if I can just detect when such overlapping occurs. However, if I can detect exactly which area(s) of my window is/are covered that would be great.
There is no such API function. And usually the it isn't needed. WM_PAINT cares for itself.
If you get a WM_PAINT message you receive a region and a update rectangle of the area that needs a repaint. But it is a rectangle only, no complex region. Also there is a clipping region too.
But it should be possible to calculate the region by yourself. If we are talking about a top level window.
Create a rectangular region that is consists of your window rect
Walk all top level windows from back to front
Ignore all windows until you find your top level window
For each visible top level window create a rectangular region and XOR it with your current one.
Should be easy with GetWindow GW_HWNDNEXT
The resulting region is what you are searching for.
Again: There is no such function or message that determine, that is fired or can be executed to find such overlapping. There is no need for such an information. The system cares for itself with the appropriate WM_PAINT message. If an area is covered. There is no need for an action. If an area is uncovered WM_PAINT gets fired.
I think you should be able to get this kind of information when processing the WM_PAINT message, since normally the clipping region would be set accordingly. Calls to the RectVisible() function should tell you, for any part of your window, whether it "should be painted" (and so, whether it was just uncovered).
Despite this is not a solution to the OP's problem, I want to remark that once an overlapping window reveals part of your window (and also if you drag more area of your window back to screen), you will get a WM_ERASEBKGND message before the WM_PAINT.

Direct2D WM_MOUSEMOVE message with scaled display

I am new to Direct2D programming and I have encountered an issue with the WM_MOUSEMOVE message handling.
As documented in MSDN, I should use this enum to handle the mouse move, and should use the LOWORD & HIWORD to extract the current x and y coordinates.
That works fine when I am working on a normal display, but when trying to run it on scaled displays (e.g. 125% in my case), the values of x and y aren't accurate, in other words, there is an "indentation" between the current position of the mouse and the values extracted from lparam.
I guess I should query the OS or the window to get the current scaling so I can calculate the right position, but don't know how!
any help please?
You can take control of the scaling by declaring your program as DPI aware. Then the automatic scaling will stop and you'll get the original coordinates. You'll need to scale the window yourself though.
Creating a DPI-Aware Application

Getting mouse position unbounded by screen size, c++ & windows

I'm currently writing a c++ console application that grabs the mouse position at regular intervals and sends it to another visual application where it is used to drive some 3d graphics in real time. The visual app is closed source and cannot be altered outside it's limited plug-in functionality.
Currently I'm using the GetCursorPos() function which is easy and fast enough, but I'm running into the issue that all of the data is clipped based on the current screen resolution of 1920x1600 so that all x values are between 0 and 1920 and all y values are between 0 and 1600 no matter how far the mouse is physically moved.
I need to get the mouse position before it's clipped at the edge of the screen, or possibly the deltas which I could use to calculate the current position.
I've seen some references to the windows MouseMove event but I would really not want to implement a window to make it work or especially have it as the active to receive those events.
I'm working in a windows environment and a language change is not feasible.
I might be wrong, but in Win32 land you don't get mouse move messages when the mouse is at the edge of the screen because, well, the mouse isn't moving. The usual way to get an infinite mouse area is to do the following:
Hide the mouse, get exclusive access and record position
Centre mouse to window
When mouse moves, get delta from centre of screen to current position
Centre mouse to window again
The next mouse move should have a delta of (0,0), so ignore it
Go to 3 until end of mouse move operation
Reset position, show the mouse and release exclusive access
If you didn't hide the mouse, then you'd see the mouse moving a small distance and then snapping back to the centre position, which looks nasty.
This method does require a message pump for the mouse move messages so the console application idea probably won't work with this. Can you create a full screen invisible window for grabbing the mouse?
Just get the position, and move it to the center and return the delta yourself
This is how FPS games do it
I don't have any direct experience with raw input, which is probably what you need to tap into. According to MSDN, you have to register the device, then setup your winproc to accept the WM_INPUT messages and then do your calculations based on the raw data.
Here's another relevant link.