Solved

using Clipboard functions in a DLL

Posted on 1998-09-03
2
582 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

19 Experts available now in Live!

Get 1:1 Help Now