Solved

Form Background

Posted on 1998-09-25
13
192 Views
Last Modified: 2010-04-30
If this is possible, how can i make the background of the form, the desktop, so the app would be like see-thru. Thanx!
0
Comment
Question by:cdc_sickle
  • 5
  • 3
  • 2
  • +3
13 Comments
 
LVL 2

Expert Comment

by:AllenC_Jr
Comment Utility

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
'*Note Taken From VB-Helper.Com Many Examples Are Held There
0
 

Author Comment

by:cdc_sickle
Comment Utility
This did not work
it compiled the program but the bg was still grey
0
 

Expert Comment

by:WolfgangRitter
Comment Utility
Load the WIN.INI file to get the background, then:

sub form1_load
      form1.picture = "(the picture)"
end sub

Ask me if you have any questions.

0
 

Expert Comment

by:PSV
Comment Utility
Hi
Is very much possible. There are two ways to do this.
First one (sometimes it doesn't work) is mentioned in MSDN in Topic "Transparent Control".

In the second approach U have to store the backround (just before your form get displayed) as DIB & display it on form_activate event. I am sure U can get code for this whole process from MSDN again.  But keep in mind that there are lot of problems involved like palette handling on 256 colors palette, changing image when form move to new place or resized.

0
 

Author Comment

by:cdc_sickle
Comment Utility
That form1.picture "(the picture)"
did not make the background of the form trans.
0
 

Author Comment

by:cdc_sickle
Comment Utility
That form1.picture "(the picture)"
did not make the background of the form trans.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 14

Expert Comment

by:waty
Comment Utility
Here is code to make a form transparent :

' *** Make form transparent
Declare Function CombineRgn Lib "GDI32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Declare Function CreateRectRgn Lib "GDI32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long

Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long

Public Const RGN_AND = 1
Public Const RGN_COPY = 5
Public Const RGN_DIFF = 4
Public Const RGN_OR = 2
Public Const RGN_XOR = 3

Private Type POINTAPI
   x As Long
   y As Long
End Type

Private Type RECT
   Left     As Long
   Top      As Long
   Right    As Long
   Bottom   As Long
End Type

Public Sub MakeFormTransparent(frm As Form)
   ' *** Make a form transparent
   
   Dim rctClient As RECT, rctFrame As RECT
   Dim hClient As Long, hFrame As Long
   
   ' *** Grab client area and frame area
   GetWindowRect frm.hWnd, rctFrame
   GetClientRect frm.hWnd, rctClient
   
   ' *** Convert client coordinates to screen coordinates
   Dim lpTL As POINTAPI, lpBR As POINTAPI
   lpTL.x = rctFrame.Left
   lpTL.y = rctFrame.Top
   lpBR.x = rctFrame.Right
   lpBR.y = rctFrame.Bottom
   ScreenToClient frm.hWnd, lpTL
   ScreenToClient frm.hWnd, lpBR
   rctFrame.Left = lpTL.x
   rctFrame.Top = lpTL.y
   rctFrame.Right = lpBR.x
   rctFrame.Bottom = lpBR.y
   rctClient.Left = Abs(rctFrame.Left)
   rctClient.Top = Abs(rctFrame.Top)
   rctClient.Right = rctClient.Right + Abs(rctFrame.Left)
   rctClient.Bottom = rctClient.Bottom + Abs(rctFrame.Top)
   rctFrame.Right = rctFrame.Right + Abs(rctFrame.Left)
   rctFrame.Bottom = rctFrame.Bottom + Abs(rctFrame.Top)
   rctFrame.Top = 0
   rctFrame.Left = 0
   
   ' *** Convert RECT structures to region handles
   hClient = CreateRectRgn(rctClient.Left, rctClient.Top, rctClient.Right, rctClient.Bottom)
   hFrame = CreateRectRgn(rctFrame.Left, rctFrame.Top, rctFrame.Right, rctFrame.Bottom)
   
   ' *** Create the new "Transparent" region
   CombineRgn hFrame, hClient, hFrame, RGN_XOR
   
   ' *** Now lock the window's area to this created region
   SetWindowRgn frm.hWnd, hFrame, True

End Sub

0
 

Author Comment

by:cdc_sickle
Comment Utility
To many errors in that, the public consts is the frst error that comes up
0
 
LVL 14

Expert Comment

by:waty
Comment Utility
What kind of errors? It works perfectly here on my computer...
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
Use Waty's code and put it in a module.

private sub form_load
 MakeFormTransparent me
end sub
0
 

Author Comment

by:cdc_sickle
Comment Utility
Public Sub MakeFormTransparent(frm As Form)
   ' *** Make a form transparent
   
   Dim rctClient As RECT, rctFrame As RECT
   Dim hClient As Long, hFrame As Long
   
   ' *** Grab client area and frame area
   GetWindowRect frm.hWnd, rctFrame
   GetClientRect frm.hWnd, rctClient
   
   ' *** Convert client coordinates to screen coordinates
   Dim lpTL As POINTAPI, lpBR As POINTAPI
   lpTL.x = rctFrame.Left
   lpTL.y = rctFrame.Top
   lpBR.x = rctFrame.Right
   lpBR.y = rctFrame.Bottom
   ScreenToClient frm.hWnd, lpTL
   ScreenToClient frm.hWnd, lpBR
   rctFrame.Left = lpTL.x

I get an error on the screentoclient stuff, when i put it in the modual
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 100 total points
Comment Utility
Add this line just before MakeFormTransparent

Declare Function ScreenToClient Lib "user32" Alias "ScreenToClient" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

0
 
LVL 14

Expert Comment

by:waty
Comment Utility
Oops, I forgot to had this declaration.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now