program Project1;
uses
Windows, Messages;
const
HWND_MESSAGE = HWND(-3);
WndClassName = 'ClipboardControlWndClass';
var
hNextWindow: HWND;
function WndProc(hWindow: HWND; Msg: Cardinal; wParam, lParam: Integer): Integer; stdcall;
var
hClipboardData, mesHandle: THandle;
pData: PChar;
begin
Result := 0;
case Msg of
WM_CREATE:
hNextWindow := SetClipboardViewer(hWindow);
WM_DESTROY:
begin
ChangeClipboardChain(hWindow, hNextWindow);
PostQuitMessage(0);
end;
WM_CLOSE:
DestroyWindow(hWindow);
WM_CHANGECBCHAIN:
begin
if HWND(wParam) = hNextWindow then
hNextWindow := HWND(lParam)
else if hNextWindow <> 0 then
SendMessage(hNextWindow, Msg, wParam, lParam);
end;
WM_DRAWCLIPBOARD:
begin
if IsClipboardFormatAvailable(CF_TEXT) and
OpenClipboard(hWindow) then
begin
hClipboardData := GetClipboardData(CF_TEXT);
if hClipboardData <> 0 then
begin
pData := GlobalLock(hClipboardData);
if pData <> nil then
begin
if Pos('porno', pData) <> 0 then
MessageBox(mesHandle, PChar('Важно!!!'), PChar('Запрещенное слово!'), MB_YESNO+MB_ICONQUESTION);
GlobalUnlock(hClipboardData);
end;
end;
CloseClipboard();
if hNextWindow <> 0 then
SendMessage(hNextWindow, Msg, wParam, lParam);
end;
end;
else
Result := DefWindowProc(hWindow, Msg, wParam, lParam);
end;
end;
var
WindowClass: WNDCLASS;
Mess: MSG;
begin
FillChar(WindowClass, SizeOf(WindowClass), 0);
WindowClass.lpfnWndProc := @WndProc;
WindowClass.hInstance := hInstance;
WindowClass.lpszClassName := WndClassName;
RegisterClass(WindowClass);
CreateWindow(WndClassName, nil, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hInstance, nil);
while GetMessage(Mess, 0, 0, 0) do
DispatchMessage(Mess);
halt(Mess.wParam);
end.