How to get the size in pixels of the Resize Corners of a Window - windows

Is there a way (API) of getting the size (vertical and horizontal) in pixels of the resize corners?
I am referring to the area at each of the corners of a window where you can resize the window in both directions (Left-to-Right and Top-to-Bottom) at the same time using your mouse. You will know you are there with your mouse cursor when you hover over the corners of the window and the mouse cursor is a Diagonal Resizing cursor.
Thank you
Edit:
An example: Hover your mouse over the right edge of a sizable window. Start in the middle (vertically) of the window and move the mouse up along the edge until the horizontal sizing cursor changes to a diagonal sizing cursor. How do I determine by asking the OS how far that position when the cursor changes, is from the top of the window.

I would suggest to use the size of the scrollbars. Call GetSystemMetrics with SM_CYHSCROLL and SM_CXVSCROLL. May be also SM_CYSIZEFRAME and SM_CXSIZEFRAME sizes can be combined.
But I think a better value is to use the height of the status bar. However even Microsoft Windows seems to use some fixed value as can seen on the screenshot.

Comparing the results of GetClientRect and GetWindowRect will tell you how wide the non-client (border) area is along each edge of the window.
If you're concerned that it might not all be active for sizing (true especially along the top), or you want to distinguish the diagonal sizing areas from edge sizing areas, you can take the coordinates discovered in step 1 and pass them to SendMessage(WM_NCHITTEST) See its documentation for the various return codes. There's no problem sending this message repeatedly -- it's designed to be called for each mouse move event and therefore is very fast.

Related

Does UI Automation ScrollPattern have a Bounding Rect or is there a reliable way to get it?

I've been messing around with UI Automation and Scrolling. I found that in notepad if you take the bounding rectangle of the scrollable window, subtract out the size of any scrollbar bounding rectangles, it scrolls perfectly. However, trying the same thing against ISpy++, which aligns the top treeview item perfectly on each scroll even when there may be one or two pixels of the next item in the view at the bottom.
The problem with that is it reports the scroll amount requested was set. Say the view was 6.384914% and you do all the math to calculate where you scroll the view to the next window, say it came out to 24.382102 (completely made up number), so you scroll there, but it really didn't because it aligned the top item which otherwise would be missing a few pixels based on height of window. You read back where scrolling decided to set it and it says it was 24.382102 (note that when the scroll actually moves a full item it does report a different final scroll position and so can be calculated out).
What would solve the above is if we knew the actual bounding rectangle of the view that represents the 6.384914% so that those extra pixels wouldn't be considered part of the view, when you move to the next page, you're now align to where the next page would actually start. In this case of the tree, the bounding rectangle would be aligned to all items that fit plus the final spacing (or that could be part of the top of the view).
I wanted to scroll and get the data perfectly without any overlaps (except on final page of course, but that could be calculated out when you have the proper aligned boundaries that matches scrolling) or extra spacing.
Is there a way to do that, that I'm missing?
TIA!!

DirectX Resize shows win32 background at Edges

