Solved

using Clipboard functions in a DLL

Posted on 1998-09-03
2
586 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

732 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