自己做窗体的最小/最大化怎么入手?
不使用自带的最小/最大化想用自己的,这样的话如何入手开始?
[解决办法]
'增加一个窗体 Form1,设计时 Form1.BorderStyle = 0
'在窗体上增加一个 Picture1; 再在Picture1中增加二个Labe1 , Label1 与 labe12(注意要放进Picture1中);
Private 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
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uId As Long
uFlags As Long
ucallbackMessage As Long
hIcon As Long
szTip As String * 32
End Type
Private IsMove As Boolean
Private oldFrmPoint As POINTAPI
Private oldMousePoint As POINTAPI
Private nfIconData As NOTIFYICONDATA
Const MAX_TOOLTIP As Integer = 32 '这部分是声明常量
Const NIF_ICON = &H2 '删除图标
Const NIF_MESSAGE = &H1
Const NIF_TIP = &H4
Const NIM_ADD = &H0 '添加图标到任务栏提区
Const NIM_DELETE = &H2
Const WM_MOUSEMOVE = &H200
Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202
Const WM_LBUTTONDBLCLK = &H203
Const WM_RBUTTONDOWN = &H204
Const WM_RBUTTONUP = &H205
Const WM_RBUTTONDBLCLK = &H206
Const SW_RESTORE = 9
Const SW_HIDE = 0
Private Sub Form_Load()
Label1.Caption = "-"
Label2.Caption = "X"
SetWindowPos Me.hwnd, &HFFFF, 0, 0, 0, 0, 1
Me.Left = 3540
Me.Top = 690
Me.Width = 10000
Me.Height = 10000
Label1.ForeColor = vbRed
Label1.Left = 9600
Label1.Top = 0
Label1.AutoSize = True
Label1.BackStyle = 0
Label2.ForeColor = vbRed
Label2.Left = 9800
Label2.Top = 0
Label2.AutoSize = True
Label2.BackStyle = 0
Picture1.ZOrder 1
Picture1.Left = 0
Picture1.Top = 0
Picture1.Height = 200
Picture1.Width = Me.Width
Picture1.BackColor = vbBlue
Picture1.BorderStyle = 0
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lMsg As Single
lMsg = X / Screen.TwipsPerPixelX '屏幕横向(X)分辨率
If lMsg = WM_LBUTTONUP Then Call Shell_NotifyIcon(NIM_DELETE, nfIconData): Me.Show
'左键单击卸载托盘图标并显示窗体
End Sub
'***************************tt移动窗体
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
IsMove = True
oldFrmPoint.X = Me.Left
oldFrmPoint.Y = Me.Top
GetCursorPos oldMousePoint
End If
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 And IsMove = True Then
Dim lpPoint As POINTAPI
GetCursorPos lpPoint
Me.Left = oldFrmPoint.X + (lpPoint.X - oldMousePoint.X) * Screen.TwipsPerPixelX
Me.Top = oldFrmPoint.Y + (lpPoint.Y - oldMousePoint.Y) * Screen.TwipsPerPixelY
End If
End Sub
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Label1.ForeColor = vbWhite
End If
End Sub
Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Label1.ForeColor = vbRed
Call myHide '进入托盘
End If
End Sub
Private Sub Label2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Label2.ForeColor = vbWhite
End If
End Sub
Private Sub Label2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Label2.ForeColor = vbRed
End
End If
End Sub
'*****************************************
Private Sub myHide() '这里是隐藏到托盘的代码
nfIconData.hwnd = Me.hwnd
nfIconData.uId = Me.Icon
nfIconData.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
nfIconData.ucallbackMessage = WM_MOUSEMOVE
nfIconData.hIcon = Me.Icon.Handle
nfIconData.szTip = "示例"
nfIconData.cbSize = Len(nfIconData)
Call Shell_NotifyIcon(NIM_ADD, nfIconData)
Me.Visible = False
End Sub
'增加一个窗体 Form1
'在窗体上增加一个 Picture1; 再在Picture1中增加二个Labe1 , Label1 与 labe12(注意要放进Picture1中);
Private 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
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type NOTIFYICONDATA
cbSize As Long
hWnd As Long
uId As Long
uFlags As Long
ucallbackMessage As Long
hIcon As Long
szTip As String * 32
End Type
Private IsMove As Boolean
Private oldFrmPoint As POINTAPI
Private oldMousePoint As POINTAPI
Private nfIconData As NOTIFYICONDATA
Private Const RGN_AND As Long = 1
Private Const RGN_COPY As Long = 5
Private Const RGN_DIFF As Long = 4
Private Const RGN_OR As Long = 2
Private Const RGN_XOR As Long = 3
Private Sub Form_Load()
Label1.Caption = "-"
Label2.Caption = "X"
SetWindowPos Me.hWnd, &HFFFF, 0, 0, 0, 0, 1
Me.Left = 3540
Me.Top = 690
Me.Width = 10000
Me.Height = 10000
Label1.ForeColor = vbRed
Label1.Left = 9600
Label1.Top = 0
Label1.AutoSize = True
Label1.BackStyle = 0
Label2.ForeColor = vbRed
Label2.Left = 9800
Label2.Top = 0
Label2.AutoSize = True
Label2.BackStyle = 0
Picture1.ZOrder 1
Picture1.Left = 0
Picture1.Top = 0
Picture1.Height = 300
Picture1.Width = Me.Width
Picture1.BackColor = vbBlue
Picture1.BorderStyle = 0
DrawForm
End Sub
'***************************tt移动窗体
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
IsMove = True
oldFrmPoint.X = Me.Left
oldFrmPoint.Y = Me.Top
GetCursorPos oldMousePoint
End If
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 And IsMove = True Then
Dim lpPoint As POINTAPI
GetCursorPos lpPoint
Me.Left = oldFrmPoint.X + (lpPoint.X - oldMousePoint.X) * Screen.TwipsPerPixelX
Me.Top = oldFrmPoint.Y + (lpPoint.Y - oldMousePoint.Y) * Screen.TwipsPerPixelY
End If
End Sub
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Label1.ForeColor = vbWhite
End If
End Sub
Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Label1.ForeColor = vbRed
Form1.WindowState = 1
End If
End Sub
Private Sub Label2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Label2.ForeColor = vbWhite
End If
End Sub
Private Sub Label2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Label2.ForeColor = vbRed
End
End If
End Sub
'*****************************************
Private Sub DrawForm() '绘制窗体
Dim hRgn As Long, h1 As Long, h2 As Long
Dim lRes As Long
h1 = CreateRectRgn(0, 30, Me.ScaleWidth, Me.ScaleHeight) '自己定义四个角的坐标点 30表示上面标题栏的高度,实际自己调
lRes = SetWindowRgn(Me.hWnd, h1, True)
End Sub