在VB中添加一按钮..点击按钮后整个窗体缩小到托盘..回答好了在追加100分

2024-12-26 14:25:48
推荐回答(5个)
回答1:

1。回答:代码如下
Option Explicit
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * 64
End Type
Private Const NIM_ADD = &H0
Private Const NIM_DELETE = &H2
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Dim k As NOTIFYICONDATA

Private Sub Command1_Click()
Shell_NotifyIcon NIM_ADD, k
End Sub

Private Sub Form_Load()
k.cbSize = Len(k)
k.hIcon = Image1.Picture
k.hwnd = Me.hwnd
k.szTip = "试验" & vbNullChar
k.uFlags = NIF_ICON Or NIF_TIP '''逻辑加
End Sub
(注意:还有一个“Image1”控件,而且要设定Image1的Picture属性,要附给一个“.icon”格式的图标)

2.回答:代码如下
Option Explicit
Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
x As Long
y As Long
End Type
Dim client As RECT
Dim qu As POINTAPI

Private Sub Form_Load()
GetClientRect Me.hwnd, client
ClientToScreen Me.hwnd, qu
OffsetRect client, qu.x, qu.y
ClipCursor client
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
ClipCursor ByVal 0&
End Sub

3.回答:
因为此时你附给的“Picture”属性值不是“.icon”格式,即必须赋予图标格式的文件

4.回答:
以上涉及到了好几个API函数,这里都说很麻烦,如果你真的追加我100分的话我再教你。你百度上发信息给我,我回复你我的QQ号,再教你,决不食言!

回答2:

两个api就可以了,用起来都很简单,不会就在网上搜一下啦。

shell_notifyicon 添加托盘图标
ClipCursor 限制鼠标范围

回答3:

声明

Public Const DefaultIconIndex = 1 '图标缺省索引
Public Const WM_LBUTTONDOWN = &H201 '按鼠标左键
Public Const WM_RBUTTONDOWN = &H204 '按鼠标右键

Public Const NIM_ADD = 0 '添加图标
Public Const NIM_MODIFY = 1 '修改图标
Public Const NIM_DELETE = 2 '删除图标

Public Const NIF_MESSAGE = 1 'message 有效
Public Const NIF_ICON = 2 '图标操作(添加、修改、删除)有效
Public Const NIF_TIP = 4 'ToolTip(提示)有效

'API函数声明
'图标操作
Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
'判断窗口是否最小化
Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long
'
'设置窗口位置和状态(position)的功能
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

'定义类型
'通知栏图标状态
Public Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * 64
End Type
函数过程

'添加图标至通知栏
Public Function Icon_Add(iHwnd As Long, sTips As String, hIcon As Long, IconID As Long) As Long
'参数说明:iHwnd:窗口句柄,sTips:当鼠标移到通知栏图标上时显示的提示内容
'hIcon:图标句柄,IconID:图标Id号
Dim IconVa As NOTIFYICONDATA
With IconVa
.hwnd = iHwnd
.szTip = Trim(sTips) + Chr$(0)
.hIcon = hIcon
.uID = IconID
.uCallbackMessage = WM_LBUTTONDOWN
.cbSize = Len(IconVa)
.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
Icon_Add = Shell_NotifyIcon(NIM_ADD, IconVa)
End With
End Function
'删除通知栏图标(参数说明同Icon_Add)
Function Icon_Del(iHwnd As Long, lIndex As Long) As Long
Dim IconVa As NOTIFYICONDATA
Dim L As Long
With IconVa
.hwnd = iHwnd
.uID = lIndex
.cbSize = Len(IconVa)
End With
Icon_Del = Shell_NotifyIcon(NIM_DELETE, IconVa)
End Function
'修改通知栏图标(参数说明同Icon_Add)
Public Function Icon_Modify(iHwnd As Long, sTips As String, hIcon As Long, IconID As Long) As Long
Dim IconVa As NOTIFYICONDATA
With IconVa
.hwnd = iHwnd
.szTip = sTips + Chr$(0)
.hIcon = hIcon
.uID = IconID
.uCallbackMessage = WM_LBUTTONDOWN
.cbSize = Len(IconVa)
.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
Icon_Modify = Shell_NotifyIcon(NIM_MODIFY, IconVa)
End With
End Function

调用方法
'将窗口图标加入通知栏
Call Icon_Add(Me.hwnd, Me.Caption, Me.Icon, 0)
Call Icon_Del(Me.hwnd, 0) '删除通知栏图标

这是我程序里用的一段。贴上来先

回答4:

1:留个邮箱我发个例子给你
2: 同1
3:这有可能是你的ICO图片缺少vb所需要尺寸的图片 做ICO时 最好做成48*48的 效果最好
4 :又要用到邮箱 我有个API 大全 vb用到的API 上面基本上都有 功能也说得很详细

回答5:

我不懂,但是在网上找了些答案,如果你需要我就给你发过来 呵呵