Child Window with Limited Resizing - c

I want to create a child window that takes up all the space of the left side of main window, but its minimum width is 128 pixels. I also want it to be resizable, but only on the right edge, and makes sure that the width stays at the minimum of 128. Creating the child window with these styles: WS_EX_STATICEDGE, WS_SIZEBOX|WS_CHILD|WS_VISIBLE and handling the WM_NCHITTEST message, I can make it only resizable on the right edge. But I can't make it so the minimum width stays at 128. Can somebody tell me how to do this or if there's another window class that takes care of all this?

You must handle the messages which resize the window: WM_POSCHANGING, WM_SIZING, WM_SIZE and WM_POSCHANGED. The most important is to handle WM_SIZING for good user experience.

Related

Snapping window has negative value of Left property

I have an issue where I snap the window to the left and after I close the window I will save the location (Left, Top) along with size of the window. Next time the window is loaded I will try to apply the location and size.
I say try because the window might have been viewed on a screen that has larger resolution so it might not be visible at all on our new screen. What I do is - I see if the window(after I apply location and size) fits in the screen. If it doesn't I will show it on the center and if it does, well it's already where I want it.
My issue is when I snap window to the left. The actual Left property is not 0(zero) but -6.something. I suspect this is because the window has shadow around it so the location must be in minus so the actual form(the one with border) is touching left part of the screen. Because of my logic I will get this screen in the center.
Is there a bullet proof way of determining that the form is snapped to one of the sides?
Is there a bullet proof way of determining that the form is snapped to one of the sides?
No, I don't think so. There is at least no "IsSnapped" property or similar that you can use.
You will have to rely on the Left value and adjust it based on the difference in size between the different screens that are involved I am afraid.

Detecting X11 window resize towards top/left

I'm working on a mapping application and I'm trying to get resizing in X11 working the way I'd like. Conceptually, I'd like my window to be a viewport onto some real-valued space where my data lives. When you resize the window, the size of your view onto this real-valued world should change accordingly.
What this means is that when resizing the window, rather than shrinking/stretching the data, more or less of the underlying window becomes visible. It's easy to handle the case when the window is resized by growing/shrinking on the bottom/right, but I'd like to handle the case when it's resized on the top/left as well.
This is trickier, because a top/left resize also moves the window's origin as well as it's dimensions. I need to detect the change in the origin so that I can compensate to keep my data centered as the window is resized.
Is there a robust way to get the absolute coordinates of a window in X11? The coordinates that X11 reports directly through ConfigureNotify and XWinAttributes are dodgy due to window manager reparenting.
In Xlib use XTranslateCoordinates to translate the coordinate (0,0) in your viewport window into coordinates of the root window. This also covers the case of a stacking window manager messing with your window position.

How can I limit the size of a widget in GTK?

I would like to limit the growth of a GTK text view (controlled by the program, not user) to only the size of its container. When the window resizes, I want it to resize, otherwise I want it to fit where it belongs. It tries to expand horizontally indefinitely instead of wrapping at its current width.
Indeed, you can put your widget into a ScrolledWindow, but beware: this will help only if POLICY is set to POLICY_AUTOMATIC or POLICY_ALWAYS - then ScrolledWindow will request only a minimal amount of space, required to draw its scrollbars.
If POLICY is POLICY_NEVER, ScrolledWindow will request as much size as it child requests, and the toplevel window will grow beyond its normal size. See gtkscrolledwindow.c, comment in the very beginning.
Try to put that textview into a scrolledwindow.

Silverlight child window getting cropped from edges when resizing browser window

I am using ordinary Silverlight ChildWindow in my application. When resizing the browser window, in particular when making its width smaller than that of the child window, the edges of the child window get cropped, so that it is impossible to close it via the close button as it is no more visible. I have tried a number of workarounds but nothing helped. In particular I have subscribed to the SizeChanged event of the child window and set its sizes relative to the layout root's sizes. Here is the code of the SizeChanged event handler:
// Get the dimensions of the application screen
Size appSize = Application.Current.RootVisual.RenderSize;
// Make the child window occupy the 90% of width and 40% of height of the entire screen
this.Width = appSize.Width * 9 / 10;
this.Height = appSize.Height * 4 / 10;
This code modifies the sizes of the child window, but it also updates the sizes of the overlay, so that it no longer covers the whole page, which is a very strange behavior.
Has anyone encountered this kind of problems? Please share any ideas.
Thanks in advance.
I had a similar problem. It occured because scale in a browser was higher than 100%.

Retrieve the entire rectangle of a scrollable window

I'm trying to retrieve the entire rectangle of a scrollable window using the WIN32 API. I thought that GetClientRect would return what I need, but that function appears to return only the current viewport. Is there a specific function call that returns the entire scrollable region as a RECT or must I call GetScrollRange to calculate the region myself?
It doesn't work like that. As far as Windows is concerned, a scrollable window isn't a small viewport onto a larger region whose dimensions you can set or retrieve, it's just a rectangle with a scroll bar control at the edge. It's up to you to determine the appearance of the scroll bar by calculating the portion of the notional region that is visible within the viewport provided by the window, and to paint the window contents accordingly.
It sounds as if that particular window is using virtual scrolling. Even GetScrollRange doesn't necessarily tell you the dimensions, because there's no requirement that a delta of 1 on the scrollbar equals 1 pixel, in fact in many cases it is one record, one row, etc.
Another thing to try is to enumerate all the child windows, and find the minimum and maximum x and y coordinates (don't forget to include the width and height of each child window). Of course this won't help if the content is directly drawn and not a hierarchy of windows.

Resources