
Visual Basic Code Snippets #2
In this next update I'll continue to re-post my Visual Basic code snippets (which are older than five years by the way) that pertain to Forms.
Make a Form Cover the Entire Screen
Compatibility: Win. 98-XP
Add the following code into a module within your project...
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 Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1
Public Const HWND_TOP = 0
Public Const SWP_SHOWWINDOW = &H40
Add the following code wherever you want the code to execute...
Dim cx As Long
Dim cy As Long
Dim RetVal As Long
If Me.WindowState = vbMaximized Then
Me.WindowState = vbNormal
End If
cx = GetSystemMetrics(SM_CXSCREEN)
cy = GetSystemMetrics(SM_CYSCREEN)
RetVal = SetWindowPos(Me.hwnd, HWND_TOP, 0, 0, cx, cy, SWP_SHOWWINDOW)
Flash a Forms Border
Compatibility: Win. 98-XP
Add the following code into a module within your project...
Public Declare Function FlashWindow Lib "User32" (ByVal hWnd As Long, ByVal bInvert As Long) As Long
Add a Timer to a form named Timer1 with an interval of 220 then add the following code into Timer1_Timer...
Dim nReturnValue As Long
nReturnValue = FlashWindow(Form1.hWnd, True)
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!
My Old Visual Basic Public Code/Source
I recently came across some of my really old Visual Basic tutorials and source code snippets I used to have up at my very first version of this site. Well, it's been over five years since these snippets have seen the light of day (or more like, been lit up in pixels on screens) and I believe they still have some use for archival purposes and at the very least helping Visual Basic newbies with the basic concepts of programming with Windows.
I'll go ahead and release them on this site as separate posts and I'll try to categorize them as much as I can. Stay tuned!
(Please note that these code snippets were all written using Visual Basic 6.)
Visual Basic Code Snippets #1
Visual Basic Code Snippets #2
Visual Basic Code Snippets #3
Visual Basic Code Snippets #4
Visual Basic Code Snippets #5
Visual Basic Code Snippets #6
Visual Basic Code Snippets #7
Visual Basic Code Snippets #8
Visual Basic Code Snippets #9
Visual Basic Code Snippets #10
Visual Basic Code Snippets #11