Advertisement
Guest User

Untitled

a guest
Oct 8th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Rem Attribute VBA_ModuleType=VBAFormModule
  2. Option VBASupport 1
  3. Option Explicit
  4. '//===================================================
  5. '// Routine to do the Userform
  6. '// by Ivan F Moala
  7. '// 28th July 2004
  8. '//===================================================
  9.  
  10. Private Const WS_EX_CONTROLPARENT As Long = &H10000
  11. Private Const WS_EX_APPWINDOW = &H40000
  12. Private Const WS_MINIMIZEBOX = &H20000
  13. Private Const WS_MAXIMIZEBOX = &H10000
  14. Private Const WS_THICKFRAME = &H40000
  15. Private Const WS_SIZEBOX = WS_THICKFRAME
  16.  
  17. Private Const GWL_STYLE = (-16)
  18. Private Const GWL_EXSTYLE = (-20)
  19.  
  20. Private Declare Function ShowWindow _
  21.     Lib "user32" ( _
  22.         ByVal hwnd As Long, _
  23.         ByVal nCmdShow As Long) _
  24. As Long
  25.  
  26. Private Declare Function GetWindowLong _
  27.     Lib "user32" _
  28.         Alias "GetWindowLongA" ( _
  29.             ByVal hwnd As Long, _
  30.             ByVal nIndex As Long) _
  31. As Long
  32.  
  33. Dim hIcon As Long
  34.  
  35. Private Sub CommandButton1_Click()
  36. '//
  37. End Sub
  38.  
  39. Private Sub CommandButton2_Click()
  40. '//
  41. End Sub
  42.  
  43. Private Sub OptionButton1_Click()
  44.     hIcon = Me.Image1.Picture.Handle
  45.     g_Icon = hIcon
  46.     CreateFrmIcon Me, g_hwnd, hIcon
  47. End Sub
  48.  
  49. Private Sub OptionButton2_Click()
  50.     hIcon = Me.Image2.Picture.Handle
  51.     g_Icon = hIcon
  52.     CreateFrmIcon Me, g_hwnd, hIcon
  53. End Sub
  54.  
  55. Private Sub OptionButton3_Click()
  56.     hIcon = Me.Image3.Picture.Handle
  57.     g_Icon = hIcon
  58.     CreateFrmIcon Me, g_hwnd, hIcon
  59. End Sub
  60.  
  61. Private Sub UserForm_Activate()
  62.     Dim wLong As Long
  63.    
  64.     If Not g_objForm Is Nothing Then Exit Sub
  65.     ShowWindow g_hwnd, SW_HIDE
  66.     '// make sure form shows up in TaskBar
  67.    wLong = GetWindowLong(g_hwnd, GWL_EXSTYLE)
  68.     wLong = wLong Or WS_EX_CONTROLPARENT Or WS_EX_APPWINDOW
  69.     SetWindowLong g_hwnd, GWL_EXSTYLE, wLong
  70.     '// add Minimize button Only
  71.    wLong = GetWindowLong(g_hwnd, GWL_STYLE)
  72.     wLong = wLong Or WS_MINIMIZEBOX
  73.     SetWindowLong g_hwnd, GWL_STYLE, wLong
  74.     ShowWindow g_hwnd, SW_NORMAL
  75.     Set g_objForm = Me
  76. End Sub
  77.  
  78. Private Sub UserForm_Initialize()
  79.     '//
  80.    g_blnFromCreated = True
  81.     '// Get the userform Window handle
  82.    g_hwnd = FindWindow(vbNullString, UserForm1.Caption)
  83.     If hIcon = 0 Then
  84.        hIcon = Me.Image1.Picture.Handle
  85.        g_Icon = hIcon
  86.     End If
  87.     CreateFrmIcon Me, g_hwnd, hIcon
  88.     '//create RighClick Menu
  89.    CreateRightClickMenu
  90. End Sub
  91.  
  92. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  93. '// Lets clean-up
  94.    
  95.     '// UnsubClass !!
  96.    SetWindowLong g_hwnd, GWL_WNDPROC, lngPrevWndProc
  97.     DeleteIcon
  98.     '// We're closing down now so set global reference to false
  99.    g_blnFromCreated = False
  100.     '// destroy our Menu
  101.    DestroyMenu lMnu
  102.     '//
  103.    Set g_objForm = Nothing
  104.    
  105. End Sub
  106.  
  107. Private Sub UserForm_Resize()
  108. '// This is where we handle the Minimize to SystemTray
  109. '// Is it Minimized
  110. If Not g_blnMin Then
  111.     '// ID used for callback.
  112.    ' For XP ONLY
  113.    'lngWndID = Application.Hinstance
  114.    ' Others use this
  115.    lngWndID = vbNull
  116.     '// This is where we Subclass the window, we need to get an ID
  117.    lngPrevWndProc = SetWindowLong(g_hwnd, GWL_WNDPROC, AddressOf WndProcHook)
  118.     '// Now create our Icon
  119.    CreateIcon
  120.     '// Hide our form so it doesn't diplay in the TaskBar!
  121.    Me.Hide
  122.     '// It has NOW been Minimized
  123.    g_blnMin = True
  124. Else
  125.     '// Reset the Boolean to show it is now Restored.
  126.    g_blnMin = False
  127. End If
  128.  
  129. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement