-
Edits and buttons
I'm having trouble getting this to work, i just have a button and a text box right now and when you click the button i want the text in the text box to change but it doesn't seem to work. Heres what i have for the code.
Under Defines:
#define ID_CAPCNV 100
#define ID_EDBX 101
Under WM_CREATE:
HWND EBOX;
HWND BTN;
EBOX = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_BORDER, 5, 5, 200, 30, hwnd, (HMENU)ID_EDBX, 0, NULL);
BTN = CreateWindow("button", "Text", WS_CHILD | WS_VISIBLE, 5, 50, 100, 20, hwnd, (HMENU)ID_EDBX, 0, NULL);
return(0);
Under WM_COMMAND:
SetWindowText(EBOX, TEXT("Convert!!!"));
SetDlgItemText(EBOX, ID_EDBX,"TEST");
UpdateWindow(EBOX);
I've tried SetWindowText and SetDlgItemText both seperatly but i included them both in here so maybe you can help
-
Does anyone know why the text in the edit box isn't changing, i can't figure this 1 out. Thanks. (that was my post earlier)
-
Umm, first of all... Don't you use "CreateDialog()" to create a dialog box? (or are you even making a dialog box?) And then, what are EBOX and BTN?... the names aren't too descriptive. And besides, what's the error???
-
The HWND are not static so their value is lost by the time a WM_COMMAND msg is received. Many msg's per sec are flowing thru your callback. Most local variables should be static.
Use a static or call GetDlgItem() or GetWindow() to find the ctrls HWND.
CreateWindow() is fine.
CreateDialog() requires a resource template.
-
>The HWND are not static so their value is lost by the time a WM_COMMAND msg is received
HWNDs do not have to be static
>what are EBOX and BTN?... the names aren't too descriptive.
Actually they are quit descriptive, EBOX is clearly EditBox and BTN is clearly Button
and, as for the question,
you have to:
#define ID_BTN 102
you cant use the same ID for the Edit Box and button
then after you do that, make ur WM_COMMAND: look like this:
Code:
case WM_COMMAND:
{
switch(LOWORD(wParam)
{
case ID_BTN:
SetWindowText(EBOX, "Convert!!!");
break;
}
}
break;
-
>>>The HWND are not static so their value is lost by the time a WM_COMMAND msg is received
HWNDs do not have to be static
Yes, they way they are used here, they do.
They are not global.
They get a value under the WM_CREATE.
This value will not be there after the next message passes thru the callback if they are not static.
Try it.
Also better to check if the button has been clicked rather than another message with
if (BN_CLICKED == HIWORD(wParam))
-
Oops i didnt notice that they were not global, sorry