Solved

How to draw DIRECT to Desktop Windows?

Posted on 1998-10-28
13
218 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
It drops a transparent picture on the desktop.

0
 
LVL 4

Expert Comment

by:BoRiS
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 4

Expert Comment

by:BoRiS
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Ok, there you have it.
If someone else wants it, just tell me.

bryan

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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 video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

10 Experts available now in Live!

Get 1:1 Help Now