cider in Orcas and VB.net

Suspended
Joined
15 Mar 2005
Posts
1,034
Location
cyrodiil
ok, so i've been trying to get this to work since i got vista, i'd really like to make some sort of transparent aero background on an application for college, i want the same sort of effect as Nero Reloaded to make an HCI assignment more fun. i need to do it in VB.net, as i'm awful at C - does anybody know what i need to call, or any good links for this as it's driving me up the wall
 
Had to have a play myself so here's the same effect in VB.NET for ya.



and the code

Code:
 [size=2][color=#0000ff]
Imports[/color][/size][size=2] System.Data
 
[/size][size=2][color=#0000ff]Imports[/color][/size][size=2] System.Drawing
 
[/size][size=2][color=#0000ff]Imports[/color][/size][size=2] System.Text
 
[/size][size=2][color=#0000ff]Imports[/color][/size][size=2] System.Windows.Forms
 
[/size][size=2][color=#0000ff]Imports[/color][/size][size=2] System.Runtime.InteropServices
 
[/size][size=2][color=#0000ff]Imports[/color][/size][size=2] System.Drawing.Drawing2D
 
[/size][size=2][color=#0000ff]Public[/color][/size][size=2][color=#0000ff]Class[/color][/size][size=2] Form1
 
[/size][size=2][color=#008000]' Import functions from dwmapi.dll - get this info from the sdk dwmapi.h
 
[/color][/size][size=2]<DllImport([/size][size=2][color=#a31515]"dwmapi.dll"[/color][/size][size=2], CharSet:=CharSet.Auto)> _
 
[/size][size=2][color=#0000ff]Public[/color][/size][size=2][color=#0000ff]Shared[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] DwmExtendFrameIntoClientArea([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] hWnd [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.IntPtr, [/size][size=2][color=#0000ff]ByRef[/color][/size][size=2] pMargins [/size][size=2][color=#0000ff]As[/color][/size][size=2] Margins)
 
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub
 
[/color][/size][size=2]<DllImport([/size][size=2][color=#a31515]"dwmapi.dll"[/color][/size][size=2], CharSet:=CharSet.Auto)> _
 
[/size][size=2][color=#0000ff]Public[/color][/size][size=2][color=#0000ff]Shared[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] DwmIsCompositionEnabled([/size][size=2][color=#0000ff]ByRef[/color][/size][size=2] IsIt [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Boolean[/color][/size][size=2])
 
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub
 
[/color][/size][size=2][color=#008000]' Create the brush that'll work around the Alpha transparency issue
 
[/color][/size][size=2][color=#0000ff]Private[/color][/size][size=2] DWMFrame [/size][size=2][color=#0000ff]As[/color][/size][size=2] SolidBrush = [/size][size=2][color=#0000ff]New[/color][/size][size=2] SolidBrush(Color.Black)
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] BlurBehind [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Boolean[/color][/size][size=2] = [/size][size=2][color=#0000ff]False
 
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] MaxTrans [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Boolean[/color][/size][size=2] = [/size][size=2][color=#0000ff]False
 
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] blurect [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Boolean[/color][/size][size=2] = [/size][size=2][color=#0000ff]False
 
[/color][/size][size=2][color=#008000]' Create an instance of the Margins struct for use in our form
 
[/color][/size][size=2][color=#0000ff]Private[/color][/size][size=2] inset [/size][size=2][color=#0000ff]As[/color][/size][size=2] Margins = [/size][size=2][color=#0000ff]New[/color][/size][size=2] Margins
 
[/size][size=2][color=#008000]' Define the Margins struct - get this from dwmapi.h
 
[/color][/size][size=2][color=#0000ff]Public[/color][/size][size=2][color=#0000ff]Structure[/color][/size][size=2] Margins
 
[/size][size=2][color=#0000ff]Public[/color][/size][size=2] Left [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Integer
 
[/color][/size][size=2][color=#0000ff]Public[/color][/size][size=2] Right [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Integer
 
[/color][/size][size=2][color=#0000ff]Public[/color][/size][size=2] Top [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Integer
 
[/color][/size][size=2][color=#0000ff]Public[/color][/size][size=2] Bottom [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Integer
 
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Structure
 
[/color][/size][size=2][color=#0000ff]Public[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2]()
 
InitializeComponent()
 
[/size][size=2][color=#008000]' Set the Margins to their default values
 
[/color][/size][size=2]inset.Top = 40
 
inset.Left = 0
 
inset.Right = 0
 
inset.Bottom = 0
 
[/size][size=2][color=#008000]' Check if DWM is enabled. This is a pretty stupid way to check, since it requires dwmapi.dll to be present anyway...
 
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] isit [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Boolean[/color][/size][size=2] = [/size][size=2][color=#0000ff]False
 
[/color][/size][size=2]DwmIsCompositionEnabled(isit)
 
[/size][size=2][color=#0000ff]If[/color][/size][size=2] isit [/size][size=2][color=#0000ff]Then
 
[/color][/size][size=2][color=#008000]' If DWM is enabled, call the function that gives us glass, passing a reference to our inset Margins
 
[/color][/size][size=2]DwmExtendFrameIntoClientArea([/size][size=2][color=#0000ff]Me[/color][/size][size=2].Handle, inset)
 
[/size][size=2][color=#0000ff]Else
 
[/color][/size][size=2][color=#008000]' If DWM isn't enabled, shout it out
 
[/color][/size][size=2]MessageBox.Show([/size][size=2][color=#a31515]"DWM isn't enabled"[/color][/size][size=2])
 
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
 
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub
 
[/color][/size][size=2][color=#0000ff]Protected[/color][/size][size=2][color=#0000ff]Overrides[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] OnPaint([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Windows.Forms.PaintEventArgs)
 
[/size][size=2][color=#0000ff]MyBase[/color][/size][size=2].OnPaint(e)
 
[/size][size=2][color=#0000ff]Me[/color][/size][size=2].PaintSquare(e, [/size][size=2][color=#0000ff]Me[/color][/size][size=2].DWMFrame)
 
[/size][size=2][color=#0000ff]Me[/color][/size][size=2].DrawStringPointF(e)
 
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub
 
[/color][/size][size=2][color=#0000ff]Private[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] PaintSquare([/size][size=2][color=#0000ff]ByRef[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Windows.Forms.PaintEventArgs, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] b [/size][size=2][color=#0000ff]As[/color][/size][size=2] SolidBrush)
 
e.Graphics.FillRectangle(b, 0, 0, Width, inset.Top)
 
e.Graphics.FillRectangle(b, 0, 0, inset.Left, Height)
 
 
 
[/size][size=2][color=#008000]' Note the numbers ( -14, -34) are just trial-and-error values, used to fix the glass... try omitting them, you'll get the idea. 
 
[/color][/size][size=2]e.Graphics.FillRectangle(b, Width - inset.Right - 14, 0, inset.Right, Height)
 
e.Graphics.FillRectangle(b, 0, Height - inset.Bottom - 34, Width, inset.Bottom)
 
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub
 
[/color][/size][size=2][color=#0000ff]Public[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] DrawStringPointF([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] PaintEventArgs)
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] g [/size][size=2][color=#0000ff]As[/color][/size][size=2] Graphics = [/size][size=2][color=#0000ff]Me[/color][/size][size=2].CreateGraphics
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] blackfont [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Drawing.Drawing2D.GraphicsPath = [/size][size=2][color=#0000ff]New[/color][/size][size=2] System.Drawing.Drawing2D.GraphicsPath
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] brsh [/size][size=2][color=#0000ff]As[/color][/size][size=2] SolidBrush = [/size][size=2][color=#0000ff]New[/color][/size][size=2] SolidBrush(Color.Pink)
 
blackfont.AddString([/size][size=2][color=#a31515]"OCUK PinkAardvark"[/color][/size][size=2], [/size][size=2][color=#0000ff]New[/color][/size][size=2] FontFamily([/size][size=2][color=#a31515]"Tahoma"[/color][/size][size=2]), [/size][size=2][color=#0000ff]CInt[/color][/size][size=2](FontStyle.Regular), 26, [/size][size=2][color=#0000ff]New[/color][/size][size=2] Point(15, 0), StringFormat.GenericDefault)
 
[/size][size=2][color=#008000]'//SmoothingMode must be set, or text smoothing will not work
 
[/color][/size][size=2]g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
 
g.FillPath(brsh, blackfont)
 
[/size][size=2][color=#008000]'//Fill the font with White brush
 
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub
 
End[/color][/size][size=2][color=#0000ff]Class
 
[/color][/size]
 
Last edited:
Back
Top Bottom