MFC: limit the size of child control from the code of control itself - winapi

Say, I have a CListCtrl-derived control. I want it to be always square (i.e. it's width and height should be always equal to each other).
The control resides on a dialog (CDialog-based), it is resized once the dialog is resized (the control is resized using SetWindowPos()). What I want to achieve is to make it impossible to resize the control improperly: the control must always have equal horizontal and vertical dimensions regardless of what is passed to SetWindowPos.
Of course, I can control the values that are passed to SetWindowPos. The question is: is it possible to control the size of the CListCtrl-derived control inside the code of that control itself?

If you subclass the control and have it handle the WM_SIZING message you can constrain the resize in any way you'd like. Just modify the RECT structure that's passed with the message.

Related

Resizing UWP Window on User Drag

I am trying to change the size of the UI Elements within a UWP Window on the change of the size of the window itself, such as clicking the edge of the window and dragging right. However, on increase of size, there seems to be Bounds set on the creation of the Window for the maximum size of the content, is there anyway to bypass this Bounds?
Try setting the UI Element's HorizontalAlignment and/or VerticalAlignment to "Stretch". Alternatively, if you want to scale it too, you may put the whole thing in a ViewBox. There are really quite a few options to achieve what you want.

Glade 3.18 + GTK3 - Make children keep internal size

So i have a GUI with a toplevel GtkWindow that has alot of boxes and windows beneath it. See image below
the problem is when a user resizes window1 (downwards) , the bottom element, i.e statusbar2 only enlarges and fills up the rest of the available area.
The notion of a status bar is that it should be always the same size, like 80 px of height. What I want to do is that when a user resizes the window, the internal components stay the same relative height and width. Atleast the status bar. So when i drag down to enlarge, the box3 item should only enlarge. The statusbar2 should "hook" onto the bottom edge of the window and stay the same size.
This must be doable surely?
If you need the glade file, I might be able to upload it
Any help is appreciated!
Regards
You'll want to set the status bar's vexpand property to False, and set the vexpand property to True of whatever widget(s) you would like to absorb the extra space.

How do I make a WrappingTextField fill the entire Window?

I have a Window and a WrappingTextField.
I want the WrappingTextField to always fill the entire Window. Even when the user is resizing the Window, and when it is in full screen.
No matter which options or constraints I choose in Auto Layout, it only resizes with the Window horizontally, but its height remains the same, even if the height of the Window grows.
How do I make it fill the entire Window, and stay that way?
By WrappingTextField I'm assuming you mean an a standard NSTextField object with it's Layout set to Wraps within Interface Builder.
The resizing behaviour of an NSTextField is influenced by its Content Hugging Priority. By default Interface Builder sets this at 750 for the control's Vertical dimension, and this is probably what's preventing your text field from resizing the way you want it to. Give it a smaller value - like say 100 - and the problem should resolve.

MFC grid is absolute layout and gets clipped during window resize

Using visual studio C++ 2010.
Currently in a window in MFC code I have a grid. I want the grid to "become smaller" if I resize the window (drag the corners manually), but as I resize the window the grid actually is completely static, so e.g. resizing the window to a very small size will cause the edges of the grid to become outside of the window's visibility.
I noticed that the other "objects" within this window (notably, the MFC buttons I have such as "cancel") do scale with the window and don't go out of sight when I resize the window to a smaller size. They follow the window's edges as if they were given smart relative coordinates instead of absolute coordinates that my grid follows.
Currently I am using the grid here http://www.codeproject.com/Articles/8/MFC-Grid-control-2-27 although I highly suspect it is not the source of the problem (there is an example code that uses it, and the resize behaves as expected; I cannot compile it but I ran the exe example). I recently switched from MSFlexGrid (because it doesn't support 64 bit) but in the previous version when I used to use MSFlexGrid, it didn't have this problem either.
I thought it might be some sort of window property or object property in the .rc file but I compared the files and found no leads.
There is no such a thing like a window property that tells window to adjust the size to the size of the parent.
If buttons change size and position, you are probably using some kind of class that takes care of resizing of the child controls.
Follow the same for your grid, or notify grid about the parent size change and adjuxt grid size accordingly.

Place a window behind any other existing third party window

In order to take a screenshot of a specific window, I need to place a white colored TForm behind that window. What Windows API could I use to change the z-order of my window and place it correctly ?
Try the SetWindowPos() function.
On Delphi you can useSendToBack method, .Top and .Left properties.
form1.Top := ...;
form1.Left := ...;
form1.SendToBack;
procedure SendToBack;
Description
Use SendToBack to change the order of
overlapping controls or forms.
The order in which controls stack on
top of each other (also called the Z
order) depends on the order the
controls are placed on the form. For
example, if you put a label and an
image on a form so that one is on top
of the other, the one that was placed
first on the form becomes the one on
the bottom. Because both the label and
the image are non-windowed controls,
they "stack" as you would expect them
to. Call the SendToBack method for the
top object to move it below the other
object.
The stacking order of two windowed
controls is the same as the stacking
of two non-windowed controls. For
example, if you put a memo on a form,
then put a check box on top of it, the
check box remains on top. Calling
SendToBack for the check box makes the
memo appear on top.
The stacking order of windowed and
non-windowed controls cannot be
mingled. For example, if you put a
memo, a windowed control, on a form,
and then put a label, a non-windowed
control, on top of it, the label
disappears behind the memo. Windowed
controls always stack on top of
non-windowed controls. In this
example, calling the SendToBack method
of the memo does nothing, the label
remains behind the memo.
If the control has the input focus
when the SendToBack method executes,
it loses the input focus.
(Edit: WinSnap is a very good utility for taking and editing screenshots)
If you can get the handle of the window you want in front then I would assume that:
Pseudo Code:
MyAppWindow.BringToFront
followed by
TargetWindow.BringToFront
Should have the desired effect, yes?

Resources