Markenstein
asked on
How do I get RichEdit to work?
I can't get RichEdit to show up. I'm using the following code:
#include <richedit.h>
...
CreateWindowEx(WS_EX_CLIEN TEDGE, RICHEDIT_CLASS,NULL, WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOHSCROLL, 0, 0, 300, 300, hwnd, (HMENU) 1, hInstance, NULL);
Do i need to add a lib or something? Why isn't this working?
#include <richedit.h>
...
CreateWindowEx(WS_EX_CLIEN
Do i need to add a lib or something? Why isn't this working?
what compiler are you using and what errors are you getting back?
ASKER
VC++ 6, i get no errors, nor relevant warnings. It does everything fine just that nothing shows up.
You must call AfxinitRichEdit() in InitInstance routine of your App class
Typo error:
AfxInitRichEdit
AfxInitRichEdit
Sorry,
I can't help you. I am still a C++ student myself.
I can't help you. I am still a C++ student myself.
ASKER
So do i have to use MFC to use RichEdit or is that Afx prefix mean something else?
Sorry I thought I was in MFC area :(
For your question, you can add this line:
LoadLibrary("riched32.dll" );
There's also an example for RichEdit in MSDN: REITP.C
Best regards
For your question, you can add this line:
LoadLibrary("riched32.dll"
There's also an example for RichEdit in MSDN: REITP.C
Best regards
ASKER
That didn't work, it still displays nothing. I have the following:
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
....
in WinMain
LoadLibrary("riched32.dll" );
in WinProc under WM_SHOWWINDOW
CreateWindow(RICHEDIT_CLAS S, NULL, WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOHSCROLL, 0, 0, 300, 300, hwnd, (HMENU) 1, hInstance, NULL);
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
....
in WinMain
LoadLibrary("riched32.dll"
in WinProc under WM_SHOWWINDOW
CreateWindow(RICHEDIT_CLAS
ASKER
Adjusted points from 50 to 75
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That didn't worth either... I tried the REIPT example and that didn't work either. It compiled but it said it couldn't make the RichEdit. Maybe there is an error on my side? I'm running NT4, SP6
I created an application with VC6 Application Wizard. Adding 3 lines
#include <richedit.h>
LoadLibrary("Riched20.dll" );
CreateWindow(RICHEDIT_CLAS S, NULL, WS_CHILD | WS_VISIBLE| ES_MULTILINE | ES_AUTOHSCROLL, 0, 0, 300, 300, hWnd, 0, hInst, NULL);
and it works fine. (I also removed some codes to shorten the program).
Try this code. If you still not able to run it you should look for the file riched20.dll in your file system. Defaultly it's in c:\winnt\system32 (or c:\windows\system32). If you have riched32.dll, you can use RichEdit 1.0 (its class name is RichEdit instead of RICHEDIT_CLASS)
#include "stdafx.h"
#include "resource.h"
#include <richedit.h>
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRI NG]; // The title bar text
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_TESTRE, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance) ;
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance , (LPCTSTR)IDC_TESTRE);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg .hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_TESTRE);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
LoadLibrary("Riched20.dll" );
hWnd = CreateWindow(szWindowClass , szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_SHOWWINDOW:
CreateWindow(RICHEDIT_CLAS S, NULL, WS_CHILD | WS_VISIBLE| ES_MULTILINE | ES_AUTOHSCROLL, 0, 0, 300, 300, hWnd, 0, hInst, NULL);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
#include <richedit.h>
LoadLibrary("Riched20.dll"
CreateWindow(RICHEDIT_CLAS
and it works fine. (I also removed some codes to shorten the program).
Try this code. If you still not able to run it you should look for the file riched20.dll in your file system. Defaultly it's in c:\winnt\system32 (or c:\windows\system32). If you have riched32.dll, you can use RichEdit 1.0 (its class name is RichEdit instead of RICHEDIT_CLASS)
#include "stdafx.h"
#include "resource.h"
#include <richedit.h>
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRI
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_TESTRE, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance)
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_TESTRE);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
LoadLibrary("Riched20.dll"
hWnd = CreateWindow(szWindowClass
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_SHOWWINDOW:
CreateWindow(RICHEDIT_CLAS
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
ASKER
Alright i got it, i don't know what i did wrong... Anyways sorry for taking so long.
ASKER
It worked when i moved LoadLibrary from WinMain to right before the CreateWindowEx function.