Edit text on text window - c++

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.

Related

How to break text line on a WS_EX_CLIENTEDGE "Edit" text field on Win32

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.

c++ - Expression must have a pointer-to-object type

So I was following a tutorial on how to make a text box and get inputted text from it. I get the error 'Expression must have a pointer-to-object type' on the line where gwtstat, on the [0] part of &text[0]. Just a basic run down of my code incase anyone wants it, case 1: gets called when a 'Go' button is pressed next to the text box. TextBox is a HWND containing the text box, and the 'text' variable is of type char. Here is the code in whole:
switch (LOWORD(wParam)){
case 1:
int gwtstat = 0;
gwtstat = GetWindowText(TextBox, &text[0], 20);
::MessageBox(hWnd, &text, &text, MB_OK);
}
So, I have looked through google and this website, but none of the answers have worked thus far.
EDIT::: Ok, just so yall have all the code, here's all the code that I use for the textbox:
HWND TextBox;
char text[20];
Where TextBox gets made: (inside DrawGLScene, called every frame)
if (testKey.isS()){
TextBox = CreateWindow("EDIT", "", WS_BORDER | WS_CHILD | WS_VISIBLE, 10, 10, 400, 20, hWnd, NULL, NULL, NULL);
CreateWindow("BUTTON", "Go", WS_VISIBLE | WS_CHILD | WS_BORDER, 420, 10, 70, 20, hWnd, (HMENU) 1, NULL, NULL);
}

WinAPI's control's positioning not working?

When I tried to set my static control position at 0, 0 and size the same as window's size everything worked just fine. Control was placed the same as window, but when i tried to make control smaller and place it so that there's equal amount of space on every side of control it didn't work. At the top there was more space than at the bottom and on the left side ther was more space than on the right side. Could you please tell me how to do what i wanted to do? Code i was using:
1: ghStatic = CreateWindowExW(WS_EX_CLIENTEDGE, L"STATIC", L"Foo", WS_CHILD | WS_VISIBLE | SS_CENTER, 0, 0, 300, 300, hwnd, nullptr, hInstance, nullptr);
2: ghStatic = CreateWindowExW(WS_EX_CLIENTEDGE, L"STATIC", L"Foo", WS_CHILD | WS_VISIBLE | SS_CENTER, 75, 75, 150, 150, hwnd, nullptr, hInstance, nullptr);
Are do you using the CreateWindowExW function to change the size of your hwnd? You cannot use this function to change the hwnd size, it is used to create controls, because it will be trying to recreate what was already created.
Try use MoveWindow function to change the position and size of hwnd:
MoveWindow(YourHWND, x, y, w, h, TRUE);
MoveWindow(ghStatic, 75, 75, 150, 150, TRUE);

EDIT control text overflow

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

c++ edit box goes behind main window

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...