We don't display ads so we rely on your Bitcoin donations to 1KWEk9QaiJb2NwP5YFmR24LyUBa4JyuKqZ
Post date: Mar 16, 2010 3:14:54 PM
{
Coder: steve10120
Compiled: Delphi7
Website: hackhound.org
}
GetClipText retreives the current text in the clipboard.
SetClipText sets the required text to the clipboard.
function GetClipText(var szText:string):Boolean;
var
hData: DWORD;
pData: Pointer;
dwSize: DWORD;
begin
Result := FALSE;
if OpenClipBoard(0) then
begin
hData := GetClipBoardData(CF_TEXT);
if hData <> 0 then
begin
pData := GlobalLock(hData);
if pData <> nil then
begin
dwSize := GlobalSize(hData);
if dwSize <> 0 then
begin
SetLength(szText, dwSize);
CopyMemory(@szText[1], pData, dwSize);
Result := TRUE;
end;
GlobalUnlock(DWORD(pData));
end;
end;
CloseClipBoard;
end;
end;
function SetClipText(szText:string):Boolean;
var
pData: DWORD;
dwSize: DWORD;
begin
Result := FALSE;
if OpenClipBoard(0) then
begin
dwSize := Length(szText) + 1;
if dwSize <> 0 then
begin
pData := GlobalAlloc(MEM_COMMIT, dwSize);
if pData <> 0 then
begin
CopyMemory(Pointer(pData), PChar(szText), dwSize);
if SetClipBoardData(CF_TEXT, pData) <> 0 then
Result := TRUE;
end;
end;
CloseClipBoard;
end;
end;
Usage:
var
szText: string;
begin
if SetClipText('Hello World!') then
begin
if GetClipText(szText) then
MessageBox(0, PChar(szText), nil, 0);
end;
end.