#include <windows.h>
#include <richedit.h>
static HINSTANCE g_hRichEdit;
static char g_szWindowName[] = "RE";
static char g_szWindowClass[] = "RE32";
static HWND g_hWnd;
static HWND g_hRE;
static HMENU g_hMenu;
LRESULT CALLBACK wnd_proc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
CREATESTRUCT * cs;
MSGFILTER * pMF;
switch ( uMsg ) {
case WM_CREATE:
cs = (LPCREATESTRUCT)lParam;
g_hRE = CreateWindowEx( WS_EX_STATICEDGE,
RICHEDIT_CLASS, "test", WS_CHILD | WS_VISIBLE,
10, 10, 300, 200, hWnd, NULL, cs->hInstance, NULL );
g_hMenu = GetSystemMenu( hWnd, FALSE );
SendMessage( g_hRE, EM_SETEVENTMASK, (WPARAM)0, (LPARAM)ENM_MOUSEEVENTS );
return 0;
case WM_NOTIFY:
pMF = (MSGFILTER *)lParam;
if ( pMF->nmhdr.hwndFrom == g_hRE ) {
if ( pMF->msg == WM_RBUTTONDOWN ) {
POINT pt;
pt.x = LOWORD( pMF->lParam );
pt.y = HIWORD( pMF->lParam );
ClientToScreen( g_hRE, (LPPOINT)&pt );
TrackPopupMenu(
g_hMenu,
TPM_LEFTALIGN | TPM_RIGHTBUTTON,
pt.x,
pt.y,
0,
g_hWnd,
NULL );
}
}
return 0;
case WM_DESTROY:
PostQuitMessage( 0 );
return 0;
}
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
MSG msg;
WNDCLASS wc;
g_hRichEdit = LoadLibrary( "riched32.dll" );
ZeroMemory( &wc, sizeof( WNDCLASS ) );
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = wnd_proc;
wc.hInstance = hInst;
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)GetStockObject( LTGRAY_BRUSH );
wc.lpszClassName = g_szWindowClass;
RegisterClass( &wc );
g_hWnd = CreateWindow(
g_szWindowClass, g_szWindowName, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
100, 100, 400, 300, NULL, NULL, hInst, NULL );
while ( GetMessage( &msg, NULL, 0, 0 ) ) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
DestroyWindow( g_hWnd );
UnregisterClass( g_szWindowClass, hInst );
return 0;
}