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.
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);
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.
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.
Can anyone give me an example code for a tool window (with pixel dimensions) for the Win32 API?
Thanks
Tool windows are just windows with the WS_EX_TOOLWINDOW extended style:
hWnd = CreateWindowEx(WS_EX_TOOLWINDOW, szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 100, 100, 500, 400, NULL, NULL, hInstance, NULL);
Note you need to use CreateWindow*Ex* to use extended styles. The above is a 500x400 window at 100,100 on the screen.
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.