Attached are a couple of examples of creating transparent windows with visible controls, but that don't allow the clicks to pass through.
Since SetLayeredWindowAttributes API won't let you set the Alpha for just one particular colour - you have to make use of two forms.
Glass Form.zip
Very simple example of creating a glass form. Although this (and the following example) use two forms, all the code and controls are contained on one form - with the fEvents object being used to manage events on the transparent parts.
Tracing App.zip - updated
This example is a bit more complex (and actually has function!). This app acts a sheet of glass which youu can move around and draw on. Here's my tracing of a monkey:
(if you think that's bad then imagine what it would've been like if I'd drawn it free hand!)
The bottom-right circle can be used for resizing. The top and bottom left are for moving the form. And the three buttons in the top-right do their usual things. Click on the block of colour to change the colour and use the dropdown to change the pen width. The save button will allow you to save your picture, but the background will be Cyan and not transparent (although you could implement saving with transparency if you wanted)
In order to stop the taskbar button changing (from checked to unchecked) everytime you clicked on a transparent part of the form, the app finds the button and ensure's it stays checked - I've avoided using subclassing at all.
When the form gets big the drawing time really slows down - there are probably much better ways of drawing on the form - but since I know very little about graphics, I haven't attempted them.
I can't really think of real world application for this code - but it's pretty cool
Any bugs, comments or suggestions then post them here.
As with anything using SetLayeredWindowAttributes, this will only work on 2000 and later
If you find that the clicks are passing through then try increasing the number in the SetTrans fEvents, 1 line in Form_Load - see posts #9, #10 & #11
Last edited by bushmobile; Jul 11th, 2006 at 02:05 PM.
Reason: Updated Pic
The tracing from is transparent. When I click left button, the background form gets focus. There is no canvas to draw on.
Now I'm confused.
Are you saying it doesn't work for you? If you click and drag somewhere within the rectangle created by the four corner circles does it not draw a line?
Are you saying it doesn't work for you? If you click and drag somewhere within the rectangle created by the four corner circles does it not draw a line?
Nope. It just makes the form transparent. (like regioning)
On second check, the glass form acts same. It is not acting as a GLASS.
Run-time error '5':
Invalid procedure call or argument.
Cause:
No minimum form size.
Fix:
Declare module-level variables MinWidth and MinHeight, assign values in Form_Load event. In picSize_MouseMove event procedure, declare variable for new left, top, width and height values. Test new width and height against minimums. If dragging from top left (Case 0), keep previous top and/or left values to prevent moving of form if height and/or width are forced to minimum.
Run-time error '384':
A form cannot be moved or sized while minimized or maximized.
Cause:
No means to prevent resize while maximized.
Fix:
In picSize_MouseDown event procedure, do nothing if WindowState <> vbNormal
I have no idea what I could possibly use it for other than to just mess around (getting absolutely NO work done at all). I guess more code should be written in just the name of fun.
Very nice program. One good use for the program is for screen mark-up when you are doing an LCD presentation. It works almost perfectly for this. My only request is, how about semi-transparent ink for the mark up. As it stands now, the ink is opaque and so obliterates what is written in a window beneath. I prefer to have more of a highliter look to the ink so you can see through to the writing below.
Can you add transparency 10% 25% 50% 75% 90% or something like that?