 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
harrie Guest
|
Posted: Fri Apr 06, 2007 7:25 pm Post subject: Drawing On A Transparent Form |
|
|
Hi there,
I've been trying to emulate a [adobe] apollo sample program in Delphi
that draws on a transparent window such that the windows underneath
continue to update. But I can't crack it >:|
Is anybody else up for the challenge? The sample [ScreenPlay] is
available here:
http://labs.adobe.com/wiki/index.php/Apollo:Applications:Samples
Cheers, harrie. |
|
| Back to top |
|
 |
JD Guest
|
Posted: Sun Apr 08, 2007 8:11 am Post subject: Re: Drawing On A Transparent Form |
|
|
harrie <user (AT) domain (DOT) invalid> wrote:
| Quote: |
I've been trying to emulate [...] that draws on a transparent
window such that the windows underneath continue to update.
|
It's unclear what it is that you want to accomplish.
| Quote: | Is anybody else up for the challenge? The sample [ScreenPlay]
is available here:
|
I would suggest that your lack of response is directly related
to the vagary of the the link that you posted. IOW, exectly
what should I be looking at from that link?
I'm thinking that you want to go one of two ways so the odds
are 50/50 that I'll spend the next 20 minutes explaining some
thing that you don't want so I'll reserve comment until I know
exactly what it is that you want to accomplish.
~ JD |
|
| Back to top |
|
 |
harrie Guest
|
Posted: Tue Apr 10, 2007 5:01 am Post subject: Re: Drawing On A Transparent Form |
|
|
Hi JD,
thanks for your response.
JD wrote:
| Quote: | harrie <user (AT) domain (DOT) invalid> wrote:
I've been trying to emulate [...] that draws on a transparent
window such that the windows underneath continue to update.
It's unclear what it is that you want to accomplish.
Is anybody else up for the challenge? The sample [ScreenPlay]
is available here:
I would suggest that your lack of response is directly related
to the vagary of the the link that you posted. IOW, exectly
what should I be looking at from that link?
|
I'm trying to create a delphi program with the same functionality as the
Apollo demo program called ScreenPlay - which unfortunately requires the
installation of the Apollo runtime to work. I've tried to explain it's
functionality where it has a full-screen transparent window upon which
you can draw lines in different colours and thickness - that's it. I
know it doesn't make sense .. drawing on a transparent window .. but I
guess you need to run it to understand ..
The direct link to the demo is:
http://download.macromedia.com/pub/labs/apollo/sample_apps/ScreenPlay.air
But you will need to install the runtime - which requires an Adobe Labs
registration to be able to download. I thought this might have been the
reason no one was interested?? If anyone really objects to having to
register the direct link to the installer is:
http://download.macromedia.com/pub/labs/apollo/installers/apollo_win_alpha1_031907.msi
| Quote: |
I'm thinking that you want to go one of two ways so the odds
are 50/50 that I'll spend the next 20 minutes explaining some
thing that you don't want so I'll reserve comment until I know
exactly what it is that you want to accomplish.
~ JD
|
|
|
| Back to top |
|
 |
