Solved

How to draw DIRECT to Desktop Windows?

Posted on 1998-10-28
13
242 Views
Last Modified: 2010-04-06
Some code in delphi.
Thanks.
0
Comment
Question by:ndthang
[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
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

624 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