I want to have a form that all my actions go through it.
Actually, my form is semi transparent that is always on top most, and I just want to display information on it. And when I click on it, I actually want to click on the window behind it.
Printable View
I want to have a form that all my actions go through it.
Actually, my form is semi transparent that is always on top most, and I just want to display information on it. And when I click on it, I actually want to click on the window behind it.
Try using me.show = false when the user clicks it, then make the code click again, then show the form again
something like this...
VB Code:
Private Sub Form_Click() Me.Visible = False vbMouse.Click Me.Visible = True End Sub
That does not look like an acceptable solution to me...
To make the form invisible/visible everytime you click or move the mouse ? I don't think so....
The form will flicker like crazy
Is the other window part of the same program?
is this what you are looking for:
if you want to have the form with no titlebar too just change the form borderstyle = 0 - none
VB Code:
Option Explicit Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long Public Sub GlassifyForm(frm As Form) Const RGN_DIFF = 4 Const RGN_OR = 2 Dim outer_rgn As Long Dim inner_rgn As Long Dim wid As Single Dim hgt As Single Dim border_width As Single Dim title_height As Single Dim ctl_left As Single Dim ctl_top As Single Dim ctl_right As Single Dim ctl_bottom As Single Dim control_rgn As Long Dim combined_rgn As Long Dim ctl As Control If WindowState = vbMinimized Then Exit Sub ' Create the main form region. wid = ScaleX(Width, vbTwips, vbPixels) hgt = ScaleY(Height, vbTwips, vbPixels) outer_rgn = CreateRectRgn(0, 0, wid, hgt) border_width = (wid - ScaleWidth) / 2 title_height = hgt - border_width - ScaleHeight inner_rgn = CreateRectRgn( _ border_width, _ title_height, _ wid - border_width, _ hgt - border_width) ' Subtract the inner region from the outer. combined_rgn = CreateRectRgn(0, 0, 0, 0) CombineRgn combined_rgn, outer_rgn, _ inner_rgn, RGN_DIFF ' Create the control regions. For Each ctl In Controls If ctl.Container Is frm Then ctl_left = ScaleX(ctl.Left, frm.ScaleMode, vbPixels) _ + border_width ctl_top = ScaleX(ctl.Top, frm.ScaleMode, vbPixels) _ + title_height ctl_right = ScaleX(ctl.Width, frm.ScaleMode, vbPixels) _ + ctl_left ctl_bottom = ScaleX(ctl.Height, frm.ScaleMode, vbPixels) _ + ctl_top control_rgn = CreateRectRgn( _ ctl_left, ctl_top, _ ctl_right, ctl_bottom) CombineRgn combined_rgn, combined_rgn, _ control_rgn, RGN_OR End If Next ctl ' Restrict the window to the region. SetWindowRgn hWnd, combined_rgn, True End Sub Private Sub Form_Resize() GlassifyForm Me End Sub
If I understand this correctly, you want to click on one form but have that click activate or perform some action on the form behind it, is that right?Quote:
Originally Posted by CVMichael
Sounds like it to me too. You could use the Form_Click event in your TopMost form to call the Form_Click in your underlying form.
Basically, I want the computer to act as if there is nothing there... You can't do anything to it, except view it on the screen... and I want it on top most.Quote:
Originally Posted by Hack
I will have a tray icon, where I can "enable it" so that you can actually click on it, and do whatever, but when in "viewing" mode, I just want it displaid on the screen that's it...
wiz126, I'll try your code shortly, thanks
I attached a picture to show what I want.
As you can see there is a semi transparent window (title Continous Backup) that is on top of Display Properties.
You can see the "OK" button, I want to click on the OK button, but I can't because the Continous Backup window is on top of it...
And actually, wiz126's code won't work because it makes my form complectly transparent, except the objects. And I don't want that...
I want the form as it is now, and be able to click "through" it anywhere on the form (well, maybe not the title bar, so I can move the window around).
Edit
Ow... And I also want it so you can't get the focus on it, when in "viewing" mode...
Michael,
you'd have to create a low level hooking so you can intersept all mouse and/or keyboard activities. I would recommend to look @ vbAccelerator's Journal (or something like that) sample project. Also, you would need to trap mouse movements but that is a simple thing. You would do all of this from underlying form(s) and from the top one. And the last thing: Karl E. Peterson has very nice sample to make form translucent so take a look at it.
I just realized, I only need the mouse to go through, because for the keyboard, the user would select the window first, then type. Even if my window is on top of it, typing in the window below still works.
But how do I know what window is below depending on where the mouse is ?
For example in the picture attached, there is the Display Properties window, and the tray.
How do I know if the mouse is over the Display Properties or the tray ? through my window ?
I think there is an API that returns the window handle by X, Y position of the mouse, but that API returns the window that is on top of the mouse, and in my case it is my window. But I need the window below mine...
Any clue ?
You don't have to know - you "dispatch" it from that window and not from the one that's transparent. So, if your "hooking" routine detects mouse click and mouse pointer is within one of your buttons boundaries then you know what to do.Quote:
Originally Posted by CVMichael
Call me stupid, but I don't get it :blush:
Why dispach it from that window, and not mine ?
I detect the mouse movement on mine, so I have to send the same message to the window below... right ?
Don't you have multiple forms in your app where one is transparent and rest of them are not and you want to "click" on the button that "belongs" to a form that's beneath the transparent ? Unless I misunderstood you completly and the form you want to click on is some external app ... :confused:
Display Properties and the tray IS an external app...
All the windows below mine are external applications, if they were mine, it would've been very easy to do...
Also... i don't want to click on that specific button, that was just an example...
Another example, if I have paint open, and my app on top of it, I want to be able to draw anything in paint while my form is on top of it...
All OS's, or just 2000+?
2000+, most of the API's i'm using already (like transparency, and the round corners) are pretty advanced, so i'm sure the app won't work on lower OS's...Quote:
Originally Posted by penagate
I'm targetting for XP (and up)
If I remember correctly there's an API for getting a window from a X/Y coordinate.
Then just subclass your window and redirect the mouse messages to
the hWnd returned by the API, if the coordinates get sent with the messages.
That would be WindowFromPoint().Quote:
Originally Posted by rm_03
Trouble is, your window is at that point. You need somehow to get the one beneath it.
I thought I had it with SendInput but then I realised it was simply duplicating the messages to your own window.
I was saying the same thing on post #11Quote:
Originally Posted by rm_03
The problem is that my form is always on top, so that API will return my window not the on ebelow it.
What's wrong about that ?Quote:
Originally Posted by penagate
If that sends the input to the window below, then that's all I need... I can just ignore the message on my window when in "viewing" mode.
Well it never reaches the window below, it just triggers another mouse event on your window.
OMG... I can't believe I didn't think of this before.
VB Code:
SetWindowLong Me.hWnd, GWL_EXSTYLE, GetWindowLong(Me.hWnd, WS_EXSTYLE) Or WS_EX_TRANSPARENT
:D
Edit: WS_EX_TRANSPARENT = &H20.
OW MY GOD, THAT ACTUALLY WORKS !!!!! :D :D :D :D :D :D :D :D
NICE !!!!
THANK YOU
WAW... very nice !
No worries, I knew it was something simple like that :D
One question though...
How do I "undo" that ? :)
I mean if I want to reset it, and be able to click on it ?
Replace Or with And Not.
Yup, it worked with "And Not":
Thanks again...VB Code:
SetWindowLong Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) And Not WS_EX_TRANSPARENT
PS, it's so weird when you actually want to click on it, and you can't :D :D
Yeah, I was clicking my form in the IDE and it kept disappearing, thought it was a bug until I realised it I hadn't set it topmost :)