This is simple. I created an EDIT control like this:
HWND MYTEXT= CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", L"",
WS_CHILD|WS_VISIBLE|ES_LEFT|ES_MULTILINE,
20, 120, 150, 20, hWnd, NULL, hInst, NULL);
but when I type text inside of it I can't type more text than the width of the EDIT control. When I reach the end it's like there's no more space and I get a beep. How can I make the text scroll in this situation?
You can give your edit control the WS_HSCROLL and/or WS_VSCROLL window styles. For instance:
HWND myText
= CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", L"",
WS_CHILD | WS_VISIBLE | WS_HSCROLL | ES_LEFT | ES_MULTILINE,
20, 120, 150, 20, hWnd, NULL, hInst, NULL);
Alternately, as Matthew T. Staebler rightfully suggests, use ES_AUTOHSCROLL and/or ES_AUTOVSCROLL (note the ES_ prefix, as these are edit styles, not window styles).
Related
I create a textbox on a win32 gui app. Later on I'm trying to set a text to it but newline "\n" isn't working when using SetWindowText
g_ButtonManager.hWndThirtyText = CreateWindowExW(WS_EX_CLIENTEDGE, TEXT("Edit"), TEXT(""),
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE,
10, 95, //x,y
200, 60, //width, height
hWnd, (HMENU)IDM_THIRTYTEXT, NULL, NULL);
Even though I:
SetWindowTextA(g_ButtonManager.hWndThirtyText, "Hello\nThere");
It displays HelloThere in the same line.
---Edit
Even with | ES_WANTRETURN
g_ButtonManager.hWndThirtyText = CreateWindowExW(WS_EX_CLIENTEDGE, TEXT("Edit"), TEXT("Hello\nMy\nFriend"),
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE | ES_WANTRETURN,,
10, 95, //x,y
200, 60, //width, height
hWnd, (HMENU)IDM_THIRTYTEXT, NULL, NULL);
Will not work.
Oh, I figured it.
\r\n is required for a newline.
I am trying to modify the color of items in my Listbox.
I use WinApi C++ in Visual Studio 2017.
To create my listbox, I wrote that code:
hListbox = CreateWindowW(L"Listbox", L"My Listbox", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP | WS_BORDER | LBS_EXTENDEDSEL, 100, 60, 300, 2400, hWnd, NULL, NULL, NULL);
Add the items:
SendMessage(hListbox, LB_ADDSTRING, NULL, (LPARAM)Text); (...)
Is it possible to change the color of the text or the background, without changing the type of my object? Or is there an other easy way to create a listbox with colored items?
I'm showing text on a:
hWndText = CreateWindowEx(WS_EX_CLIENTEDGE,
"Edit", cquestions.at(1).c_str(), WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
10, //x
10, //y
TextFieldWidth, //width
100, //height
hWnd, NULL, NULL, NULL);
(cquestions is a std::vector<std::string>). Although the result is shown below.
I've tried inserting "\n" to it but it won't work.
How can I make it so the text will wrap?
You need the ES_MULTILINE style to make an edit control display more than one line of text.
i created a edit box but it doesn't show on the window. it shows if the window is not full screen. if it is full screen the edit box goes behind it. here is the function for the edit box
HWND editbox=CreateWindowA("EDIT", NULL,
WS_VISIBLE | WS_EX_TOPMOST | WS_BORDER | ES_LEFT,
87, 81, 150, 17,
hWnd,
(HMENU)5, hInstance, NULL);
i don't know why it does that i set it to WS_EX_TOPMOST and it still goes behind it. i used directx 9 to make my program in full screen
All WS_EX_** styles should be passed as the first argument of CreateWindowEx, not the third of CreateWindow. This probably causes the problem. Use CreateWindowExA instead.
All the arguments in CreateWindowEx remain the same, there's just one additional parameter at the beginning.
HWND editbox=CreateWindowExA(WS_EX_TOPMOST, "EDIT", NULL,
WS_VISIBLE | WS_BORDER | ES_LEFT,
87, 81, 150, 17,
hWnd,
(HMENU)5, hInstance, NULL);
EDIT: I know what was wrong. You forgot the WS_CHILD style in the third argument. It is needed so Windows knows that this is a child window.
HWND editbox=CreateWindowA("EDIT", NULL,
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
87, 81, 150, 17,
hWnd,
(HMENU)5, hInstance, NULL);
HWND editbox=CreateWindowA("EDIT", NULL,
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
87, 81, 150, 17,
hWnd,
(HMENU)5, hInstance, NULL);
WS_CHILD is required if you want to display the new control atop a window...
How do I capture key presses when a list view control has focus?
My window creation code looks like
// Window creation
HWND hwnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_APPWINDOW, g_szClassName, "Test", WS_VISIBLE | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_POPUP | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 209, 351, 0, 0, hInstance, 0);
HWND hwnd_list = CreateWindowEx(0, WC_LISTVIEW, "", WS_BORDER | WS_VISIBLE | WS_CHILD | WS_TABSTOP | LVS_REPORT | LVS_SINGLESEL | LVS_NOCOLUMNHEADER | LVS_EX_FULLROWSELECT, 1, 246, 201, 55, hwnd, (HMENU)IDL_LISTVIEW, hInstance, 0);
Inside WndProc I process the WM_KEYPRESS message and create a MessageBox displaying the virtual code, but its only triggering when I press keys after clicking outside the list view.
You'll need to take a look at control subclassing, http://msdn.microsoft.com/en-us/library/bb773183%28VS.85%29.aspx.
If you're using MFC, it's a bit less painful. (Back in the day when Borland was still alive, it was a breeze in OWL, but that's ancient history.)
You need to subclass the listview proc and then use 'WM_KEYDOWN' to capture the input.