I have a CPropertySheet.
When I use
ModifyStyle(DS_MODALFRAME, WS_POPUP | WS_THICKFRAME | WS_MAXIMIZEBOX);
inside an OnCreate handler everything is fine. The created window behaves as expected and is resizable.
When I use the same code, just a tick later in CPropertySheet::OnInitDialog than this code has only the effect that the correct frame is shown, also the cursor changes when I drag over the window border. But there is no resize feature.
Same happens for a CDialog when uses in OnInitDialog. Seams that some flags can't be changed after a window is created.
Is there more information about this problem?
You need to set the nFlags parameter to SWP_FRAMECHANGED and maybe also SWP_DRAWFRAME in your call to ModifyStyle. This way it will call SetWindowPos internally, which will apply the new style. You also need to remove WS_SYSMENU instead of DS_MODALFRAME.
Example:
ModifyStyle(WS_SYSMENU, WS_POPUP | WS_THICKFRAME | WS_MAXIMIZEBOX, SWP_FRAMECHANGED);
Related
I want to make a window created with
CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_LAYERED, wc.lpszClassName, 0, WS_POPUP | WS_VISIBLE | WS_SYSMENU, ...);
a part of the desktop. (I know this may be impossible, but I want to get as close as possible to this feeling).
Thus, I need that when WIN+D is hit (or when bottom-right of the screen Show desktop button is clicked), the window should not be hidden.
How to prevent the window to be hidden when showing desktop with WIN+D?
Note: I initially thought it was possible by preventing the window to be minimized
(https://stackoverflow.com/questions/27781352/prevent-window-to-be-minimized?noredirect=1#comment43975051_27781352) but as pointed by some users, it seems
that it is another problem.
It is possible to make the window part of the desktop by doing:
HWND hwndOwner = GetWindow(GetWindow(GetTopWindow(0), GW_HWNDLAST), GW_CHILD);
SetWindowLong(hwndMain, GWL_HWNDPARENT, (LONG) hwndOwner);
Also try another test: http://files.rsdn.ru/42164/quasi_owner.zip (exe + sources, tested on Win7-x86).
1st version (not really working):
It is enough remove WS_MINIMIZEBOX & add WS_EX_TOPMOST
I have a button which is created in the WM_CREATE function of a Win32 Application with the following code:
hChangeWorldButton = CreateWindowEx(NULL,
"BUTTON",
"OK",
WS_CHILD | WS_VISIBLE | BS_FLAT | BS_BITMAP,
2,
2,
25,
25,
hWnd,
(HMENU)CHANGEWORLD_BUTTON,
GetModuleHandle(NULL),
NULL);
SendMessage(hChangeWorldButton, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)worldBmp);
I would like the button to show only the image. Not the background and border.
How can I do this? I have tried many different button styles from MSDN but nothing seems to fit my needs. I was thinking of using BS_OWNERDRAW but it seems a bit overkill. Or is it the only solution?
Finally, how can I change the cursor to be a hand when it's hovering over the button?
No button style is available that results in the visual representation you are after. You would have to go with BS_OWNERDRAW here.
As an alternative you could use a Static Control with the SS_NOTIFY style instead. A static control allows you to get the visual representation you want, and the SS_NOTIFY styles allows you to respond to mouse input. However, you will not be able to implement a keyboard interface.
While I have not tried this myself, it may also be possible to get the desired effect by using a Command Link (BS_COMMANDLINK), and setting the caption to an empty string.
To eliminate the button's background and border simply make the button smaller than the bitmap.
I've created a simple window with:
CreateWindowExW(
WS_EX_TOPMOST,
L"RichEdit20W",
L"window_text",
WS_OVERLAPPEDWINDOW | WS_BORDER | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE //...
now every time I hange "window text" parameter, both control and window title is changing, the same with SetWindowTextW() and SendMessageW(hwnd, WM_SETTEXT, ...).
Edit controls (and rich edit controls) are not really designed to have "titles" as such. It is quite unusual to use a control as a top-level window. Instead, you should register your own window class to use for the top-level window (which can then have its own caption text) and make the edit control a child window.
I have an application that compiles ok (mingw) and runs ok, however the edit control that is created has scroll bars but the vertical scroll bar doesn't do anything. The same executable works fine on WinXP. Also, the edit control has both vertical and horizontal scroll bars, the horizontal works just fine, but vertical does not. The vertical scroll bar is visible and clickable, but nothing happens...
Following code is used when creating the edit control:
HWND hwndEdit = CreateWindow(TEXT("EDIT"), TEXT("Edit control"),
WS_OVERLAPPED | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_LEFT | ES_MULTILINE |
ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_READONLY | WS_SIZEBOX,
1000, 480, 400, 500, NULL, 0, GetModuleHandle(NULL), NULL);
SendMessage(hwndEdit, WM_SETTEXT, 0, (LPARAM) TEXT(""));
SendMessage(hwndEdit, EM_LIMITTEXT, 0, 0);
Following code is used repeatedly to add text to edit control:
char test[] = "test";
SendMessage(hWndDbg, EM_SETSEL, 0x7FFFFFFF, 0x7FFFFFFF); // Undo any selection and move to end.
SendMessage(hWndDbg, EM_REPLACESEL, 0, (LPARAM) temp);
Finally found the fix. It seems in WinXP the edit control does not have to have a parent window defined, in Win7 it is required for the vertical scroll bar to work, horizontal scroll bar works in Win7 even without parent window defined.
Note that vertical scroll bars even make sense on single-line edit controls. In this case, WM_VSCROLL must be set, and ES_AUTOVSCROLL not. (EM_AUTOVSCROLL means EM_AutoHIDEVScroll.) The alternative UpDown control makes more programming efford than capturing VM_VSROLL messages, and then changing the (typically numerical) value inside the edit control.
Unluckily, the MS Visual Studio built-in Resource Editor won't let you add WM_VSROLL to single-line edits! You must do this by adding this bit by editing the .RC file in text mode.
Similar to the fact that this Resource Editor won't let you add a default text to the control, which is still supported by the resource loader.
Use GetDesktopWindow() as hWndParent parameter. It works on Win7.
I've got an application window in which I'm adding the WS_THICKFRAME style and I have removed the WS_CAPTION style. When the window maximizes, I want to hide the WS_THICKFRAME, but retain the Aero-Snap feature, so I have altered my handler for WS_NCCALCSIZE to return an inflated rect with respect to the size of the window borders.
That is, the important part of the WS_NCCLIENTSIZE handler code looks like this:
...
CRect rc( lpncsp->rgrc[0] );
if (IsZoomed())
{
int borderSize = GetSystemMetrics(SM_CYSIZEFRAME);
rc.InflateRect(borderSize,topOff+borderSize,borderSize,borderSize);
}
else
rc.InflateRect(0,topOff+0,0,0);
lpncsp->rgrc[0] = rc;
...
That code effectively makes the WS_THICKFRAME hidden.
Only problem is that when the window loses focus or regains focus (while maximized) the WS_THICKFRAME gets drawn within the boundary. Is there a message in which I can return the Inflated rect back or at least re-adjust the window size to hide the WS_THICKFRAME again when the window focus is set/unset?
Yeah, that won't work. Implement a message handler for WM_GETMINMAXINFO to allow the borders of the window to fall off the screen. Beware that if you didn't set the linker's /SUBSYSTEM option to say that your program is made for Vista or Win7 (version 6,0) then Aero will lie to you when you use GetWindowRect(). The value you get back is based on thin (legacy) borders.