Results 1 to 29 of 29

Thread: [RESOLVED] Have a form that's not really there...

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Resolved [RESOLVED] Have a form that's not really there...

    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.

  2. #2
    Hyperactive Member Datacide's Avatar
    Join Date
    Jun 2005
    Posts
    309

    Re: Have a form that's not really there...

    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:
    1. Private Sub Form_Click()
    2.  
    3.     Me.Visible = False
    4.     vbMouse.Click
    5.     Me.Visible = True
    6.  
    7. End Sub
    PHP in your FACE!

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Have a form that's not really there...

    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

  4. #4
    Hyperactive Member Datacide's Avatar
    Join Date
    Jun 2005
    Posts
    309

    Re: Have a form that's not really there...

    Is the other window part of the same program?
    PHP in your FACE!

  5. #5
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Resolved Re: Have a form that's not really there...

    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:
    1. Option Explicit
    2.  
    3. Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    4. Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
    5. Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
    6.  
    7. Public Sub GlassifyForm(frm As Form)
    8. Const RGN_DIFF = 4
    9. Const RGN_OR = 2
    10.  
    11. Dim outer_rgn As Long
    12. Dim inner_rgn As Long
    13. Dim wid As Single
    14. Dim hgt As Single
    15. Dim border_width As Single
    16. Dim title_height As Single
    17. Dim ctl_left As Single
    18. Dim ctl_top As Single
    19. Dim ctl_right As Single
    20. Dim ctl_bottom As Single
    21. Dim control_rgn As Long
    22. Dim combined_rgn As Long
    23. Dim ctl As Control
    24.  
    25.     If WindowState = vbMinimized Then Exit Sub
    26.  
    27.     ' Create the main form region.
    28.     wid = ScaleX(Width, vbTwips, vbPixels)
    29.     hgt = ScaleY(Height, vbTwips, vbPixels)
    30.     outer_rgn = CreateRectRgn(0, 0, wid, hgt)
    31.  
    32.     border_width = (wid - ScaleWidth) / 2
    33.     title_height = hgt - border_width - ScaleHeight
    34.     inner_rgn = CreateRectRgn( _
    35.         border_width, _
    36.         title_height, _
    37.         wid - border_width, _
    38.         hgt - border_width)
    39.  
    40.     ' Subtract the inner region from the outer.
    41.     combined_rgn = CreateRectRgn(0, 0, 0, 0)
    42.     CombineRgn combined_rgn, outer_rgn, _
    43.         inner_rgn, RGN_DIFF
    44.  
    45.     ' Create the control regions.
    46.     For Each ctl In Controls
    47.         If ctl.Container Is frm Then
    48.             ctl_left = ScaleX(ctl.Left, frm.ScaleMode, vbPixels) _
    49.                 + border_width
    50.             ctl_top = ScaleX(ctl.Top, frm.ScaleMode, vbPixels) _
    51.                 + title_height
    52.             ctl_right = ScaleX(ctl.Width, frm.ScaleMode, vbPixels) _
    53.                 + ctl_left
    54.             ctl_bottom = ScaleX(ctl.Height, frm.ScaleMode, vbPixels) _
    55.                 + ctl_top
    56.             control_rgn = CreateRectRgn( _
    57.                 ctl_left, ctl_top, _
    58.                 ctl_right, ctl_bottom)
    59.             CombineRgn combined_rgn, combined_rgn, _
    60.                 control_rgn, RGN_OR
    61.         End If
    62.     Next ctl
    63.  
    64.     ' Restrict the window to the region.
    65.     SetWindowRgn hWnd, combined_rgn, True
    66. End Sub
    67.  
    68.  
    69. Private Sub Form_Resize()
    70.     GlassifyForm Me
    71. End Sub
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Have a form that's not really there...

    Quote Originally Posted by CVMichael
    And when I click on it, I actually want to click on the window behind it.
    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?

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Have a form that's not really there...

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Have a form that's not really there...

    Quote Originally Posted by Hack
    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?
    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.

    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

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Have a form that's not really there...

    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...
    Attached Images Attached Images  
    Last edited by CVMichael; Sep 9th, 2005 at 10:22 AM.

  10. #10
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Have a form that's not really there...

    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.

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Have a form that's not really there...

    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 ?
    Attached Images Attached Images  

  12. #12
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Have a form that's not really there...

    Quote Originally Posted by CVMichael
    ...But how do I know what window is below depending on where the mouse is ? ...
    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.

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Have a form that's not really there...

    Call me stupid, but I don't get it

    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 ?

  14. #14
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Have a form that's not really there...

    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 ...

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Have a form that's not really there...

    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...

  16. #16
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Have a form that's not really there...

    All OS's, or just 2000+?

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Have a form that's not really there...

    Quote Originally Posted by penagate
    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...

    I'm targetting for XP (and up)

  18. #18
    Lively Member rm_03's Avatar
    Join Date
    Aug 2004
    Posts
    92

    Re: Have a form that's not really there...

    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.

  19. #19
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Have a form that's not really there...

    Quote Originally Posted by rm_03
    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().

    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.

  20. #20

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Have a form that's not really there...

    Quote Originally Posted by rm_03
    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.
    I was saying the same thing on post #11
    The problem is that my form is always on top, so that API will return my window not the on ebelow it.

  21. #21

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Have a form that's not really there...

    Quote Originally Posted by penagate
    I thought I had it with SendInput but then I realised it was simply duplicating the messages to your own window.
    What's wrong about that ?
    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.

  22. #22
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Have a form that's not really there...

    Well it never reaches the window below, it just triggers another mouse event on your window.

  23. #23
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Have a form that's not really there...

    OMG... I can't believe I didn't think of this before.

    VB Code:
    1. SetWindowLong Me.hWnd, GWL_EXSTYLE, GetWindowLong(Me.hWnd, WS_EXSTYLE) Or WS_EX_TRANSPARENT



    Edit: WS_EX_TRANSPARENT = &H20.

  24. #24

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Have a form that's not really there...

    OW MY GOD, THAT ACTUALLY WORKS !!!!!
    NICE !!!!
    THANK YOU

    WAW... very nice !

  25. #25
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Have a form that's not really there...

    No worries, I knew it was something simple like that

  26. #26

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Have a form that's not really there...

    One question though...

    How do I "undo" that ?

    I mean if I want to reset it, and be able to click on it ?

  27. #27
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Have a form that's not really there...

    Replace Or with And Not.

  28. #28

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Have a form that's not really there...

    Yup, it worked with "And Not":
    VB Code:
    1. SetWindowLong Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) And Not WS_EX_TRANSPARENT
    Thanks again...

    PS, it's so weird when you actually want to click on it, and you can't

  29. #29
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [RESOLVED] Have a form that's not really there...

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width