How do I get text from a Win2 rich edit

Hi,

I have a rich edit displaying just fine on my Win32 app; it is created as follows
1
2
3
4
5
6
7
8
9
10
11
12
	LoadLibrary(TEXT("Msftedit.dll"));

	g_hRichEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
		_T("RICHEDIT50W"),
		_T("My Rich Edit"),
		WS_BORDER | WS_CHILD | WS_VISIBLE | ES_MULTILINE,
		2, 2,
		500, 300,
		hWnd,
		(HMENU)IDC_RICHEDIT,
		hInstance,
		NULL);

I think I need to use GetDlgItemText()get the text, but then I have an issue with the id param

 
GetDlgItemText(hWnd, WHAT GOES HERE?, g_szInput, MAXCHAR);


I put in IDC_RICHEDIT from the CreateWindowEXx() call; I didn't think that would work and it didn't: the app built and ran but after the GetDlgItemText() call, g_szInput was NULL or the value I initialized it to.

How am I suppose to do this? Once again the examples and discussions simple say use GetDlgItemText() but don't explain how.

Do I need to put the rich edit in a .rc file so it has an id? If so, how?
Please give complete code.
Thank you for responding but your answer is useless.

I looked at that page and it says nothing about how to get text from the rich edit. If you can show me on that page or any page it leads to that I am wrong and the answer IS there, I will apologize abjectly.

I'm sorry if I'm being overly snippy, but from several posts I've put on this forum, far too many responders (not all by any means) toss out a quick link to some page without knowing whether it actually answers the question. A further beef I have is responders who say do this or that and don't give the needed headers for the functions or variables they are telling you to use.
you can use GetWindowTextLength and then GetWindowText.

i changed code from your other topic:
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <windows.h>
#include <tchar.h>
#include <Richedit.h>

// Global variables
static TCHAR szWindowClass[] = _T("win32app");
static TCHAR szTitle[] = _T("Test Rich Edit Control");

// THE RICH EDIT CONTROL
HWND g_hRichEdit = NULL;

// Forward declarations of functions
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

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

	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = 0;
	wc.lpfnWndProc = WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
	wc.lpszMenuName = NULL;
	wc.lpszClassName = (LPWSTR)szWindowClass;
	wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

	if(!RegisterClassEx(&wc))
	{
		MessageBox(NULL, _T("Window Registration Failed!"), _T("Error!"),
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	hWnd = CreateWindowEx(
		0,
		(LPWSTR)szWindowClass,
		_T("Win32 App Demo"),
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, 350, 350,
		NULL, NULL, hInstance, NULL);

	if(hWnd == NULL)
	{
		MessageBox(NULL, _T("Window Creation Failed!"), _T("Error!"),
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	LoadLibrary(TEXT("Msftedit.dll"));

	g_hRichEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
		_T("RICHEDIT50W"),
		_T("My Rich Edit"),
		WS_BORDER | WS_CHILD | WS_VISIBLE | ES_MULTILINE,
		2, 2,
		200, 300,
		hWnd,
		0,
		hInstance,
		NULL);

	HWND hButtonhandle = CreateWindowEx( 0,
		_T("button"),
		_T("get text"),
		WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,
		207, 2,
		75, 35,
		hWnd,
		(HMENU)260,
		hInstance,
		NULL);

	ShowWindow(hWnd, nCmdShow);

	UpdateWindow(hWnd);

	while (GetMessage(&msg, NULL, 0, 0) > 0)
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	LRESULT result = 0;

	switch (msg)
	{
		case WM_CLOSE:
		{
			DestroyWindow(hWnd);
			break;
		}
		case WM_DESTROY:
		{
			PostQuitMessage(0);
			break;
		}
        case WM_COMMAND:
            {
                if ( 260 == LOWORD( wParam))
                {
                    if ( BN_CLICKED == HIWORD(wParam))
                    {
                        TCHAR * buffer = 0;
                        int nLen = 0;

                        nLen = GetWindowTextLength( g_hRichEdit);

                         if ( nLen > 0 )
                         {
                            buffer = new TCHAR[nLen+1];

                            if ( 0 != GetWindowText( g_hRichEdit, buffer, nLen+1) )
                            {
                                MessageBox( hWnd, buffer , L"rich edit text", 0);
                            }

                            delete [] buffer;
                         }

                    }
                }
            }
            break;
		default:
		{
		   result = DefWindowProc(hWnd, msg, wParam, lParam);
		}
	}

	return result;
}
Thank you, that is what I needed :)
Registered users can post here. Sign in or register to post.