When a StatusBar is first created, for example:
HWND hStatusBar = CreateWindowEx(0, STATUSCLASSNAME, "", WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hWnd, 0, GetModuleHandle(NULL), NULL);
Is it created in simple mode or in multiple-part mode? or maybe this is not guaranteed and it is better to set the mode I want after creating it?
Status bars are created, as you have done, with a call to CreateWindowEx. When a status bar is first created it has no parts. Parts are added to status bars by sending a SB_SETPARTS message to the status bar.
Is it created in simple mode or in multiple-part mode?
Simple mode without parts.
Is it better to set the mode I want after creating it?
Parts can only by specified after the window has been created.
Related
I'm noticing that standard edit controls are not showing the last line of text if it's not fully visible. Is there a way to override this behavior? If not, is there an equivalent solution to an edit box that does? Preferably in "pure" Win32 API fashion, as I am not using MFC or ATL. This is how I define the edit control at the moment:
CreateWindow(L"EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE, 0, 0, 0, 0, hWnd, (HMENU)ID_EDIT_CONTROL, hInst, NULL);
How do I make an Edit Control have its width and height as 100% of the window.
A good example of this is the Edit Control in Notepad.
Up till now, I've been setting the size of controls in the CreateWindow() function as static integers.
e.g.
CreateWindow("EDIT", NULL, WS_CHILD | WS_VISIBLE,
0, 0, 640, 480, hWnd, NULL, NULL, NULL);
I am using C and Visual Studio 2015.
Thanks in advance.
You have to handle WM_SIZE messages in your main window procedure and use SetWindowPos API call to resize an edit control.
I have noticed a strange effect when I create a Listview.
When I create a ListView without also creating a Button, the selected item in the ListView have a dotted border. However, when I also create a Button, the ListView selected item don't have a dotted border anymore. This only happens when I have a manifest file that enables common controls 6:
This is the code I used to create the Window and ListView and Button:
// Create Window
HWND hWnd = CreateWindowEx(0, "WinClass", "My Window", WS_OVERLAPPEDWINDOW, 261, 172, 394, 284, NULL, NULL, hInstance, NULL);
// Create ListView
HWND hListView = CreateWindowEx(0, WC_LISTVIEW, "", WS_CHILD | LVS_REPORT | WS_VISIBLE, 0, 0, 232, 190, hWnd, 0, GetModuleHandle(NULL), NULL);
// Create Button
HWND hButtonRefresh = CreateWindowEx(NULL, "BUTTON", "OK", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 10, 200, 110, 25, hWnd, NULL, GetModuleHandle(NULL), NULL);
Note: I don't have a problem with this effect, I just want to understand why it is happening!
It's just because the button has the focus and the list view lost it, click on the list view and the dots should reappear.
I believe the dotted border is indicating the default control. In the second screenshot go to the Properties of the button and set Default Button to false and then you should see the dotted border around the text like in the first screenshot.
To do this open the dialog in Resources view, select the button and choose Properties from the right-button mouse menu. In the Properties window you should see Default Button in the Behavior section - just change it to False.
Alternatively in code try something like this:-
DWORD style = m_BtnOk.GetStyle();
// remove default push button style
style &= ~BS_DEFPUSHBUTTON;
// set the style
::SendMessage(m_BtnClose.GetSafeHwnd(), BM_SETSTYLE, (WPARAM)style, (LPARAM)TRUE);
As others have indicated, it's purpose is to indicate input focus. If you Tab around any native form, you'll see the rectangle jump around the indexes set up by the developer.
The reason it appears at all is because it has a TabStop. As there is only one element in the first example, there's only one possibility for a tab stop, so it's indicated by the rectangle. Play around with the TabStop property, Tab around, see what changes.
How can I do that?
The following seems to work:
CreateWindowEx(WS_EX_TOOLWINDOW, szToolWndClass, "Title",
WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 240, 320,
hWnd, NULL, hInstance, NULL)
But this doesn't (the window is not displayed):
CreateWindowEx(WS_EX_TOOLWINDOW, szToolWndClass, "Title",
WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 240, 320,
hWnd, (HMENU) IDD_TOOL, hInstance, NULL)
However, it works when I add the WS_CHILD style, but that doesn't create a floating window.
Top-level windows use the ID slot as the HMENU (or rather, child windows use the HMENU slot as the control ID); so child windows can't have HMENUs, and top-level HWNDs can't have IDs.
What's likely happening is that when you omit WS_CHILD, windows treats the ID as a HMENU, and since it's not a valid HMENU, fails the CreateWindow call.
Generally speaking, an ID only makes sense in the context of a known container. So in the context of a dialog, IDs make sense, because the dialog owns the controls in it, and the author can ensure there's no duplicates - and GetDlgItem will do something sensible.
But on the desktop, every window is from a different source, so there would be no way to ensure unique IDs, so the concept wouldn't really make sense there anyhow.
Your best bet is perhaps to save away the HWND itself, and use it directly when needed.
One thing to be aware of is that when you don't use WS_CHILD, your new window is actually a child of the desktop window, but is owned by the HWND you pass in, it's not a child of that window. Enumerating the child windows of that owner window will not return your new window.
Raymond Chen (who's blog should be considered required reading for all Win32 devs) has a good explanation of the parent vs owner issue here.
With C#, I was easily able to get the effect I wanted:
However, I'm having trouble doing the same thing using the Win32 API in C. I don't know how to create a window that has no icon (at all), but still has a caption, a minimize button, and a close button.
I registered my class properly, but I can't figure out what to put for the window styles/extended window styles.
static const TCHAR lpctszTitle[] = TEXT("Stuff"), lpctszClass[] =
TEXT("StuffClass");
HWND hWnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TOPMOST, lpctszClass,
lpctszTitle, WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX,
CW_USEDEFAULT, 0, 250, 55, NULL, NULL, hThisInstance, NULL);
The code above produced:
which still has an icon in the title bar and is not what I wanted.
A standard window requires an icon because it needs some form of representation in the taskbar at the bottom of the screen. What should be displayed when you press Alt+Tab in the window switcher if one of the main windows doesn't have an icon?
You need to specify the WS_EX_DLGMODALFRAME extended style. This is the same effect that WinForms sets when you turn off the icon in the title bar.
You also need to make sure that you do not specify an icon when you register the window class. You need to set the hIcon and hIconSm fields of the WNDCLASSEX structure to 0.
Change your code to the following:
static const TCHAR lpctszTitle[] = TEXT("Stuff"), lpctszClass[] =
TEXT("StuffClass");
HWND hWnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TOPMOST, lpctszClass,
lpctszTitle, WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX,
CW_USEDEFAULT, 0, 250, 55, NULL, NULL, hThisInstance, NULL);
On a side note, use Spy++ or other similar tool to see the styles that any given HWND actually uses. Point it at your C# window, then duplicate the reported styles in your C code.