Solved

How to draw DIRECT to Desktop Windows?

Posted on 1998-10-28
13
222 Views
Last Modified: 2010-04-06
Some code in delphi.
Thanks.
0
Comment
Question by:ndthang
13 Comments
 
LVL 4

Accepted Solution

by:
BoRiS earned 100 total points
ID: 1344694
ndthang

here is a code snippet

procedure TForm1.Button1Click(Sender: TObject);
 var
   dc : hdc;
 begin
   dc := GetDc(0);
   MoveToEx(Dc, 0, 0, nil);
   LineTo(Dc, 600, 600);
   ReleaseDc(0, Dc);
 end;

the only thing with drawing on the desktop is that there must be no image on the desktop
to draw of the image on the desktop you need to draw onto the screen memory as far as i know...

Later
BoRiS
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1344695
ndthang

sorry I stand corrected the reason I could not see the line drawing on the desktop is that the line is black and so is my image background but I changed the image to an image with a white background and it works perfectly...

You can draw anything you like on the desktop window but the code I sent just simply draws a line across the desktop...

Later
BoRiS
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344696
Hi !,

wait, don't accept the answer yet, ( I don't mean to reject it ).
I have a code which maybe can help you, wait, I'll look for it.

bryan

0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344697
Ok, I found it, But I'll have to email it to you, since it has a bitmap and some things.
Of course, the code is not mine.
It goes like this:



unit Unit1;

// This little example shows how to create the illusion
// of your program painting directly on the desktop!
// If you have any ideas for improvements, please send
// the new version to me - you will ofcourse be credited.
// Particularly I'm looking for methods to make the
// drawing faster, although it's not HORRIBLY slow now.
//
// Note that: the illusion is lost if something changes
// underneath your form - this means that this effects
// is probably only useful for splash screens etc.
// If you can figure out how to make the image repaint
// when something changes underneath it, please write!
// Also note that I'm assuming the client area of the
// form is exactly the same size as the map and mask
// images.
//
// You can e-mail me at mus303@yahoo.com

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TMyForm = class(TForm)
    CloseButton: TButton;
    MyImage: TImage;
    CopyButton: TButton;
    LogoMap: TImage;
    LogoMask: TImage;
    procedure FormCreate(Sender: TObject);
    procedure CloseButtonClick(Sender: TObject);
    procedure CopyButtonClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MyForm: TMyForm;

implementation

{$R *.DFM}

procedure TMyForm.FormCreate(Sender: TObject);
begin
  // as the form is created, make sure it doesn't
  // paint its client area ...
  Brush.Style:=bsClear;
end;

procedure TMyForm.CloseButtonClick(Sender: TObject);
begin
  halt;
end;

procedure TMyForm.CopyButtonClick(Sender: TObject);
var
  newBitmap: TBitmap; // We need this to work with.
  ScreenDC: HDC;      // This will let us access the 'desktop'.
  REOrg: TPoint;      // Origin of our Form's client area.
  X,Y: Integer;       // Holds coordinates.
  P,I,M: PByteArray;  // For faster (than Pixels[]) access.
begin
  // Create a new bitmap:
  newBitmap:=TBitmap.Create;
  try
    // Now assign this bitmap to our image:
    MyImage.Picture.Graphic:=newBitmap;
    // Get our form's width/height for the new image:
    MyImage.Picture.Graphic.Width:=MyForm.ClientWidth;
    MyImage.Picture.Graphic.Height:=MyForm.ClientHeight;
    // Get the forms origin:
    REOrg:=MyForm.ClientToScreen(Point(0,0));
    // Allow access to the desktop:
    ScreenDC:=GetDC(0);
    try
      // Copy the desktop area under the form, to our image:
      BitBlt(MyImage.Picture.Bitmap.Canvas.Handle,0,0,MyForm.ClientWidth,MyForm.ClientHeight,ScreenDC,REOrg.X, REOrg.Y, SRCCOPY);
    finally
      // Release the desktop DC again:
      ReleaseDC(0, ScreenDC);
    end;
  finally
    // Release our temporary bitmap:
    newBitmap.Free;
  end;
  // Convert our images to true colour:
  MyImage.Picture.Bitmap.HandleType:=bmDIB;
  MyImage.Picture.Bitmap.PixelFormat:=pf24Bit;
  LogoMap.Picture.Bitmap.HandleType:=bmDIB;
  LogoMap.Picture.Bitmap.PixelFormat:=pf24Bit;
  LogoMask.Picture.Bitmap.HandleType:=bmDIB;
  LogoMask.Picture.Bitmap.PixelFormat:=pf24Bit;
  // Process the pixels:
  For Y:=0 to Height-1 do begin
    P:=MyImage.Picture.Bitmap.ScanLine[Y];
    I:=LogoMap.Picture.Bitmap.ScanLine[Y];
    M:=LogoMask.Picture.Bitmap.ScanLine[Y];
    For X:=0 to (Width)*3-1 do
      P[X]:=(P[X]*(256-M[X])+I[X]*(M[X])) div 256;
  end;
  // Make the image visible:
  MyImage.Visible:=True;
end;

end.






I found it on the net.
Drop here your email, so I can send you.
It's a cool effect.

bryan

0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344698
It drops a transparent picture on the desktop.

0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1344699
bryan7

this sounds good but it does not draw on the desktop it captures a picture of the desktop and places it on the form and then paints the bitmap over the form with the captured desktop image...

But nice affect anyway...

Later
BoRiS
0
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.

 
LVL 4

Expert Comment

by:BoRiS
ID: 1344700
bryan7

this sounds good but it does not draw on the desktop it captures a picture of the desktop and places it on the form and then paints the bitmap over the form with the captured desktop image...

But nice affect anyway...

Later
BoRiS
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344701
I've tested it, and it drops a bitmap on the desktop, really.
A simple TImage picture. Please check it.

I'll send you too.
( With this, I don't mean to get points, then just to help )

bryan

0
 
LVL 4

Expert Comment

by:erajoj
ID: 1344702
Sorry Bryan, if the code you send is the one you're referring to; you're wrong.
Boris is right. However, you show how to copy parts of the screen's device context to a bitmap, and that's good knowledge as well, although the masking code is quite bulky/clumsy, but that's not the issue here.

ndthang, just remember that what you draw on the screen's device context is very volatile. Any change might erase what you drew.

/// John
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344703
Hey... I didn't understand anything of the code I dropped.. ;(

So I have no idea on how it works.
But, please, check it, it drops picture on the desktop, and mixes with it, I mean,
the picture seems transparent.

And, if you push the button more than once, after some pushes the transparency
dissapears.

Please, let me send you and know what you think.

bryan

0
 

Author Comment

by:ndthang
ID: 1344704
Thank you very much for every thing you teach me.

Boris's answer is quite right. But Bryan's code is very useful for me.

See you.

ndthang@geocities.com

0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1344705
bryan7

The code you sent is very helpful, I must say, also can you mail it to me to take a proper look at it...

Thank you for the help, it's good to see that we are all willing to share our knowledge

phillip@vwv.com

Later
BoRiS
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344706
Ok, there you have it.
If someone else wants it, just tell me.

bryan

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

Title # Comments Views Activity
How to convert wav to mp3 in delphi 9 171
Using FastMM4... should I enable MMX option? 9 75
Thread safe  opinion 7 126
Machine not responding during CopyFile() 3 89
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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

20 Experts available now in Live!

Get 1:1 Help Now