Ok, well it is best to post compile-able code so that anyone trying to help does not have to mess about trying to get things right.
EDIT:
Try trapping both WM_KEYDOWN and WM_CHAR
I think you only need to trap WM_CHAR though.
static int WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
/* Select Case uMsg */
switch(msg){
case WM_KEYDOWN:
//MsgBox("WM_KEYDOWN", "", 0);
return 0;
case WM_CHAR:
//MsgBox("WM_CHAR", "", 0);
return 0;
}
return CallWindowProc((WNDPROC)PrevProc, hwnd, msg, wParam, lParam);
}
Here is the listing that I used.
/****************************************************************************
* *
* File : main.c *
* *
* Purpose : Generic Win32 application. *
* *
* History : Date Reason *
* 00/00/00 Created *
* *
****************************************************************************/
#define WIN32_LEAN_AND_MEAN /* speed up compilations */
#include <windows.h>
#include <windowsx.h>
#include <tchar.h>
#include <richedit.h>
#include "main.h"
/** Prototypes **************************************************************/
static LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
/** Global variables ********************************************************/
static HANDLE ghInstance;
HWND Edit1;
static WNDPROC PrevProc;
HANDLE hlib;
int MsgBox(char *Msg, char *Title, int Num)
{
return MessageBox(GetActiveWindow(), Msg, Title, Num);
}
static int WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
/* Select Case uMsg */
switch(msg){
case WM_KEYDOWN:
//MsgBox("WM_KEYDOWN", "", 0);
return 0;
case WM_CHAR:
//MsgBox("WM_CHAR", "", 0);
return 0;
}
return CallWindowProc((WNDPROC)PrevProc, hwnd, msg, wParam, lParam);
}
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
WNDCLASS wc;
HWND hwnd;
MSG msg;
ghInstance = hInstance;
hlib = LoadLibrary(_T("riched20.dll")); // Rich Edit v2.0, v3.0
/* Register the main window class */
wc.lpszClassName = _T("win1Class");
wc.lpfnWndProc = MainWndProc;
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.hInstance = ghInstance;
wc.hIcon = LoadIcon(ghInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if (!RegisterClass(&wc))
return 1;
/* Create the main window */
hwnd = CreateWindow(_T("win1Class"), _T("win1 Program"), WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, ghInstance, NULL);
if (!hwnd)
return 1;
/* Show and paint the main window */
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
/* Pump messages until we are done */
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
Edit1 = CreateWindow(RICHEDIT_CLASS, NULL, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE | WS_BORDER | ES_LEFT | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 0, 0, 550, 450, hwnd, (HMENU)NULL, ghInstance, NULL);
PrevProc = (WNDPROC)SetWindowLong((HWND)Edit1, GWL_WNDPROC, (LONG)WindowProc);
break;
case WM_CLOSE:
SetWindowLong((HWND)Edit1, GWL_WNDPROC, (LONG)PrevProc);
CloseWindow(Edit1);
FreeLibrary(hlib);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return FALSE;
}
John