When resizing down in DirectX I noticed a flicker along the bottom/right edges.
If you fix the size of the swapchain (in red), and set the win32 background to green you will get the following on a resize down:
It appears that the window size lags behind the mouse position ("Drag Rectangle") but the area DirectX fills (in red and black) matches the Drag Rectangle, with the remainder to be painted with the window background color (green).
The DirectX Utility Toolkit (DXUT) didn't have this problem. Experimenting with their settings I found that setting DXGI_SWAP_CHAIN_DESC::SwapEffect = DXGI_SWAP_EFFECT_DISCARD would just paint the screen green (the window background color) during a sizemove. I assume that DXUT has their own special handling for when win32 enters a modal sizemove loop in order to display DirectX content during a sizemove.
DXGI_SWAP_EFFECT_DISCARD is part of the old blit mode presentation model. Notably it cant have DXGI_SWAP_CHAIN_DESC1::Scaling = DXGI_SCALING_NONE the scaling must be stretched to the window size. So my best guess is this behavior is due to the implementation of the flip presentation model (it flips a rectangle too small (black) and then covers by painting the rest green).
Does anyone know how to stop the win32 background from showing?
Edit:
Thanks to IInspectable! I can confirm the WS_EX_NOREDIRECTIONBITMAP extended style works: it stops the artifact from the win32 background showing
I reproduced the exact same behavior when using CreateSwapChainForComposition() with DirectComposition as I got using CreateSwapChainForHwnd().
This means that there are two path for pixels to get to the screen. The green pixels are going through the Redirection Surface. Hence, explicitly requesting WS_EX_NOREDIRECTIONBITMAP prevents any drawing through a Redirection Surface stopping the win32 background from showing.
The other path is the flip presentation behavior which is how the red and black pixels are get displayed. Hence, not using flip presentation when resizing also stops the win32 background from being shown.
There must be a bug with DWM: when there is a Redirection Surface, the clipping to prevent the swapchain's contents extending past the window is smaller than the redirection surface allowing it to be seen along the bottom/right edges.
There are two observations of interest:
when using WS_EX_LAYOUTRTL or manually positioning a IDCompositionVisual to the right edge of the screen with GetClientRect(), the swapchains contents are correctly position, but still clipped.
when using WS_EX_NOREDIRECTIONBITMAP the window`s nonclient area lines up with the contents of the swapchain rather than the swapchains contents being clipped
These observations would seam to imply that the cause of the issue is that DWM is using it's prefered size for the window size sometimes and the size of the redirection surface othertimes.

Changing size of non-client area in NCCALCSIZE when window is maximized causes flickering when maximizing with Aero Snap only

I'm trying to make a borderless window where the maximized window properly fits the work area of the screen when maximized. This has turned out to be more difficult than I could've ever imagined, and every solution I can find has some sort of downside or glitch that prevents it from being perfect. Some of the glitches are very minor and probably wouldn't be a big deal to most people, but it bothers me.
I know it's possible to do this somehow because I've used a few programs that clearly draw their own non-client area but have proper maximize behavior and appear to be without glitches. Steam and Twitch clients are two examples. However, I have no idea how much code or what sort of tricks they used to get their windows to have that behavior.
Background Info:
When maximizing a window, the window manager positions the window in such a way that the non-client area falls just outside of the visible work area so that the non-client area is not visible when the window is maximized. I remove the non-client area by returning 0 from WM_NCCALCSIZE because I want to be able to draw my own non-client area. The result is that the window manager is trying to account for a non-client area that doesn't exist and my maximized borderless window extends off the screen approximately 7 or 8 pixels in all directions.
What I've tried to fix this:
I've tried handling WM_MINMAXINFO, which doesn't work because the window manager ignores any dimensions passed unless they are smaller than the work area or monitor area. For example, if I subtract 1 from the ptMaxSize.x coordinate, the window fits almost perfectly except there's a 1 pixel transparent space where you can click whatever is behind the window. See this post for more info.
What almost works:
I found this post which contains a solution that almost works perfectly, except that when maximizing the window with Aero Snap, there's a very brief flicker where you can see everything behind the window. This doesn't occur when maximizing the window by double clicking the title bar or using the maximize buttons, even when adjusting the size of the non-client area on maximize. Here's a video that demonstrates the issue.
Video explanation:
First, I maximize the window several times with Aero Snap without the adjustments being made to the non-client area to demonstrate that the maximize transition is flicker-free. Then I show that the window flickers after having adjusted the size of the non-client area on maximizing.
My Question:
Is there a way to prevent the flicker from happening when using this method to fit the maximized borderless window to the work area? Or is there a better way to go about making the maximized window fit the screen? Handling WM_MINMAXINFO seemed like the best hack-free approach, but because of the quirky way windows responds to dimensions that are greater than or equal to the work area, it doesn't seem to work.

How to get the top frame height of a dwm extended and maximized window?

I created a window using dwmextendframeintoclientarea, everything is ok except the top frame height is less than the value I settled while the window is maximized.
So the text drawn using drawthemetext will not align absolutly vertical center as following picture shows.
the first one is the caption bar while the window is normal size, while the second window is maximized.
It is because the height of the top frame actually is less than the value I setted in DwmExtendFrameIntoClientArea.
The problem is how could I get the real height of the top frame while dwm is enable and the window is maximized?
When your application is maximized, Windows actually sizes it slightly larger than the screen. The edges of your window thus extend offscreen, resulting in the rendering you observed. You can use the position and size received in the MINMAXINFO struct in the WM_GETMINMAXINFO message sent to your window to determine just how far offscreen your window extends, and use that to adjust your rendering when maximized.

Determine if a rect is visible inside window

I would like to determine if a rect inside a window is completly visible.
I have found RectVisible, but that function determines if any part of the rect is visible, I want to know if the entire rect is visible.
Is there any function for this?
First get the system clipping region (the visible region of a window) into a region by using GetRandomRgn. Read more about the 'system region' here. Then, offset that region since it is in screen coordinates (the article I linked has an example). After that, create a region from your rectangle with CreateRectRgn and combine the parts of your 'rectangle region' with those that are not part of the 'system region': that is calling CombineRgn passing the rectangle region as the first region, and the system region as the second region, and RGN_DIFF as the fnCombineMode. If the result is NULLREGION then your rectangle is fully visible - it is not fully or partially covered by any window (top level or not), or it is not fully or partially off-screen.
All in all, there's a probability that you're approaching your problem the wrong way around. If you've told what you've been trying to achieve someone could probably suggest a simpler approach.
Use PtVisible on each corner of the rectangle.
The PtVisible function determines
whether the specified point is within
the clipping region of a device
context.
Can you do a simple comparison using the coordinates of the window and the rectangle.
Check the rectangle's left ordinate is to the right of the Window's left border; the right ordinate is to the left of the Window's right border; and similar for top and bottom?
The only wrinkle might be if you are using both logical and physical coordinates, in which case you will need to perform a transformation.
All the functions that dealt with clip rectangles and point visibility broke with Windows Vista's new desktop composition feature. The functions will work fine on Windows XP and earlier, and on Windows 7 with Aero/Desktop Composition turned off, but otherwise, they will always claim that the entire window is visible.

Resources