Jens Gruschel Guest
|
Posted: Wed Apr 11, 2007 2:13 am Post subject: Re: Drawing On A Transparent Form |
|
|
| Quote: | I'm trying to create a delphi program with the same functionality as the
Apollo demo program called ScreenPlay - which unfortunately requires the
installation of the Apollo runtime to work. I've tried to explain it's
functionality where it has a full-screen transparent window upon which
you can draw lines in different colours and thickness - that's it. I
know it doesn't make sense .. drawing on a transparent window .. but I
guess you need to run it to understand ..
|
You can
a) capture the screen to a bitmap
b) create a borderless form
c) draw the bitmap you captured onto your form
d) draw lines or whatever onto the form
However this is very static, you won't see any changes which might occur
below your window (let's say there is a clock with moving hands).
On Windows 2K/XP you can make use of transparent windows supported by
the OS, which allows to define a color, which is used for transparency.
Delphi 6 and later versions support that directly (see TransparentColor
and TransparentColorValue properties of your form). Otherwise take a
look at SetLayeredWindowAttributes (http://preview.tinyurl.com/yjd3p7)
or search for a 3rd party Delphi component encapsulating it.
A third approach is to draw to the zero device context directly, however
I don't really recommend it.
--
Jens Gruschel
http://www.pegtop.net |
|
| Back to top |
|
 |
Eddie Shipman Guest
|
Posted: Wed Apr 11, 2007 2:19 am Post subject: Re: Drawing On A Transparent Form |
|
|
<SNIP>
| Quote: | I'm trying to create a delphi program with the same functionality as
the Apollo demo program called ScreenPlay - which unfortunately
requires the installation of the Apollo runtime to work. I've tried
to explain it's functionality where it has a full-screen transparent
window upon which you can draw lines in different colours and
thickness - that's it. I know it doesn't make sense .. drawing on a
transparent window .. but I guess you need to run it to understand ..
SNIP |
Problem is, if you create a transparent desktop window, anything you
draw on it will be transparent, too.
I see no way of doing this with straight GDI, maybe it is something new
in GDI+? |
|
| Back to top |
|
 |
harrie Guest
|
Posted: Wed Apr 11, 2007 4:22 am Post subject: Re: Drawing On A Transparent Form |
|
|
| Quote: | Problem is, if you create a transparent desktop window, anything you
draw on it will be transparent, too.
|
I used a transparent form to track mouse movements and actions and then
drew to the desktop window but of course as soon as another window was
given focus the drawings over it would be lost. Whereas the ScreenPlay
program is able to repaint the lines drawn so it must be masking the
drawings over a transparent form/window in some way.
| Quote: |
I see no way of doing this with straight GDI, maybe it is something new
in GDI+?
|
good tip .. I'll look into GDI+
a curious thing is that my program that drew on the desktop window was
not able to draw on the ScreenPlay window when it was a background
window but any kind of program window could repaint over it? |
|
| Back to top |
|
 |
harrie Guest
|
Posted: Wed Apr 11, 2007 4:25 am Post subject: Re: Drawing On A Transparent Form |
|
|
| Quote: | You can
a) capture the screen to a bitmap
b) create a borderless form
c) draw the bitmap you captured onto your form
d) draw lines or whatever onto the form
However this is very static, you won't see any changes which might occur
below your window (let's say there is a clock with moving hands).
On Windows 2K/XP you can make use of transparent windows supported by
the OS, which allows to define a color, which is used for transparency.
Delphi 6 and later versions support that directly (see TransparentColor
and TransparentColorValue properties of your form). Otherwise take a
look at SetLayeredWindowAttributes (http://preview.tinyurl.com/yjd3p7)
or search for a 3rd party Delphi component encapsulating it.
A third approach is to draw to the zero device context directly, however
I don't really recommend it.
|
None of these methods reproduce the behaviour of the ScreenPlay program.
I'm going to look into GDI+ as suggested by Eddie. |
|
| Back to top |
|
 |
Jens Gruschel Guest
|
Posted: Wed Apr 11, 2007 4:35 am Post subject: Re: Drawing On A Transparent Form |
|
|
| Quote: | None of these methods reproduce the behaviour of the ScreenPlay program.
|
Sorry, I don't want to install the runtime library you mentioned, so I
don't know what exactly is wrong with the approaches I suggested.
Drawing any kind of things should be possible, however you might need to
combine it with other techniques for example when it comes to capture
the mouse cursor.
Transparent forms Windows provides by the way are not limited to a
single transparent color, you can also work with an alpha mask, however
that's a bit more difficult and not supported by Delphi directly.
--
Jens Gruschel
http://www.pegtop.net |
|
| Back to top |
|
 |
Eddie Shipman Guest
|
Posted: Thu Apr 12, 2007 12:52 am Post subject: Re: Drawing On A Transparent Form |
|
|
harrie wrote:
| Quote: | You can
a) capture the screen to a bitmap
b) create a borderless form
c) draw the bitmap you captured onto your form
d) draw lines or whatever onto the form
However this is very static, you won't see any changes which might
occur below your window (let's say there is a clock with moving
hands).
On Windows 2K/XP you can make use of transparent windows supported
by the OS, which allows to define a color, which is used for
transparency. Delphi 6 and later versions support that directly
(see TransparentColor and TransparentColorValue properties of your
form). Otherwise take a look at SetLayeredWindowAttributes
(http://preview.tinyurl.com/yjd3p7) or search for a 3rd party
Delphi component encapsulating it.
A third approach is to draw to the zero device context directly,
however I don't really recommend it.
None of these methods reproduce the behaviour of the ScreenPlay
program. I'm going to look into GDI+ as suggested by Eddie.
|
Have you asked in the Adobe forums how they do it? Sometimes
they will give you an idea of how it's being done if you ask the right
queestion nicely. ;-)
-- |
|
| Back to top |
|
 |
