Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Rem Attribute VBA_ModuleType=VBAFormModule
- Option VBASupport 1
- Option Explicit
- '//===================================================
- '// Routine to do the Userform
- '// by Ivan F Moala
- '// 28th July 2004
- '//===================================================
- Private Const WS_EX_CONTROLPARENT As Long = &H10000
- Private Const WS_EX_APPWINDOW = &H40000
- Private Const WS_MINIMIZEBOX = &H20000
- Private Const WS_MAXIMIZEBOX = &H10000
- Private Const WS_THICKFRAME = &H40000
- Private Const WS_SIZEBOX = WS_THICKFRAME
- Private Const GWL_STYLE = (-16)
- Private Const GWL_EXSTYLE = (-20)
- Private Declare Function ShowWindow _
- Lib "user32" ( _
- ByVal hwnd As Long, _
- ByVal nCmdShow As Long) _
- As Long
- Private Declare Function GetWindowLong _
- Lib "user32" _
- Alias "GetWindowLongA" ( _
- ByVal hwnd As Long, _
- ByVal nIndex As Long) _
- As Long
- Dim hIcon As Long
- Private Sub CommandButton1_Click()
- '//
- End Sub
- Private Sub CommandButton2_Click()
- '//
- End Sub
- Private Sub OptionButton1_Click()
- hIcon = Me.Image1.Picture.Handle
- g_Icon = hIcon
- CreateFrmIcon Me, g_hwnd, hIcon
- End Sub
- Private Sub OptionButton2_Click()
- hIcon = Me.Image2.Picture.Handle
- g_Icon = hIcon
- CreateFrmIcon Me, g_hwnd, hIcon
- End Sub
- Private Sub OptionButton3_Click()
- hIcon = Me.Image3.Picture.Handle
- g_Icon = hIcon
- CreateFrmIcon Me, g_hwnd, hIcon
- End Sub
- Private Sub UserForm_Activate()
- Dim wLong As Long
- If Not g_objForm Is Nothing Then Exit Sub
- ShowWindow g_hwnd, SW_HIDE
- '// make sure form shows up in TaskBar
- wLong = GetWindowLong(g_hwnd, GWL_EXSTYLE)
- wLong = wLong Or WS_EX_CONTROLPARENT Or WS_EX_APPWINDOW
- SetWindowLong g_hwnd, GWL_EXSTYLE, wLong
- '// add Minimize button Only
- wLong = GetWindowLong(g_hwnd, GWL_STYLE)
- wLong = wLong Or WS_MINIMIZEBOX
- SetWindowLong g_hwnd, GWL_STYLE, wLong
- ShowWindow g_hwnd, SW_NORMAL
- Set g_objForm = Me
- End Sub
- Private Sub UserForm_Initialize()
- '//
- g_blnFromCreated = True
- '// Get the userform Window handle
- g_hwnd = FindWindow(vbNullString, UserForm1.Caption)
- If hIcon = 0 Then
- hIcon = Me.Image1.Picture.Handle
- g_Icon = hIcon
- End If
- CreateFrmIcon Me, g_hwnd, hIcon
- '//create RighClick Menu
- CreateRightClickMenu
- End Sub
- Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
- '// Lets clean-up
- '// UnsubClass !!
- SetWindowLong g_hwnd, GWL_WNDPROC, lngPrevWndProc
- DeleteIcon
- '// We're closing down now so set global reference to false
- g_blnFromCreated = False
- '// destroy our Menu
- DestroyMenu lMnu
- '//
- Set g_objForm = Nothing
- End Sub
- Private Sub UserForm_Resize()
- '// This is where we handle the Minimize to SystemTray
- '// Is it Minimized
- If Not g_blnMin Then
- '// ID used for callback.
- ' For XP ONLY
- 'lngWndID = Application.Hinstance
- ' Others use this
- lngWndID = vbNull
- '// This is where we Subclass the window, we need to get an ID
- lngPrevWndProc = SetWindowLong(g_hwnd, GWL_WNDPROC, AddressOf WndProcHook)
- '// Now create our Icon
- CreateIcon
- '// Hide our form so it doesn't diplay in the TaskBar!
- Me.Hide
- '// It has NOW been Minimized
- g_blnMin = True
- Else
- '// Reset the Boolean to show it is now Restored.
- g_blnMin = False
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement