Solved

using Clipboard functions in a DLL

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Virtuailstring tree compare node issue 14 127
Show Listview image from database (String field) 5 138
Delphi IDE crash without error message ... 7 99
DBGrid or StringGrid ? 6 105
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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