SetWindowPos not moving or resizing window - c++

When I call SWP to try and move a resize a specific window. It does not move or resize.
SetWindowPos(hWndWindow, NULL, 0, 0, 500, 500, SWP_NOZORDER);
The window handle is valid. I tried both getting the handle with FindWindow and by manually setting the handle value to the window I wanted to resize.
When I use GetWindowPlacement, it says the window is SW_NORMAL and not SW_MAXIMIZE.
The window style is
0x160b0000 (WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_SYSMENU | WS_MINMIZEBOX | WS_MAXIMIZEBOX)
and the extend style is 0x0.
I have also tried setting the window to SW_NORMAL with ShowWindow before calling SetWindowPos.
SetWindowPos and MoveWindow both return non false values saying that they didn't fail.
Why is SetWindowPos and MoveWindow unable to move or resize this window?

Related

WS_EX_LAYERED with SetParent() doesn't show the window

I have this one problem I just can't solve. I'm trying to make a window from my application that is transparent (using flags WS_EX_TRANSPARENT | WS_EX_LAYERED) a child to another window, which is not transparent.
When I don't use the call SetParent( my_window, target_parent_window ) with my_window having the WS_EX_LAYERED flag, the new child window won't be visible.
I found out that a manifest entry could help me, since having a child window with flag WS_EX_LAYERED is supported since Windows 8. I tried it without any success.
::SetWindowLongW( process_window, GWL_STYLE, WS_CLIPSIBLINGS | WS_POPUP | WS_VISIBLE );
::SetWindowLongW( process_window, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW );
::SetWindowPos( process_window, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
::ShowWindow( process_window, SW_SHOW );
::SetParent( process_window, new_parent_window); // if i skip this call the window will render perfectly
https://learn.microsoft.com/en-us/windows/win32/winmsg/window-features
To create a layered window, specify the WS_EX_LAYERED extended window style when calling the CreateWindowEx function, or call the SetWindowLong function to set WS_EX_LAYERED after the window has been created. After the CreateWindowEx call, the layered window will not become visible until the SetLayeredWindowAttributes or UpdateLayeredWindow function has been called for this window.

Win32 programming child window does not have exit button

Hi I am writing a Win32 Windows program. I created a child window with the following command
case ID_VIEW_CARVIEW:
carViewHwnd = CreateWindowEx(WS_EX_TOPMOST, L"Edit", L"Edit",
WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_BORDER,
000, 00, 656, 519, hWnd, (HMENU)NULL, GetModuleHandle(NULL), NULL);
SetWindowLongPtr(carViewHwnd, GWLP_WNDPROC, (LONG_PTR)CarViewWndProc);
However, this child windows has two problems:
It does not have a "close" button on the top right.
It always stay on top of all windows on my desktop top.
How can I change it?
It does not have a "close" button on the top right.
You need set WS_SYSMENU flag for dwStyle parameter to have a window menu on its title bar.
It always stay on top of all windows on my desktop top.
Because you define WS_EX_TOPMOST style: "The window should be placed above all non-topmost windows and should stay above them, even when the window is deactivated."

MFC Add thin border to WS_CHILD window

How can I add border to an embedded child window with (WS_CHILD | DS_CONTROL) style hosed by a CFormView?
I have tried to add border in Dialog Editor by selecting Thin border type but it doesn't work.
I also tried SetWindowLong and ModifyStyle. But the result is, WS_BORDER style is added but still no border.
Is it possible to add border to embedded child window by choosing styles? or should I draw it myself?
Thanks,
Guan
As #IInspectable points out, passing SWP_DRAWFRAME to SetWindowPos is required after changing the window styles.
I finally choose ModifyStyle to add WS_BORDER to my WS_CHILD window and pass SWP_DRAWFRAME flag to the third parameter: m_wndMainPage.ModifyStyle(0, WS_BORDER, SWP_DRAWFRAME). It internally calls SetWindowPos and update the child window. Window border is drawn as expected.

Why HWND_NOTTOPMOST cannot bring the window foreground in xp?

I am using
SetWindowPos(m_hParsent, HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE)
to bring the window foreground, but it does not work in XP System, it work well in my win7.
HWND_NOTOPMOST doesn't move a window to the foreground per-se, it simply removes the topmost status from a window that has it, and a side effect of this is that the window will be left above other non-topmost windows. But the docs also say "This flag has no effect if the window is already a non-topmost window."
Use HWND_TOP to specifically move a window to the top of the z-order, or call SetForegroundWindow.

`SetWindowLong()` function doesn't change window style even after calling `SetWindowPos()`

I create the static control with the code below:
hWnd = CreateWindowExW( 0,
L"STATIC",
Content.c_str(),
SS_LEFT | WS_VISIBLE | WS_CHILD /*| SS_SUNKEN*/,
200,
120,
120,
40,
hWndParent,
NULL,
hInstance,
NULL);
If I enable the SS_SUNKEN style in the creation code above, the created static control appears sunken successfully.
But, what I'm trying to do is the change the control style after its creation.
I tried this:
void BaseWindowClass::AddStyle(DWORD NewStyle)
{
// NewStyle = 0x00001000 = SS_SUNKEN
LONG oldstyle, changedstyle;
oldstyle=SetWindowLongW(hWnd, GWL_STYLE, changedstyle=GetWindowLongW(hWnd, GWL_STYLE) | NewStyle);
UpdateWindowStyles();
// oldstyle = 0x50000000
// changedstyle = 0x50001000 (everything looks normal)
}
void BaseWindowClass::UpdateWindowStyles()
{
BOOL success;
success=SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
// success = 0x00000001 (non-zero: SetWindowPos sucseeded)
}
Documentation:
SetWindowLong()
SetWindowPos()
I call SetWindowPos() after calling SetWindowLongW() because in the documentation of SetWindowLong, it says:
Certain window data is cached, so changes you make using SetWindowLong will not take effect until you call the SetWindowPos function. Specifically, if you change any of the frame styles, you must call SetWindowPos with the SWP_FRAMECHANGED flag for the cache to be updated properly.
And, in the documentation of SetWindowPos, it says:
If you have changed certain window data using SetWindowLong, you must call SetWindowPos for the changes to take effect. Use the following combination for uFlags: SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED.
Even after changing SetWindowLongW() and SetWindowPos() the style of my static control does not change.
What am I doing wrong, or what am I missing?
SS_SUNKEN effectively sets WS_EX_STATICEDGE in the extended styles (GWL_EXSTYLE) window long, so you can update GWL_EXSTYLE appropriately and reposition as you're currently doing.
Even though SS_SUNKEN does affect the frame of a static control, it isn't one of the "frame styles" that note is referring to.
That note refers to generic frame styles that affect all windows like WS_BORDER or WS_EX_CLIENTEDGE - styles that require a recalculation of a window's non-client area when changed.
Many of the system controls cache their styles upon creation and don't update the cache even if you change the styles via SetWindowLong. I would guess that's what's happening here - if you don't create the static control with SS_SUNKEN, you can't add it later. Your best option would be to simply destroy and recreate the control with the new style.