Jump to content
  • Advertisement
Sign in to follow this  
d1sc0rd

RichEdit Control Creation Problem *FIXED*

This topic is 5411 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have read all of the forums and can't seem to figure out why I can't get "RichEdit" to be a valid registered class. Here is the code.
#include <windows.h>
#include <richedit.h>

#define IDC_MAIN_EDIT	101

HINSTANCE g_hInstRichEditDll;
HINSTANCE hInstance;
WNDCLASSEX wc;
HWND hwnd;
MSG msg;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain ( HINSTANCE hThisInstance, HINSTANCE hPrevInstance,
      LPSTR szCmdLine, int nCmdShow)
{
hInstance = hThisInstance;

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	= TEXT ("MyClass");

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

hwnd = CreateWindowEx ( 0, TEXT ("MyClass"), 
					 TEXT ("Main Window"),  
					 WS_OVERLAPPEDWINDOW, 
					 CW_USEDEFAULT, CW_USEDEFAULT, 480, 320, 
					 hwnd, NULL, hInstance, NULL);

if (hwnd == NULL)
{
 MessageBox (NULL, "Window Creation Failed!", "Error!", MB_OK);
 return 0;
}

ShowWindow (hwnd, nCmdShow);
UpdateWindow (hwnd);

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






LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{
HWND hwndEdit;

switch (message)
{

case WM_CREATE:
 g_hInstRichEditDll = LoadLibrary(TEXT ("Riched20.dll"));
 if ( g_hInstRichEditDll == NULL )
 {
  return ( FALSE );
 }

 hwndEdit = CreateWindowEx ( WS_EX_CLIENTEDGE, RICHEDIT_CLASS, NULL,  
    WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | 
	ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
    0, 0, 100, 100,
    hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL),  NULL);
 if (!hwndEdit)
 MessageBox ( hwnd, TEXT ("The edit window wasn't created."), TEXT ("EDIT ERROR"), MB_OK | MB_ICONERROR);
 break;
 case WM_SIZE:
		{
			HWND hEdit;
			RECT rcClient;

			GetClientRect(hwnd, &rcClient);

			hEdit = GetDlgItem(hwnd, IDC_MAIN_EDIT);
			SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
		}
		break;
 //ShowWindow (hwndEdit, SW_SHOW);
 //UpdateWindow (hwndEdit);
case WM_DESTROY:
 PostQuitMessage(0);
 break;
default:
 return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}






When I getlasterror I find error 1407, whcih indicates that the class richedit isn't recognized. Any ideas? [Edited by - d1sc0rd on September 24, 2004 5:49:23 PM]

Share this post


Link to post
Share on other sites
Advertisement
Hmmm without commenting on the veracity of your code, I can say it appears to work for me at least..... Maybe your loadlibrary is failing?

When are you checking getlasterror()?

jbc

Share this post


Link to post
Share on other sites
I was checking getlasterror right after creating the richedit window.

I just realized I failed to specify that this is supposed to be a richedit control, and I accidently left the edit control in there I checked the code with. Its been a rough day...

Anyway, I changed the class from edit to richedit in the source code. Does it work now?

Share this post


Link to post
Share on other sites
Since you're using richedit2.0 use the RICHEDIT_CLASS constant in the CreateWindowEx. As in:

hwndEdit = CreateWindowEx ( WS_EX_CLIENTEDGE, RICHEDIT_CLASS, NULL,

This ought to do it for you.

jbc

Share this post


Link to post
Share on other sites
ok I edited the source code to include RICHEDIT_CLASS. This still doesn't fix the problem. So far if I use richedit 1.0 by opening the old .dll I can get a richedit window, but I just can't get any newer versions to work. I just can't figure this out, it seems like it should be simple.

Share this post


Link to post
Share on other sites
d1sc0rd,

your CreateWindowEx should look like:

hwndEdit = CreateWindowEx ( WS_EX_CLIENTEDGE, RICHEDIT_CLASS, NULL,
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL |
ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
0, 0, 100, 100,
hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);

I.e. don't TEXT("") it. RICHEDIT_CLASS is a constant defined in a header.

jbc

edit: fixed typo

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!