VB6 窗体边缘自动隐藏

前端之家收集整理的这篇文章主要介绍了VB6 窗体边缘自动隐藏前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. 添加一个timer控件 Interval属性200
  2. **********模块代码***************
  3. Option Explicit
  4. Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  5. Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long,lpRect As RECT) As Long
  6. 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
  7.  
  8. Public Type RECT
  9. Left As Long
  10. Top As Long
  11. Right As Long
  12. Bottom As Long
  13. End Type
  14.  
  15. Public Type POINTAPI
  16. X As Long
  17. Y As Long
  18. End Type
  19.  
  20. Public Const HWND_TOPMOST = -1
  21. Public Const SWP_NOSIZE = &H1
  22. Public Const SWP_NOMOVE = &H2
  23. Public Const HWND_TOP = 0
  24. Public Const SWP_NOACTIVATE = &H10
  25. Public Const SWP_SHOWWINDOW = &H40
  26.  
  27. *********窗体程序代码**************
  28. Private Sub Form_Load()
  29. SetWindowPos Me.hwnd,HWND_TOPMOST,SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
  30. End Sub
  31.  
  32. Private Sub Timer1_Timer()
  33. On Error Resume Next
  34. Dim p As POINTAPI
  35. Dim f As RECT
  36. GetCursorPos p
  37. GetWindowRect Me.hwnd,f
  38. If Me.WindowState <> 1 Then
  39. If p.X > f.Left And p.X < f.Right And p.Y > f.Top And p.Y < f.Bottom Then
  40. If Me.Top < 0 Then
  41. Me.Top = -10
  42. Me.Show
  43. ElseIf Me.Left < 0 Then
  44. Me.Left = -10
  45. Me.Show
  46. ElseIf Me.Left + Me.Width >= Screen.Width Then
  47. Me.Left = Screen.Width - Me.Width + 10
  48. Me.Show
  49. End If
  50. ElseIf f.Top <= 4 Then
  51. Me.Top = 40 - Me.Height
  52. ElseIf f.Left <= 4 Then
  53. Me.Left = 40 - Me.Width
  54. ElseIf Me.Left + Me.Width >= Screen.Width - 4 Then
  55. Me.Left = Screen.Width - 40
  56. End If
  57. End If
  58. End Sub
  59. ****************END*************************

猜你在找的VB相关文章