Solved

How to draw DIRECT to Desktop Windows?

Posted on 1998-10-28
13
228 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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 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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

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