Thanks Jez. Your suggestions seems to work except for the last thing. As I move the cursor over windows, how do I repaint windows that no longer have the cursor over them? Is there a way to get all the windows to repaint? Disposing of the DC did not seem to do this?

Steve
http://www.basgetti.com

----- Original Message ----- From: "Jeremy White" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Cc: <perl-win32-gui-users@lists.sourceforge.net>
Sent: Tuesday, August 16, 2005 2:58 AM
Subject: RE: [perl-win32-gui-users] Re: Draggable 'window' [Was: MDIFrame and background Image]



Well, I have got close but I am not sure how to make the Drawn rectangle transparent or how to dispose of the DC after I am through.. Any help would be greatly appreciated.

You'll be glad to know, that the solution is straightforward:) It's probably worth explaining a few things for the benifit of other readers.

In a normal situation you would have a Win32::GUI DC object and you would call methods upon it such as $dc->Rectangle($left,$top,$right,$bottom).

You can also call the Rectangle function in procedural form, you just need to pass a DC object or a valid handle:

$dc->Rectangle($left,$top,$right,$bottom);
Win32::GUI::DC::Rectangle($dc,$left,$top,$right,$bottom);

The above two calls are equivalent. But you don't need to pass an object at all:

Win32::GUI::DC::Rectangle(18947123,$left,$top,$right,$bottom);

If 18947123 is a valid DC, then you'll get a rectangle drawn. So you can use all the DC 'methods', as function calls passing in your handles.

As the rectangle function draws with the current pen and fills with the current brush, one way would be:

sub drawRectangle{
#usage: my $ok=drawRectangle($hdc,$left,$top,$right,$bottom);
#info: returns the handle of a device context for the specified window.
my $hdc=shift || return;
my $left=shift || 0;
my $top=shift || 0;
my $right=shift || 0;
my $bottom=shift || 0;
#my $Rectangle = new Win32::API("gdi32", "Rectangle", ['N','I','I','I','I'], 'N') || return $^E;
Win32::GUI::DC::Line($hdc,$left,$top,$right,$top);
Win32::GUI::DC::Line($hdc,$right,$top,$right,$bottom);
Win32::GUI::DC::Line($hdc,$right,$bottom,$left,$bottom);
Win32::GUI::DC::Line($hdc,$left,$bottom,$left,$top);
#my $ok=$Rectangle->Call($hdc,$left,$top,$right,$bottom);
return $hdc;
}

Perhaps the better solution in this case would be to use the FrameRect function (notice how you can mix and match real Win32::GUI objects and handles):

sub drawRectangle{
#usage: my $ok=drawRectangle($hdc,$left,$top,$right,$bottom);
#info: returns the handle of a device context for the specified window.
my $hdc=shift || return;
my $left=shift || 0;
my $top=shift || 0;
my $right=shift || 0;
my $bottom=shift || 0;
#my $Rectangle = new Win32::API("gdi32", "Rectangle", ['N','I','I','I','I'], 'N') || return $^E;
my $brush      = new Win32::GUI::Brush([255,0,0]);
Win32::GUI::DC::FrameRect($hdc,$left,$top,$right,$bottom,$brush);
#my $ok=$Rectangle->Call($hdc,$left,$top,$right,$bottom);
return $hdc;
}

As for releasing the DC, you could use the ReleaseDC function - but you'll have to pass the window handle and well as the DC handle:

Win32::GUI::DC::ReleaseDC($windowhandle,$hdc);

Cheers,

jez.





--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.10.10/73 - Release Date: 8/15/2005




Reply via email to