正常情况点击后弹出来的菜单总是那样没有新意感。我现在想点击图标后的菜没关系,而是显示一个picture ,而这个picture 里面就有菜单,自己想做成什么样的都可以。可以吗??????
解决方案 »
- VB中有无与VC++中DoDataExchange函数类似的函数?
- XMLHTTP棘手问题,在线等待达人》。。。。。
- 连打该如何设计呀.
- 怎样列举出文件夹下所有的文件.
- 欢迎你参加我们的网络编程小组——E-mail: vcclub at 163.com
- 请问微软专家,ado在处理事务时connection的Cursorlocation一定要用adUseServer,不能用adUerClient吗?
- 谁能告诉我这段代码的意思啊!谢谢
- 如何修改对话框???
- 求五子棋算法,50分相送(我的可用分不多了耶,^_^)
- vb用api如何控制其他软件?
- vb实现记录拷贝?
- 用Ole显示Word,如何显示出菜单栏及工具栏
http://www.programfan.net/http://vbeden.xg88.com/bar_on_top.htm
现在的问题,如果我点击图标
form.show 1 但form 位置怎么让它停在图标的上方呢??对这样的操作没有经验,谁有更好的办法呀!!!!等我做好了,会给大家看的呢。帮帮忙呀!
可是怎么用 api 呢???给点代吗呀!!!!怎样确定位置?!!
Private Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long【说明】
获取鼠标指针的当前位置 【返回值】
Long,非零表示成功,零表示失败。会设置GetLastError 【参数表】
lpPoint -------- POINTAPI,随同指针在屏幕像素坐标中的位置载入的一个结构'This project needs
'a Form, called 'Form1'
'a Picture Box, called 'ExplButton' (50x50 pixels)
'a Picture Box with an icon in it, called 'picIcon'
'two timers (Timer1 and Timer2), both with interval 100
'Button, called 'Command1'
'In general section
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'Declare the API-Functions
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Sub DrawButton(Pushed As Boolean)
Dim Clr1 As Long, Clr2 As Long
If Pushed = True Then
'If Pushed=True then clr1=Dark Gray
Clr1 = &H808080
'If Pushed=True then clr1=White
Clr2 = &HFFFFFF
ElseIf Pushed = False Then
'If Pushed=True then clr1=White
Clr1 = &HFFFFFF
'If Pushed=True then clr1=Dark Gray
Clr2 = &H808080
End If With Form1.ExplButton
' Draw the button
Form1.ExplButton.Line (0, 0)-(.ScaleWidth, 0), Clr1
Form1.ExplButton.Line (0, 0)-(0, .ScaleHeight), Clr1
Form1.ExplButton.Line (.ScaleWidth - 1, .ScaleHeight - 1)-(.ScaleWidth - 1, 0), Clr2
Form1.ExplButton.Line (.ScaleWidth - 1, .ScaleHeight - 1)-(0, .ScaleHeight - 1), Clr2
End With
End Sub
Private Sub Command1_Click()
Dim Rec As RECT
'Get Left, Right, Top and Bottom of Form1
GetWindowRect Form1.hwnd, Rec
'Set Cursor position on X
SetCursorPos Rec.Right - 15, Rec.Top + 15
End Sub
Private Sub ExplButton_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
DrawButton True
End Sub
Private Sub ExplButton_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
DrawButton False
End Sub
Private Sub ExplButton_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
DrawButton False
End Sub
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: [email protected] Dim Stretched As Boolean
'picIcon.Visible = False
'API uses pixels
picIcon.ScaleMode = vbPixels
'No border
ExplButton.BorderStyle = 0
'API uses pixels
ExplButton.ScaleMode = vbPixels
'Set graphic mode te 'persistent graphic'
ExplButton.AutoRedraw = True
'API uses pixels
Me.ScaleMode = vbPixels
'Set the button's caption
Command1.Caption = "Set Mousecursor on X" ' If you set Stretched to true then stretch the icon to te Height and Width of the button
' If Stretched=False, the icon will be centered
Stretched = False If Stretched = True Then
' Stretch the Icon
ExplButton.PaintPicture picIcon.Picture, 1, 1, ExplButton.ScaleWidth - 2, ExplButton.ScaleHeight - 2
ElseIf Stretched = False Then
' Center the picture of the icon
ExplButton.PaintPicture picIcon.Picture, (ExplButton.ScaleWidth - picIcon.ScaleWidth) / 2, (ExplButton.ScaleHeight - picIcon.ScaleHeight) / 2
End If
' Set icon as picture
ExplButton.Picture = ExplButton.Image
End Sub
Private Sub Timer1_Timer()
Dim Rec As RECT, Point As POINTAPI
' Get Left, Right, Top and Bottom of Form1
GetWindowRect Me.hwnd, Rec
' Get the position of the cursor
GetCursorPos Point ' If the cursor is located above the form then
If Point.X >= Rec.Left And Point.X <= Rec.Right And Point.Y >= Rec.Top And Point.Y <= Rec.Bottom Then
Me.Caption = "MouseCursor is on form."
Else
' The cursor is not located above the form
Me.Caption = "MouseCursor is not on form."
End If
End Sub
Private Sub Timer2_Timer()
Dim Rec As RECT, Point As POINTAPI
' Get Left, Right, Top and Bottom of ExplButton
GetWindowRect ExplButton.hwnd, Rec
' Get the position of the cursor
GetCursorPos Point
' If the cursor isn't located above ExplButton then
If Point.X < Rec.Left Or Point.X > Rec.Right Or Point.Y < Rec.Top Or Point.Y > Rec.Bottom Then ExplButton.Cls
End Sub
然后在弹出菜单的代码处,取出鼠标点击时的坐标,根据这个坐标,来定位显示放有picturebox的窗体不就可以了吗?(因为显示pictrue必须得放在容器里)
代码如下:(由于我这里没有调试环境,一下代码只提供大概的思路,需要你具体去完善,有什么疑问请给我留言)
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As LongPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongPrivate Const WM_SYSCOMMAND = &H112
Private Const SC_RESTORE = &HF120&Private Const NIM_ADD = &H0 '注释:在任务栏中增加一个图标
Private Const NIM_DELETE = &H2 '注释:删除任务栏中的一个图标
Private Const NIM_MODIFY = &H1 '注释:修改任务栏中个图标信息
Private Const NIF_MESSAGE = &H1 '注释:NOTIFYICONDATA结构中uFlags的控制信息
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4Private Const WM_MOUSEMOVE = &H200 '注释:当鼠标指针移至图标上Private Const WM_LBUTTONUP = &H202
Private Const WM_RBUTTONUP = &H205Private Type NOTIFYICONDATA
cbSize As Long '注释:该数据结构的大小
hwnd As Long '注释:处理任务栏中图标的窗口句柄
uID As Long '注释:定义的任务栏中图标的标识
uFlags As Long '注释:任务栏图标功能控制,可以是以下值的组合(一般全包括)
'注释:NIF_MESSAGE 表示发送控制消息;
'注释:NIF_ICON表示显示控制栏中的图标;
'注释:NIF_TIP表示任务栏中的图标有动态提示。
uCallbackMessage As Long '注释:任务栏图标通过它与用户程序交换消息,处理该消息的窗口由hWnd决定
hIcon As Long '注释:任务栏中的图标的控制句柄
szTip As String * 64 '注释:图标的提示信息
End TypeType POINTAPI '鼠标坐标点
x As Long
y As Long
End TypeDim myData As NOTIFYICONDATA
Dim z As POINTAPI '鼠标坐标点Private Sub Form_Load()
Me.Visibled=False
With myData
.cbSize = Len(myData)
.hwnd = Me.hwnd
.uID = 0
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon.Handle '默认为窗口图标
.szTip = "提示…………"
End With
Shell_NotifyIcon NIM_ADD, myData
End subPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case CLng(X)
Case WM_RBUTTONUP '鼠标在图标上右击时弹出
Load form2 '显示有picture的窗体
form2.left=z.x-form2.width/2 '定位
form2.top=z.y-form2.height
form2.show
Case WM_LBUTTONUP '鼠标在图标上左击时
…………………………
End Select
End SubPrivate Sub Form_Unload(Cancel As Integer)
Shell_NotifyIcon NIM_DELETE, myData '窗口卸载时,将状态栏中的图标一同卸载
End Sub