harrie Guest
|
Posted: Thu Apr 12, 2007 4:32 pm Post subject: Re: Drawing On A Transparent Form |
|
|
Hi Jens,
apologies for my statement below as I've got it working using
SetLayeredWindowAttributes as you suggested :-$
It's quite crude but effective using two forms. First I set the main
form's AlphaBlendValue to 1 and use this to catch mouse movements and
actions and then have a second form over this that is totally
transparent using SetLayeredWindowAttributes with LWA_COLORKEY and then
simply draw on this form using any colour other than the transparent colour.
Thanks again for the tip.
here's the wrapper function I used if anyone's interested:
function SetLayeredWindowAttributes(Wnd: HWND; ColorKey: Cardinal;
BlendLevel: Integer): Boolean;
type
TSetLayeredWindowAttributes = function(Handle: HWND; crKey: DWORD;
bAlpha: Byte; dwFlags: DWORD): BOOL; stdcall;
const
WS_EX_LAYERED = $00080000;
LWA_COLORKEY = $00000001;
LWA_ALPHA = $00000002;
var
SetLayeredWindowAttributes: TSetLayeredWindowAttributes;
h: THandle;
dwStyle: DWORD;
Alpha: byte;
begin
Result := False;
h := LoadLibrary('user32.dll');
if (h <> 0) then
begin
try
@SetLayeredWindowAttributes := GetProcAddress(h,
'SetLayeredWindowAttributes');
Alpha := (255 * BlendLevel) div 100;
dwStyle := GetWindowLong(Wnd, GWL_EXSTYLE);
SetWindowLong(Wnd, GWL_EXSTYLE, dwStyle or WS_EX_LAYERED);
if (@SetLayeredWindowAttributes <> nil) then
SetLayeredWindowAttributes(Wnd, ColorKey, Alpha, LWA_COLORKEY);
Result := True;
finally
FreeLibrary(h);
end;
end;
end;
Cheers, harrie
| Quote: | None of these methods reproduce the behaviour of the ScreenPlay program.
Sorry, I don't want to install the runtime library you mentioned, so I
don't know what exactly is wrong with the approaches I suggested.
Drawing any kind of things should be possible, however you might need to
combine it with other techniques for example when it comes to capture
the mouse cursor.
Transparent forms Windows provides by the way are not limited to a
single transparent color, you can also work with an alpha mask, however
that's a bit more difficult and not supported by Delphi directly.
|
|
|
| Back to top |
|
 |
Jens Gruschel Guest
|
Posted: Fri Apr 13, 2007 12:35 am Post subject: Re: Drawing On A Transparent Form |
|
|
| Quote: | It's quite crude but effective using two forms. First I set the main
form's AlphaBlendValue to 1 and use this to catch mouse movements and
actions
|
I guess the main problem is to keep the z-order of both forms. Just some
loud thinking... an alternative might be to setup a mouse hook (see
SetWindowsHookEx), but IMO that might create more problems than it
solves, or simply to poll the mouse (call GetCursorPos and
GetAsyncKeyState for VK_LBUTTON in a timer), but it might be less exact.
Maybe using SetCapture will also work to get mouse messages for the
transparent area, but the initial mouse down event might be problematic.
--
Jens Gruschel
http://www.pegtop.net |
|
| Back to top |
|
 |
harrie Guest
|
Posted: Fri Apr 13, 2007 6:53 pm Post subject: Re: Drawing On A Transparent Form |
|
|
| Quote: | I guess the main problem is to keep the z-order of both forms. Just some
loud thinking... an alternative might be to setup a mouse hook (see
SetWindowsHookEx), but IMO that might create more problems than it
solves, or simply to poll the mouse (call GetCursorPos and
GetAsyncKeyState for VK_LBUTTON in a timer), but it might be less exact.
Maybe using SetCapture will also work to get mouse messages for the
transparent area, but the initial mouse down event might be problematic.
|
I haven't noticed [or understood] any problems with the z-order .. but
there were issues with the drawings on the [2nd form] canvas being lost
on when the application or desktop was minimised. i got around this by
duplicating all drawings to a bitmap which I copy back to the canvas
when the application is activated or restored.
BTW the colour key functionality I used with SetLayeredWindowAttributes
is actaully available on a Delphi form using TransparentColorValue and
TransparentColor.
Cheers, harrie. |
|
| Back to top |
|
 |
Jens Gruschel Guest
|
Posted: Fri Apr 13, 2007 10:07 pm Post subject: Re: Drawing On A Transparent Form |
|
|
| Quote: | I haven't noticed [or understood] any problems with the z-order .. but
there were issues with the drawings on the [2nd form] canvas being lost
on when the application or desktop was minimised. i got around this by
duplicating all drawings to a bitmap which I copy back to the canvas
when the application is activated or restored.
|
Better draw to the bitmap all the time because the same problem appears
if another window is in front of your windows temporary.
| Quote: | BTW the colour key functionality I used with SetLayeredWindowAttributes
is actaully available on a Delphi form using TransparentColorValue and
TransparentColor.
|
What I said before :-)
--
Jens Gruschel
http://www.pegtop.net |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|