Richedit control in Win32 C++
-
Hi ... can any1 tell me what is wrong with the following code? i'm sure its some silly mistake that i made ... I am trying to create a Richedit control in a window. I have included richedit.h and my code compiles successfully. but _hWnd remains NULL after this call :( ... i am using Microsoft VC++ 6 with the Platform SDK 2003 installed. please help me out. thankx in advance.
_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE,
RICHEDIT_CLASS,
TEXT("AA"),
WS_CHILD | WS_VISIBLE | ES_MULTILINE,
10, 10,
100, 100,
_parent,
0,
(HINSTANCE)::GetModuleHandle(0),
0);-Tareq
-
Hi ... can any1 tell me what is wrong with the following code? i'm sure its some silly mistake that i made ... I am trying to create a Richedit control in a window. I have included richedit.h and my code compiles successfully. but _hWnd remains NULL after this call :( ... i am using Microsoft VC++ 6 with the Platform SDK 2003 installed. please help me out. thankx in advance.
_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE,
RICHEDIT_CLASS,
TEXT("AA"),
WS_CHILD | WS_VISIBLE | ES_MULTILINE,
10, 10,
100, 100,
_parent,
0,
(HINSTANCE)::GetModuleHandle(0),
0);-Tareq
What's the value of
GetLastError()
right after the call? --Mike-- Latest blog entry: *drool* (Alyson) [May 10] Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber "You have Erica on the brain" - Jon Sagara to me -
Hi ... can any1 tell me what is wrong with the following code? i'm sure its some silly mistake that i made ... I am trying to create a Richedit control in a window. I have included richedit.h and my code compiles successfully. but _hWnd remains NULL after this call :( ... i am using Microsoft VC++ 6 with the Platform SDK 2003 installed. please help me out. thankx in advance.
_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE,
RICHEDIT_CLASS,
TEXT("AA"),
WS_CHILD | WS_VISIBLE | ES_MULTILINE,
10, 10,
100, 100,
_parent,
0,
(HINSTANCE)::GetModuleHandle(0),
0);-Tareq
-
What's the value of
GetLastError()
right after the call? --Mike-- Latest blog entry: *drool* (Alyson) [May 10] Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber "You have Erica on the brain" - Jon Sagara to meAfter using the following code from MSDN to retrieve the last error right after CreateWindowEx, i get "Invalid Window Handle". :((
LPVOID lpMsgBuf; FormatMessage( FORMAT\_MESSAGE\_ALLOCATE\_BUFFER | FORMAT\_MESSAGE\_FROM\_SYSTEM | FORMAT\_MESSAGE\_IGNORE\_INSERTS, NULL, GetLastError(), MAKELANGID(LANG\_NEUTRAL, SUBLANG\_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL ); MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB\_OK | MB\_ICONINFORMATION ); LocalFree( lpMsgBuf );
-Tareq
-
Did you init richedit control?? if you use MFC, please try to call AfxInitRichedit() in App::InitInstance(). maybe that's the point.
No MFC. Just Win32. -Tareq
-
No MFC. Just Win32. -Tareq
-
nope :( its the same. -Tareq
-
nope :( its the same. -Tareq
-
try ::LoadLibrary("Riched20.dll"); For win95 the rich edit control lib is "Riched32.dll", for win98 win2k&winxp, the lib is "Riched20.dll"
tried that also :( ... i'm sure its some silly mistake. it cant be that complicated.
HINSTANCE hLib;
hLib = LoadLibrary("Riched20.dll");
if (!hLib)
{
hLib = LoadLibrary("Riched32.dll");
if (!hLib)
{
MessageBox(0, "Richedit control failed to initialize!", "Editor", MB_ICONERROR);
exit(0);
}
else
strcpy(_className, "RichEdit");
}
else
{
strcpy(_className, "RICHEDIT_CLASS");
}-Tareq
-
After using the following code from MSDN to retrieve the last error right after CreateWindowEx, i get "Invalid Window Handle". :((
LPVOID lpMsgBuf; FormatMessage( FORMAT\_MESSAGE\_ALLOCATE\_BUFFER | FORMAT\_MESSAGE\_FROM\_SYSTEM | FORMAT\_MESSAGE\_IGNORE\_INSERTS, NULL, GetLastError(), MAKELANGID(LANG\_NEUTRAL, SUBLANG\_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL ); MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB\_OK | MB\_ICONINFORMATION ); LocalFree( lpMsgBuf );
-Tareq
This seems to suggest that the parent window has not been created yet. Where are you calling the function from? Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact" -
This seems to suggest that the parent window has not been created yet. Where are you calling the function from? Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"Here is the code ...
#define WIN32_LEAN_AND_MEAN
#include < windows.h >
#include < stdlib.h >
#include < richedit.h >
#include < commctrl.h >HWND _rich;
HMODULE _hRich;
char className[14];LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
_rich = CreateWindowEx(WS_EX_CLIENTEDGE,
className,
"Sample Text",
WS_CHILD | WS_VISIBLE | ES_MULTILINE | WS_BORDER | WS_VSCROLL,
10, 10,
200, 200,
hWnd,
0,
GetModuleHandle(0),
0);LPVOID lpMsgBuf; FormatMessage( FORMAT\_MESSAGE\_ALLOCATE\_BUFFER | FORMAT\_MESSAGE\_FROM\_SYSTEM | FORMAT\_MESSAGE\_IGNORE\_INSERTS, NULL, GetLastError(), MAKELANGID(LANG\_NEUTRAL, SUBLANG\_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL ); MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB\_OK | MB\_ICONINFORMATION ); LocalFree( lpMsgBuf ); break; case WM\_CLOSE: DestroyWindow(hWnd); break; case WM\_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hWnd, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX wc;
HWND _hWnd;ZeroMemory(className, 14); InitCommonControls(); \_hRich = LoadLibrary("RICHED20.DLL"); if (!\_hRich) { \_hRich = LoadLibrary("RICHED32.DLL"); if (!\_hRich) { MessageBox(0, "Richedit control not loaded!", "Error", MB\_ICONERROR); exit(0); } else { strcpy(className, "RichEdit"); } } else { strcpy(className, "RICHEDIT\_CLASS"); } wc.cbClsExtra = 0; wc.cbSize = sizeof(WNDCLASSEX); wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH)(COLOR\_WINDOW); wc.hCursor = 0; wc.hIcon = 0; wc.hIconSm = 0; wc.hInstance = hInstance; wc.lpfnWndProc = (WNDPROC)WndProc; wc.lpszClassName = "MainWindowClass"; wc.lpszMenuName = 0; wc.style = 0; if (!RegisterClassEx(&wc)) { MessageBox(0, "Error", "", MB\_ICONERROR); exit(0); } \_hWnd = CreateWindowEx(WS\_EX\_WINDOWEDGE, "MainWindowClass", "", WS\_OVERLAPPEDWINDOW, 0, 0, 300, 300, 0, 0, hInstance, 0); ShowWindow(\_hWnd, SW\_SHOW); UpdateWindow(\_hWnd); MSG msg; while (GetMessage(&msg, 0, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam;
}
-Tareq
-
Here is the code ...
#define WIN32_LEAN_AND_MEAN
#include < windows.h >
#include < stdlib.h >
#include < richedit.h >
#include < commctrl.h >HWND _rich;
HMODULE _hRich;
char className[14];LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
_rich = CreateWindowEx(WS_EX_CLIENTEDGE,
className,
"Sample Text",
WS_CHILD | WS_VISIBLE | ES_MULTILINE | WS_BORDER | WS_VSCROLL,
10, 10,
200, 200,
hWnd,
0,
GetModuleHandle(0),
0);LPVOID lpMsgBuf; FormatMessage( FORMAT\_MESSAGE\_ALLOCATE\_BUFFER | FORMAT\_MESSAGE\_FROM\_SYSTEM | FORMAT\_MESSAGE\_IGNORE\_INSERTS, NULL, GetLastError(), MAKELANGID(LANG\_NEUTRAL, SUBLANG\_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL ); MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB\_OK | MB\_ICONINFORMATION ); LocalFree( lpMsgBuf ); break; case WM\_CLOSE: DestroyWindow(hWnd); break; case WM\_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hWnd, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX wc;
HWND _hWnd;ZeroMemory(className, 14); InitCommonControls(); \_hRich = LoadLibrary("RICHED20.DLL"); if (!\_hRich) { \_hRich = LoadLibrary("RICHED32.DLL"); if (!\_hRich) { MessageBox(0, "Richedit control not loaded!", "Error", MB\_ICONERROR); exit(0); } else { strcpy(className, "RichEdit"); } } else { strcpy(className, "RICHEDIT\_CLASS"); } wc.cbClsExtra = 0; wc.cbSize = sizeof(WNDCLASSEX); wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH)(COLOR\_WINDOW); wc.hCursor = 0; wc.hIcon = 0; wc.hIconSm = 0; wc.hInstance = hInstance; wc.lpfnWndProc = (WNDPROC)WndProc; wc.lpszClassName = "MainWindowClass"; wc.lpszMenuName = 0; wc.style = 0; if (!RegisterClassEx(&wc)) { MessageBox(0, "Error", "", MB\_ICONERROR); exit(0); } \_hWnd = CreateWindowEx(WS\_EX\_WINDOWEDGE, "MainWindowClass", "", WS\_OVERLAPPEDWINDOW, 0, 0, 300, 300, 0, 0, hInstance, 0); ShowWindow(\_hWnd, SW\_SHOW); UpdateWindow(\_hWnd); MSG msg; while (GetMessage(&msg, 0, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam;
}
-Tareq
This code won't work. You'll get an error message saying that you're using an unknown class. You need to change
strcpy(className, "RICHEDIT_CLASS");
to
strcpy(className, RICHEDIT_CLASS);
I tried this and it worked fine. Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact" -
This code won't work. You'll get an error message saying that you're using an unknown class. You need to change
strcpy(className, "RICHEDIT_CLASS");
to
strcpy(className, RICHEDIT_CLASS);
I tried this and it worked fine. Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact":-D thankx a lot man ... i knew it was a silly mistake!!! -Tareq