Код: Выделить всё
program WinMin ;
uses
windows,
messages,
ShowErr in 'ShowErr.pas',
QDialogs, SysUtils;
const
{$EXTERNALSYM ES_SAVESEL}
ES_SAVESEL = $00008000;
{$EXTERNALSYM ES_SUNKEN}
ES_SUNKEN = $00004000;
{$EXTERNALSYM ES_DISABLENOSCROLL}
ES_DISABLENOSCROLL = $00002000;
RichId = 10;
var
wc : TWndClassEx;
MainWnd, REWnd : HWND;
Mesg : TMsg;
hRichDll: HINST;
function WindowProc(wnd:HWND; Msg : Integer; wParam:wParam; lParam:lParam):lResult; stdcall;
var p : PChar;
n : integer;
f: TextFile;
begin
case msg of
WM_DESTROY: begin
PostQuitMessage(0);
Exit;
Result:=0;
end;
WM_SIZE: begin
MoveWindow(REWnd, 0, 0, LoWord(lParam), HiWord(lParam), False);
Result:=DefWindowProc(wnd,msg,wparam,lparam);
end;
WM_ACTIVATE: begin
Result:=DefWindowProc(wnd,msg,wparam,lparam);
SetFocus(REWnd);
end;
WM_COMMAND:
begin
case LoWord(wParam) of
RichID:
case hiWord(wParam) of
EN_CHANGE: begin
n := GetWindowTextLength(lParam);
GetMem(p,n+1);
GetWindowText(lParam,p,n+1);
SetWindowText(wnd,p);
FreeMem(p,n+1);
end;
end;
end;
end;
{ WM_CHAR:
begin
ShowMessage(IntToStr(wParam) + ' ' + chr(wParam));
Result:=DefWindowProc(wnd,msg,wparam,lparam);
end}
else
Result:=DefWindowProc(wnd,msg,wparam,lparam);
end;
End;
var R: tRect;
begin
hRichDll := LoadLibrary('RICHED20.DLL');
if hRichDll = 0 then exit;
try
with wc do begin
cbSize := sizeof(wc);
style := cs_hredraw or cs_vredraw;
lpfnWndProc := @WindowProc;
cbClsExtra := 0;
cbWndExtra := 0;
hInstance := HInstance;
hIcon := LoadIcon(0,idi_application);
hCursor := LoadCursor(0,idc_arrow);
hbrBackground := COLOR_BTNFACE+1;
lpszMenuName := nil;
lpszClassName := 'WinMin : Main';
end;
RegisterClassEx(wc);
MainWnd := CreateWindowEx (0,'WinMin : Main','Win Min',WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,Hinstance,nil);
GetClientRect(MainWnd, R);
REWnd := CreateWindowEx (WS_EX_CLIENTEDGE,'RichEdit20W','',
WS_VISIBLE or WS_CHILD or WS_BORDER or WS_VSCROLL or ES_NOHIDESEL or ES_AUTOVSCROLL
or ES_MULTILINE or ES_DISABLENOSCROLL or ES_SAVESEL or ES_SUNKEN,
R.left, R.top,R.right - R.left, R.bottom - R.top,MainWnd,RichID,Hinstance,nil);
ShowWindow(MainWnd,SW_NORMAL);
SetFocus(REWnd);
while GetMessage(Mesg,0,0,0) do begin
TranslateMessage(Mesg);
DispatchMessage(Mesg);
end;
finally
FreeLibrary(hRichDll);
end;
end.