Transparent form that intercepts mouse events

P

pigeonrandle

Hi,
I am trying (with little (no) success) to create a transparent form
that can capture mouse events. Put another way, i would like to show
the other windows that are behind my form (like setting the form
transparency key to the form backcolor), but i dont want the mouse
clicks to pass through my form and on to the windows behind.

Can i perhaps do this with a message filter? by deregistering the
filter that must already be there to pass the mouse clicks on? or maybe
by overriding WndProc and handling the mouse events there?

If anyone has any ideas as to how i might accomplish this, then i will
herald them as an intellectual leviathan!

James Randle.

PS I also posted this in csharp earlier, but on reading some other
posts on similar topics thought this might be a better arena :blush:).
 
M

Michael C

pigeonrandle said:
Hi,
I am trying (with little (no) success) to create a transparent form
that can capture mouse events. Put another way, i would like to show
the other windows that are behind my form (like setting the form
transparency key to the form backcolor), but i dont want the mouse
clicks to pass through my form and on to the windows behind.

Can i perhaps do this with a message filter? by deregistering the
filter that must already be there to pass the mouse clicks on? or maybe
by overriding WndProc and handling the mouse events there?

If anyone has any ideas as to how i might accomplish this, then i will
herald them as an intellectual leviathan!

James Randle.

PS I also posted this in csharp earlier, but on reading some other
posts on similar topics thought this might be a better arena :blush:).

Sounds to me like you're using the wrong approach. What are you trying to
do?
 
R

RichS

I wrote a transparent app a while ago and used the forms Opacity values
along with the following bit of code. I controlled my ClickThrough
property with a System Tray icon. You may be able to achieve what you
want through the following code and the PerPixelAlphaBlending stuff on
codeproject.com.

I messed around with the TransparencyKey stuff and given what you ask
for, I dont think it is appropriate for what you are trying to achieve.



public bool ClickThrough
{
get{ return this.bClickThrough; }
set
{
if ( this.bClickThrough != value )
{
this.bClickThrough = value;

if ( true == this.bClickThrough )
{
// Add the WS_EX_TRANSPARENT Style
long lStyle = Interop.GetWindowLong(
this.Handle, Interop.GWL_EXSTYLE );
lStyle |= ( Interop.WS_EX_TRANSPARENT );
Interop.SetWindowLong( this.Handle,
Interop.GWL_EXSTYLE, lStyle );
}
else
{
// Remove the WS_EX_TRANSPARENT Style
long lStyle = Interop.GetWindowLong(
this.Handle, Interop.GWL_EXSTYLE );
lStyle &= ( ~Interop.WS_EX_TRANSPARENT );
Interop.SetWindowLong( this.Handle,
Interop.GWL_EXSTYLE, lStyle );
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top