'How do I create a normal win32 edit control?
I'm trying to create an edit control with the regular 3D border around it (in the classic windows style, anyway), but it just has a 1px black border around it. Here is my CreateWindowEx call:
return CreateWindowEx(0, "EDIT", "E:\\bk",
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
87, 81, 150, 17,
main_window.hwnd,
(HMENU)5, hInstance, NULL);
If I exclude WS_BORDER then it's just a white box. Any ideas on what's wrong here?
Update
WS_EX_CLIENTEDGE did the trick.
I don't know anything about manifest files, or how to make the window use the more modern windows themes (XP, for example), instead of the chunky 3D borders. But, when I do learn all that, will WS_EX_CLIENTEDGE make them use those themes instead, or will it enforce the 3D look?
Solution 1:[1]
Try using WS_EX_CLIENTEDGE. That will create an inset 3-D window border under typical situations.
return CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "E:\\bk",
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
87, 81, 150, 17,
main_window.hwnd,
(HMENU)5, hInstance, NULL);
Also see the following link for the rest of the available flags for CreateWindowEx.
Solution 2:[2]
He is right WS_EX_CLIENTEDGE will do the 3D border.
Solution 3:[3]
I think you mean the 'WS_EX_DLGMODALFRAME' style. It makes it look like the old-style 3d raised type look. Combined with 'WS_BORDER' to make it look a like a 3d border around the control.
Solution 4:[4]
Below code Creates an input box and a button, when clicked updates title.
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int main() {
HINSTANCE hInstance;
MSG msg;
WNDCLASSW wc = {0};
wc.lpszClassName = L"Edit control";
wc.hInstance = hInstance;
wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wc.lpfnWndProc = WndProc;
wc.hCursor = LoadCursor(0, IDC_ARROW);
RegisterClassW(&wc);
CreateWindowW(wc.lpszClassName, L"Edit control",
WS_OVERLAPPEDWINDOW | WS_VISIBLE, 220, 220, 280, 200, 0, 0,
hInstance, 0);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
static HWND hwndEdit;
HWND hwndButton;
switch (msg) {
case WM_CREATE:
hwndEdit = CreateWindowW(L"Edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER,
50, 50, 150, 20, hwnd, (HMENU)102, NULL, NULL);
hwndButton = CreateWindowW(L"button", L"Set title", WS_VISIBLE | WS_CHILD,
50, 100, 80, 25, hwnd, (HMENU)103, NULL, NULL);
break;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED) {
int len = GetWindowTextLengthW(hwndEdit) + 1;
wchar_t text[len];
GetWindowTextW(hwndEdit, text, len);
SetWindowTextW(hwnd, text);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
To compile:
g++ test.cpp -o test.exe -mwindows
source: zetcode.com/editcontrol
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | meklarian |
| Solution 2 | Kornalius |
| Solution 3 | Shane Powell |
| Solution 4 | A5H1Q |
