Can't get rich edit to show on Win32 app

Hi,

I am trying to place a rich edit on a Win32 app; the rich edit does not show. I have googled rich edits and looked at several pages and examples and none of them work for me.

Here is my code
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
#include <windows.h>
#include <tchar.h>
#include <Richedit.h>
#include "resource.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);
void createRichEdit(HWND hWnd, HINSTANCE hInstance);

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 + 1);
	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(
		WS_EX_CLIENTEDGE,
		(LPWSTR)szWindowClass,
		_T("Win32 App Demo"),
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, 700, 700,
		NULL, NULL, hInstance, NULL);

	if(hWnd == NULL)
	{
		MessageBox(NULL, _T("Window Creation Failed!"), _T("Error!"),
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}
// ATTEMPT TO CREATE THE RICH EDIT
	LoadLibrary(TEXT("1	Msftedit.dll"));
	createRichEdit(hWnd, hPrevInstance);
//	ShowWindow(g_hRichEdit, nCmdShow); this line didn't help
	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;
		}
		default:
		{
		   result = DefWindowProc(hWnd, msg, wParam, lParam);
		}
	}

	return result;
}

void createRichEdit(HWND hWnd, HINSTANCE hInstance)
{
	g_hRichEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
		_T("MSFTEDIT_CLASS"),
		_T("My Rich Edit"),
		WS_BORDER | WS_CHILD | WS_VISIBLE | ES_MULTILINE,
		2, 2,
		200, 300,
		hWnd,
		0,
		hInstance,
		NULL);
}

The app shows just fine but there is no rich edit on it.

Are "MSFTEDIT_CLASS", line 59, and "1 Msftedit.dll", line 103 the correct values to use?

Can you tell me how to fix this?
Last edited on
g_hRichEdit = CreateWindowEx(WS_EX_CLIENTEDGE,

return 0, which is error. To get last error use:
DWORD dwError = GetLastError();

in your case, it returned: 0x0000057f
which is
1
2
3
4
5
ERROR_CANNOT_FIND_WND_CLASS

    1407 (0x57F)

    Cannot find window class

( http://msdn.microsoft.com/en-us/library/windows/desktop/ms681385%28v=vs.85%29.aspx )

also according to MSDN: LoadLibrary(TEXT("Msftedit.dll"));
load richedit 4.1, whic class name is not MSFTEDIT_CLASS but RICHEDIT50W

so:
1
2
3
4
5
6
7
8
9
10
	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);


also fix error:
LoadLibrary(TEXT("1 Msftedit.dll"));
change to
LoadLibrary(TEXT("Msftedit.dll"));
tath,

Thank you. Fixing the values on lines 59 and 103 fixed everything.

I copied the Msftedit.dll value from http://msdn.microsoft.com/en-us/library/bb787873%28v=vs.85%29.aspx; I don't know where the 1 came from but I should have realized that it was wrong.

An example I looked at did use RICHEDIT50W but it didn't work and the above web page listed MSFTEDIT_CLASS next to Msftedit.dll so I thought that was the class name to use. I don't know what the web page meant.

Also, I'll remember to GetLastError() in the future and see if that leads me to the solution to problems like this.

Anyway it works now and thank you again.
Last edited on
Topic archived. No new replies allowed.