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...
Related
Sorry for this noob question but i'm new to C++ (coming from C#). I have a list of items from an array that i want to display on a listbox (just do display - nothing else). Adding a control in c++ was a lot harder than i thought.
Here's what i have so far: I'm not sure how to proceed from here and how to get it to work. Thanks in advance.
// .rh file
#define IDC_LISTDIR 106
//in the .rc file
CONTROL "ListBox", IDC_LISTDIR, "listbox", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_AUTOHSCROLL | WS_GROUP, 8, 80, 200, 60
//main
SendMessage(HANDLE, LB_ADDSTRING, 0, (LPARAM)L"Add This Text to listbox");
Also, i'm getting this:
error C2275: 'HANDLE' : illegal use of this type as an expression
IDD_MAINWINDOW DIALOG 36, 54, 421, 252
EXSTYLE WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE
CAPTION "Listbox Test"
FONT 9, "MS Sans Serif"
{
CONTROL "&OK", IDOK, "button", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 100, 5, 40, 14
CONTROL "&Cancel", IDCANCEL, "button", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 100, 30, 30, 14
CONTROL "CheckBox", IDC_YESNO, "button", BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_GROUP, 9, 55, 77, 22
CONTROL "ListBox", IDC_LISTDIR, "listbox", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_AUTOHSCROLL | WS_GROUP, 8, 80, 200, 60
}
SendMessage() takes an HWND to send the message to. HANDLE is a type, not an HWND variable. You need the actual HWND of the ListBox at runtime. Use GetDlgItem() to get that, eg:
HWND hwndLB = GetDlgItem(hwndDlg, IDC_LISTDIR);
SendMessage(hwndLB, LB_ADDSTRING, 0, (LPARAM)L"Add This Text to listbox");
Where hwndDlg is the HWND of the window that the ListBox is a child of.
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 want to change the text that appears on a window. I seem to be able to do it okay but it messes up the area around it and hides the other text. Am I doing it the wrong way perhaps?
So I initialise the variables like this:
static wchar_t socketstatText1T[256];
static wchar_t socketstatText2T[256];
static HWND socketstatText1;
HWND socketstatText2;
I create my text windows like this:
socketstatText1 = CreateWindowW(L"Static", L"Not Connected",
WS_CHILD | WS_VISIBLE | SS_LEFT,
310, 50, 200, 130, hwnd, (HMENU) 0, NULL, NULL);
socketstatText2 = CreateWindowW(L"Static", L"Inactive",
WS_CHILD | WS_VISIBLE | SS_LEFT,
310, 80, 200, 130, hwnd, (HMENU) 0, NULL, NULL);
And then I edit the text like this:
wcsncpy(socketstatText1T, L"Connected to socket", 18);
SetWindowTextW(socketstatText1, socketstatText1T);
This is the same way I change text for a text area and I've had no issues. I've also read that it works the same on text windows. So here a before and after the text change (this happens on a button press).
Before
After
Does anyone know what I may be missing or doing wrong? Any help is much appreciated.
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).
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.