Use combobox into Listview Items in C++ win32 api - c++

How can I set items of a listview as Combobox in C++ win32 api?
my listview
hWndListView = CreateWindowEx(
WS_EX_CLIENTEDGE,
WC_LISTVIEW,
L"",
WS_VISIBLE | WS_CHILD | LVS_REPORT | LVS_EDITLABELS,
10,
100,
430,
400,
hWndx,
(HMENU)IDC_LIST,
NULL,
NULL);
my combobox
HWND hComboBox2 = CreateWindow(
WC_COMBOBOX,
CMBX_CLASS_NAME,
CBS_DROPDOWN | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE,
10,
50,
300,
300,
hWndListView,
NULL,
NULL,
NULL);
Is it possible?
thank you!

It's not possible with standard ListView common control. You can implement your own control that does what you want by subclassing standard one, and letting it do the painting, and all other functionality. Your customization then will include responding to clicks, hittesting to figure out where click happened (with LVM_HITTEST), creating and displaying combobox, and updating item/subitem with new selection from combobox.

Related

Text box in menu win32 C++

I have a windows app on which when I do a right click a lot of options are shown in the pop up context menu. How can one place an edit text box, in the context menu so that I can type something (and on the change of text box disable few menu items ) . I tried something like this . This doesn't work.
HWND hWndEdit = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("Edit"), TEXT("test"),
WS_CHILD | WS_VISIBLE, 100, 20, 140,
20, NULL, NULL, NULL, NULL);
AppendMenu(MyLocalRightClick, MF_STRING, (UINT)hWndEdit,NULL);

How to get text from a textbox in the Windows API

I've been scratching my head over this for a week now. I'm using the Windows API and I made a textbox with
editBox = CreateWindowEx(WS_EX_PALETTEWINDOW, TEXT("Edit"), NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER | ES_MULTILINE | ES_LEFT | ES_AUTOVSCROLL, 175, 110, 140, 150, hwnd, (HMENU) ID_TEXT, NULL, NULL);
and a button
button = CreateWindowEx(WS_EX_PALETTEWINDOW, "BUTTON", "Ok", WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 175, 260, 140, 20, hwnd, (HMENU) ID_BUTTON, NULL, NULL);
and I want to be able to click the button and it store what was typed into editBox in a primitive string. Examples are preffered but links and documentation are also very much appreciated! :)
You can use the GetWindowText API function to get the text of an edit control.
For a window with title this function retrieves the title. For an edit control it retrieves the edit control's text. Just ignore any documentation saying that you're limited to 64K or so, if you encounter it (it was once that way).
To detect the button click, process the WM_COMMAND window message in your window procedure; it's sent to the parent window of the button. There is a more sophisticated approach based on reflecting the message back to button, which can then process it itself, and that approach is used in most higher level frameworks. But at the API level, just check WM_COMMAND in the parent window's window procedure.

WinApi : Add style to combo box

I'm trying to add CBS_OWNERDRAWFIXED style to an existing combobox , my code doesn't work and I have no idea why .
I suspect maybe the expression oldStyle | addedStyle is not valid , but I can't figure out why.
HWND hwnd = CreateWindow(
L"ComboBox",
L"",
WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST ,
200,
200,
200,
200,
parentHandle,
(HMENU)1,
GetModuleHandle(NULL),
NULL);
auto comboBoxStyle = GetWindowLongPtr(hwnd, GWL_STYLE);
comboBoxStyle = comboBoxStyle | CBS_OWNERDRAWFIXED;
SetWindowLongPtr(hwnd, GWL_STYLE, comboBoxStyle);
the output is just regular combobox , without any change.
This particular style can only be specified at creation time. The documentation alludes to this when it says:
CBS_OWNERDRAWFIXED
Specifies that the owner of the list box is responsible for drawing its contents and that the items in the list box are all the same height. The owner window receives a WM_MEASUREITEM message when the combo box is created and a WM_DRAWITEM message when a visual aspect of the combo box has changed.

Richedit Msftedit strange border

I get really strange behavior when I use more than one RichEdit control:
LoadLibrary("Msftedit.dll");
RichEdit = CreateWindow("RICHEDIT50W", "", ES_READONLY | ES_MULTILINE | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP, 5, 370, 600, 300, hwnd, NULL, NULL, NULL);
RichEdit2 = CreateWindow("RICHEDIT50W", "", /*0x550081C4*/ 0x50810804, 610, 65, 600, 300, hwnd, NULL, NULL, NULL);
The first EditControl works as it should, however the second one has some strange border around it.
First I tried to use the same styles as for the first richedit, then I found out the style using Spy++.
Even if I have the same styles, I get different results, probably the same as if I used WS_EX_CLIENTEDGE extended style for the second richedit.
I even tried to free the library and load it again, but with the same result.
Thank You all in advance!
So I figured it out. I have no Idea why, but the second RichEdit is somehow getting the WS_EX_CLIENTEDGE style after is created, so I simply remove the style like so:
LONG lExStyle = GetWindowLong(RichEdit2, GWL_EXSTYLE);
lExStyle &= ~WS_EX_CLIENTEDGE;
SetWindowLong(RichEdit2, GWL_EXSTYLE, lExStyle);
Now the RichEdit looks the same as the first one. But I have really no idea, where the style comes from.

Change button style on the fly in Win32

Below is part of a working normal win32 application created from scratch, not dialog based. it will show the text on the buttom, not top:
hButtonApply = CreateWindow(
"BUTTON",
"Reset",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_BOTTOM,
95, 130, 120, 40,
hWnd, (HMENU)IDC_BUTTON_RESET, hInstance, NULL);
SendMessage(hButtonApply, BM_SETSTYLE, BS_TOP, TRUE);
this however makes it a radio button:
SendMessage(hButtonApply, BM_SETSTYLE, BS_RADIOBUTTON, TRUE);
same for a resource-defined dialog button control.
Subclassing is acceptable. Owner-Drawn Buttons are not acceptable. Thanks, Haotian Yang
Some window styles can only be set during CreateWindow, I guess this might be one of them.
Did you try SetWindowLong ?
Edit:
This seems to work:
LONG style = GetWindowLong(hBtn,GWL_STYLE);
style = (style & ~BS_BOTTOM) | BS_TOP;
SetWindowLong(hBtn,GWL_STYLE,style);