#include #include HWND hwnd; HWND panel; HWND richEdit; WNDPROC oldStaticProc; int WINAPI WinMain(HINSTANCE, HINSTANCE, PSTR, int); LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK StaticProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); #if _DEBUG #pragma comment( linker, "/subsystem:console" ) int main(int argc, const char** argv) { return WinMain(GetModuleHandle(NULL), NULL, GetCommandLineA(), SW_SHOWDEFAULT); } #else #pragma comment( linker, "/subsystem:windows" ) #endif #pragma comment(lib, "opengl32.lib") int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { LoadLibrary(TEXT("Msftedit.dll")); 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.hbrBackground = CreateSolidBrush(RGB(255, 255, 255)); // White background for the main window wc.lpszClassName = CLASS_NAME; if (!RegisterClass(&wc)) { MessageBox(NULL, L"Window Registration Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } 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); return 0; } ShowWindow(hwnd, SW_SHOW); UpdateWindow(hwnd); panel = CreateWindowEx( 0, L"STATIC", NULL, WS_CHILD | WS_VISIBLE, 0, height - 150, width, 150, hwnd, NULL, hInstance, NULL ); oldStaticProc = (WNDPROC)SetWindowLongPtr(panel, GWLP_WNDPROC, (LONG_PTR)StaticProc); richEdit = CreateWindowEx( WS_EX_CLIENTEDGE, RICHEDIT_CLASS, L"Type here...", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL, 0, 0, width, 150, panel, NULL, hInstance, NULL ); MSG msg = { }; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_SIZE: { int width = LOWORD(lParam); int height = HIWORD(lParam); SetWindowPos(panel, NULL, 0, height - 150, width, 150, SWP_NOZORDER); SetWindowPos(richEdit, NULL, 0, 0, width, 150, SWP_NOZORDER); break; } case WM_CLOSE: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } LRESULT CALLBACK StaticProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { static HBRUSH hBrush = CreateSolidBrush(RGB(0, 255, 0)); // Green background switch (msg) { case WM_ERASEBKGND: return TRUE; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); RECT rect; GetClientRect(hwnd, &rect); FillRect(hdc, &rect, hBrush); // Create a rectangle that is slightly smaller than the panel rect.left += 1; rect.top += 1; rect.right -= 1; rect.bottom -= 1; HPEN hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); // Black pen for border HPEN hOldPen = (HPEN)SelectObject(hdc, hPen); HBRUSH hOldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(NULL_BRUSH)); Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom); SelectObject(hdc, hOldPen); SelectObject(hdc, hOldBrush); DeleteObject(hPen); EndPaint(hwnd, &ps); return 0; } default: return CallWindowProc(oldStaticProc, hwnd, msg, wParam, lParam); } return 0; }