• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Help translating code C++ to Delphi (Clipboard backup functions)

I need to backup the clipboard and be able to restore it.

I found some code in C++, can anyone help translate it to Delphi and get it to work? Just the Clipboard backup and restore parts.

http://www.codeproject.com/com/wordhighlight.asp

(See the Backup and Restore Clipboard Data section, ignore the rest)
0
Dream-
Asked:
Dream-
1 Solution
 
ziolkoCommented:
not tested!

procedure TForm1.Button1Click(Sender: TObject);
var format: Integer;
    data: ClipboardData;
    hMem: Handle;
    size: Integer;
    pMem: Pointer;
    pNewMem: Pointer;
begin
  if OpenClipboard(null) then
    try
      format := EnumClipboardFormats(format);
      while format <> 0 do begin
        data.m_mFormat := format;
        if not ((format in [CF_BITMAP, CF_METAFILEPPICT, CF_PALETTE, CF_OWNERDISPLAY, CF_DSPMETAFILEPICT, CF_DSPBITMAP]) or
           ((format >= CF_PRIVATEFIRST) and (format <= CF_PRIVATELAST))) then
        begin
          if format <= 14 then
            data.m_szFormatName := '';
          else if GetClipboardFormatName(format, data.m_szFormatName, 100) then
            data.m_szFormatName := '';
          hMem := GetClipboardData(format);
          if hMem <> 0 then begin
            case format of
              CF_ENHMETAFILE, CF_DSPENHMETAFILE: data.m_hData := CopyMetaFile(hMem, null);
            else
              try
                size := GlobalSize(hMem);
                pMem:= GlobalLock(hMem);
                data.m_hData := GlobaAlloc(GMEM_MOVABLE or GMEM_DDESHARE, size);
                pNewMem := GlobalLock(data.m_hData);
                Move(pMem, pNewMem, size);
              finally
                GlobalUnlock(hMem);
                GlobalUnlock(data.m_hData);
              end;
            end;
            m_lstData.AddTail(data);
          end;
        end;
      end;
    finally
      CloseClipboard;
    end;
end;


ziolko.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now