Confused about Edit Boxes

Heya there,

I can create an edit box just fine, but however when I want to try and grab the value from it...it all goes wrong. Code is below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <windows.h>

LRESULT CALLBACK WindowProc(HWND hWnd,
                         UINT message,
                         WPARAM wParam,
                         LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    HWND hWnd;
    WNDCLASSEX wc;

    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = CreateSolidBrush(RGB(235, 246, 252));
    wc.lpszClassName = L"WindowClass1";

    RegisterClassEx(&wc);

    hWnd = CreateWindowEx(NULL,
                          L"WindowClass1",    // name of the window class
                          L"Mini-Prog",   // title of the window
                          WS_OVERLAPPEDWINDOW,    // window style
                          300,    // x-position of the window
                          300,    // y-position of the window
                          500,    // width of the window
                          400,    // height of the window
                          NULL,    // we have no parent window, NULL
                          NULL,    // we aren't using menus, NULL
                          hInstance,    // application handle
                          NULL);    // used with multiple windows, NULL

    ShowWindow(hWnd, nCmdShow);

    MSG msg;

    while(GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
	return msg.wParam;
}

#define ID_BUTTON 1
#define ID_EDIT 2
#define ID_EDITCHILD 100

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static HWND hwndEdit; 
    switch(message)
    {
		case WM_CREATE:
			{
				//Button
				HWND hWndButton = CreateWindowEx(NULL,TEXT("button"), TEXT("Click Me"),
                WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
                10, 10, 80, 20,      
                hWnd, (HMENU) ID_BUTTON, GetModuleHandle(NULL), NULL);

				// Edit Box
				CreateWindow(TEXT("EDIT"), TEXT("This is some editable text"),
                WS_VISIBLE | ES_MULTILINE | WS_CHILD | WS_BORDER,
                10, 40, 200, 60,
                hWnd, (HMENU) ID_EDIT, NULL, NULL);

				hwndEdit = CreateWindowEx(
                                0, L"EDIT",   // predefined class 
                                NULL,         // no window title 
                                WS_CHILD | WS_VISIBLE | WS_VSCROLL | 
                                ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL, 
                                0, 0, 0, 0,   // set size in WM_SIZE message 
                                hwnd,         // parent window 
                                (HMENU) ID_EDITCHILD,   // edit control ID 
                                (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), 
                                NULL);        // pointer not needed 
            
			} break;

        case WM_DESTROY:
            {
                PostQuitMessage(0);
                return 0;
            } break;

		case WM_COMMAND:
			{
				switch(LOWORD(wParam))
				{
					case ID_BUTTON://button
						{
							MessageBox(hWnd, L"You clicked me", L"Success!", MB_ICONINFORMATION);
						}
				}
			}
    }

    return DefWindowProc (hWnd, message, wParam, lParam);
}
Is that it??
...it all goes wrong


>_<

What does this mean?

Do you get a compiler error? If yes, tell us what the error is and what line it's on.

Does it compile OK but just not do what you expect? If yes tell us what you expect it to do and what it's actually doing.

Be descriptive. It's much easier for us to help you solve a problem when we know what the actual problem is.
I get this error when building the solution...

1>------ Build started: Project: TestingGround, Configuration: Debug Win32 ------
1>Build started 12/09/2012 07:31:21.
1>InitializeBuildStatus:
1>  Touching "Debug\TestingGround.unsuccessfulbuild".
1>ClCompile:
1>  main.cpp
1>ManifestResourceCompile:
1>  All outputs are up-to-date.
1>Manifest:
1>  
1>mt.exe : general error c101008a: Failed to save the updated manifest to the file "Debug\TestingGround.exe.embed.manifest". The parameter is incorrect.
1>  
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.97
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Right, so I have sorted this problem. I forgot to use HWND hWnEdit; up the top.

However...rather than creating a new topic...I have a new problem. Whenever I try to give the edit box some text via SendMessage(). The output looks like this in the edit box...

湉敳瑲琠硥⁴敨敲.


SendMessage(hWndEdit,WM_SETTEXT,NULL,(LPARAM)"Insert text here...");
Try replacing this:
SendMessage(hWndEdit,WM_SETTEXT,NULL,(LPARAM)"Insert text here...");

with:
SendMessageA(hWndEdit,WM_SETTEXT,NULL,(LPARAM)"Insert text here...");
or
SendMessage(hWndEdit,WM_SETTEXT,NULL,(LPARAM)L"Insert text here...");

Another solution is to change your project settings from Unicode to ANSI
Last edited on
Thank you. Another thing I am trying to work how to display the text from the edit control in a messagebox via the SendMessage() method?
Right, ok. So I have got the MessageBox() working such as this...

1
2
3
TCHAR szTemp[128];
GetDlgItemText ( hWnd , IDC_EDIT , szTemp , 128 );
MessageBox(hWnd, szTemp, L"Success", NULL);


But how would I be able to stick the variable in a string and display it?
Topic archived. No new replies allowed.