BenEskew.com Just another web developer's personal weblog.

Register.com Hosting 468x60
11Sep/090

Visual Basic Code Snippets #1

In this update I'll re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to Forms.

Move a Form Without a Title Bar

Compatibility: Win. 98-XP

Add the following code into a module within your project...

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const HTCAPTION = 2
Public Const WM_NCLBUTTONDOWN = &HA1

Add the following code into the MouseDown event of a Form, PictureBox, or whatever...


ReleaseCapture
SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)

Make a Form Transparent

Compatibility: Win. 98-XP

Add the following code into a module within your project...

Public Const GWL_EXSTYLE = (-20)
Public Const WS_EX_TRANSPARENT = &H20&
Public Const SWP_FRAMECHANGED = &H20
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_SHOWME = SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE
Public Const HWND_NOTOPMOST = -2
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Public Function formTransparent(frm As Form)
SetWindowLong frm.hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT
SetWindowPos frm.hwnd, HWND_NOTOPMOST, 0&, 0&, 0&, 0&, SWP_SHOWME
End Function

Add the following code wherever you want the code to execute...

Call formTransparent(Form1) 'Form1 being the form you want to be transparent.

These two snippets are just the tip of the iceberg! Much more to come!

Visual Basic Code Snippets #2