Showing a partially visible last line of an edit control? - c

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);

Related

Why Edit Controls inside a Parent Window with WS_CHILD are disabled?

I have created a window with WS_CHILD specified inside CreateWindowEx function, as follows:
HWND newEvent = CreateWindowEx(WS_EX_CONTROLPARENT, NewEventClassName, NewEventTitle,
WS_BORDER | WS_OVERLAPPEDWINDOW | WS_CHILD,
CW_USEDEFAULT, CW_USEDEFAULT,
400, 230, hwnd, NULL, NULL, NULL);
Then, I created an Edit Control inside it:
HWND editCtrlEventName;
editCtrlEventName = CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", L"EVENT_NAME",
WS_GROUP | WS_CHILD | WS_VISIBLE |
ES_LEFT | ES_UPPERCASE, 110, 10, 130, 20,
newEvent, (HMENU)2001, NULL, NULL);
When the window is created, the edit control is created, but disabled inside it and I can't enable the control by any means. I already tried to use EnableWindow() function and similars in my Edit Control, but with no success. However, when I delete WS_CHILD style from newEvent, it works perfectly.
I'm a beginner at winapi programming and this behavior is not clear for me. Is there any problem in creating edit controls inside child windows?
HWND newEvent = CreateWindowEx(WS_EX_CONTROLPARENT, NewEventClassName, NewEventTitle,
WS_BORDER | WS_OVERLAPPEDWINDOW | WS_CHILD,
CW_USEDEFAULT, CW_USEDEFAULT,
400, 230, hwnd, NULL, NULL, NULL);
The mistake in the above code is to combine two styles which are mutually exclusive: WS_OVERLAPPEDWINDOW | WS_CHILD.
WS_OVERLAPPEDWINDOW is a style only for top-level windows, and WS_CHILD of course only for child windows.
Also, CW_USEDEFAULT is not valid for a child window.
Other than that, there shouldn't be any problems creating an edit control as the child window of another child window. Windows itself uses this technique in many places, for instance a combobox has an edit control as child window.

Set Width and Height As 100% For an Edit Control

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.

Strange effect when creating a ListView

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.

Is a StatusBar created in simple mode by default?

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.

Creating a window using CreateWindowEx without an icon

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.

Resources