Hello,
Welcome to Microsoft Q&A!
As far as I'm concerned, you should creat hwnd_green_panel
first and then create the hwnd_richedit_panel
.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
HMODULE hMod = LoadLibrary(TEXT("Msftedit.dll"));
if (!hMod)
{
// Handle the error
MessageBox(NULL, L"Failed to load Msftedit.dll", L"Error", MB_OK | MB_ICONERROR);
return 1; // Or some other error handling
}
int width = 800;
int height = 600;
WNDCLASS wc = { };
const wchar_t* CLASS_NAME = L"OpenGL and RichEdit Message Processing";
wc.lpfnWndProc = WindowProcedure;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
if (!RegisterClass(&wc))
{
MessageBox(NULL, L"Window Registration Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
}
hwnd = CreateWindowEx(
0,
CLASS_NAME,
L"OpenGL RichEdit Control",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, width, height,
NULL,
NULL,
hInstance,
NULL
);
if (hwnd == NULL)
{
MessageBox(NULL, L"Window Creation Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
}
// In your WinMain function, after creating hwnd_richedit_panel:
// Subclass the "STATIC" class for the green panel
WNDCLASS wcGreen = { };
GetClassInfo(NULL, L"STATIC", &wcGreen);
oldGreenProc = wcGreen.lpfnWndProc;
wcGreen.lpfnWndProc = GreenPanelProc;
wcGreen.lpszClassName = L"GREEN_SUBCLASS";
RegisterClass(&wcGreen);
hwnd_green_panel = CreateWindowEx(
0,
L"GREEN_SUBCLASS",
NULL,
WS_CHILD | WS_VISIBLE,
0, 0, width, height - 150,
hwnd,
NULL,
hInstance,
NULL
);
// Subclass the "STATIC" class
WNDCLASS wcStatic = { };
GetClassInfo(NULL, L"STATIC", &wcStatic);
oldStaticProc = wcStatic.lpfnWndProc;
wcStatic.lpfnWndProc = StaticProc;
wcStatic.lpszClassName = L"STATIC_SUBCLASS";
RegisterClass(&wcStatic);
hwnd_richedit_panel = CreateWindowEx(
0,
L"STATIC_SUBCLASS",
NULL,
WS_CHILD | WS_VISIBLE,
0, height - 150, width, 150,
hwnd,
NULL,
hInstance,
NULL
);
if (hwnd != NULL)
{
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
}
if (hwnd_richedit_panel != NULL)
{
InvalidateRect(hwnd_richedit_panel, NULL, TRUE);
UpdateWindow(hwnd_richedit_panel);
}
// Move the creation of the richEdit control here
richEdit = CreateWindowEx(
WS_EX_CLIENTEDGE,
RICHEDIT_CLASS,
L"Type here...",
WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL,
0, 0, width, 150,
hwnd_richedit_panel,
NULL,
hInstance,
NULL
);
if (richEdit == NULL)
{
// Handle the error
MessageBox(NULL, L"RichEdit Creation Failed...", L"Error!", MB_ICONEXCLAMATION | MB_OK);
return 1; // Or some other error handling
}
// After creating the RichEdit control
BOOL result = SendMessage(richEdit, WM_SETTEXT, 0, (LPARAM)L"Hello, World!");
if (!result)
{
// Handle the error
DWORD dwError = GetLastError();
MessageBox(NULL, L"SendMessage Failed...", L"Error!", MB_ICONEXCLAMATION | MB_OK);
return 1; // Or some other error handling
}
SetWindowPos(richEdit, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
SendMessage(richEdit, EM_SETSEL, 0, 0);
SendMessage(richEdit, EM_SCROLLCARET, 0, 0);
// Show the RichEdit control and force it to repaint
ShowWindow(richEdit, SW_SHOW);
UpdateWindow(richEdit);
RedrawWindow(richEdit, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
if (richEdit == NULL)
{
DWORD dwError = GetLastError();
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,
0, NULL);
MessageBox(NULL, (LPCTSTR)lpMsgBuf, L"Error", MB_OK | MB_ICONERROR);
LocalFree(lpMsgBuf);
}
MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
Thank you.
Jeanine
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.