Solved

using Clipboard functions in a DLL

Posted on 1998-09-03
2
583 Views
Last Modified: 2010-04-04
I try to write a function that Copy's the Active window to a Bitmap file. When I use this function in a program it work's fine. When put it in a DLL it don't work.
Help!!!!!

function CopyActiveScreenToFile(FName: PChar): Boolean;
var TmpBMP:TBitmap;
    Data: THandle;
    Palette: HPALETTE;
begin
  Result := False;
  Clipboard.Open;
  keybd_event(VK_SNAPSHOT, 0, 0, 0);
  TmpBMP := TBitmap.Create;
  try
    Data := GetClipboardData(CF_BITMAP);
    Palette := GetClipboardData(CF_PALETTE);
    TmpBMP.LoadFromClipBoardFormat(CF_BITMAP, Data, Palette);
    TmpBMP.SaveToFile(FName);
    if FileExists(FName) then
      Result := True
    else
      Result :=False;
  finally
    TmpBMP.Free;
  end;
  Clipboard.Close;
end;
0
Comment
Question by:lucley
2 Comments
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1338521
hoi, lucley!

i can't get this to work - EIvalidGraphic with LoadFromClipboardFormat.
?
are you sure it runs as supposed?

Black Death.
0
 
LVL 5

Accepted Solution

by:
inter earned 200 total points
ID: 1338522
At first I have the same problem with BlackDeath and by tracing the problem I found that the problem is caused by the snapshot. Mainly snopshot does not copy image into clipboard because the function doesnot give trasfer to the windows... so I do only a simple modification here it is:


function CopyActiveScreenToFile(FName: PChar): Boolean;
var TmpBMP: TBitmap;
  Data: THandle;
  Palette: HPALETTE;
begin
  Result := False;
  //this does not work if you do not process messages
  keybd_event(VK_SNAPSHOT, 0, 0, 0);
  //here is what I have added
  Application.ProcessMessages;
  Clipboard.Open;
  TmpBMP := TBitmap.Create;
  try
    Data := GetClipboardData(CF_BITMAP);
    Palette := GetClipboardData(CF_PALETTE);
    TmpBMP.LoadFromClipBoardFormat(cf_BitMap, Data, Palette);
    TmpBMP.SaveToFile(FName);
    if FileExists(FName) then
      Result := True
    else
      Result := False;
  finally
    TmpBMP.Free;
  end;
  Clipboard.Close;
end;

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now