Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Private Sub Form_Load()
Dim oldmode As Long
oldmode = Form1.ScaleMode
Form1.ScaleMode = vbPixels
Label1.BackStyle = 1 'opaque
Label1.BackColor = vbRed
Label1.BorderStyle = 0 ' None
Label1.Move Frame1.Left - 1, Frame1.Top - 1, Frame1.Width + 2, Frame1.Height + 2
Label1.ZOrder 0 ' Send to back
Form1.ScaleMode = oldmode
End Sub
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Sub DrawFrameBorder()
Dim oldcolor As Long
Dim oldmode As Long
Dim hdc As Long
oldmode = Form1.ScaleMode
oldcolour = Form1.ForeColor
hdc = GetDC(Me.hwnd) ' Get device context
Form1.ForeColor = vbRed
Rectangle hdc, Frame1.Left - 1, Frame1.Top - 1, Frame1.Left + Frame1.Width + 2, Frame1.Top + Frame1.Height + 3
ReleaseDC Me.hwnd, hdc ' Release device context
Form1.ForeColor = oldcolour
Form1.ScaleMode = oldmode
End Sub
Private Sub Form_Paint()
DrawFrameBorder
End Sub
Option Explicit
Private Sub Form_Load()
HookFrame
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnhookFrame
End Sub
Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function FrameRect Lib "user32" (ByVal hDC As Long, lpRect As rect, ByVal hBrush As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As rect) As Long
Private Declare Function InvalidateRect Lib "user32" (ByVal hWnd As Long, lpRect As Any, ByVal bErase As Long) As Long
Private Declare Function UpdateWindow Lib "user32" (ByVal hWnd As Long) As Long
Private Type rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const GWL_WNDPROC As Long = -4
Private Const WM_PAINT As Long = &HF
Dim OldWndProc As Long
' Subclass procedure for Frame control
Function FrameWndProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim result As Long
result = CallWindowProc(OldWndProc, hWnd, Msg, wParam, lParam)
If Msg = WM_PAINT Then
Dim hDC As Long, rect As rect, hBrush As Long
hDC = GetDC(hWnd)
If hDC <> 0 Then
' Get Frame dimensions
' this is where you can modify the size/position of the rectangle that will be drawn in the frame
GetWindowRect hWnd, rect
rect.Right = rect.Right - rect.Left
rect.Bottom = rect.Bottom - rect.Top
rect.Left = 0
rect.Top = 0
' Create a custom border brush (change color here)
hBrush = CreateSolidBrush(RGB(255, 0, 0)) ' Red border
' Draw the custom border
FrameRect hDC, rect, hBrush
' Clean up
DeleteObject hBrush
ReleaseDC hWnd, hDC
End If
End If
' return result from default repaint
FrameWndProc = result
End Function
' Hook the Frame control
Public Sub HookFrame()
OldWndProc = GetWindowLong(Form1.Frame1.hWnd, GWL_WNDPROC)
SetWindowLong Form1.Frame1.hWnd, GWL_WNDPROC, AddressOf FrameWndProc
End Sub
' Unhook on form unload to prevent crashes
Public Sub UnhookFrame()
If OldWndProc <> 0 Then
SetWindowLong Form1.Frame1.hWnd, GWL_WNDPROC, OldWndProc
End If
End Sub