VB一个可以改变箭头方向的气泡提示

这篇具有很好参考价值的文章主要介绍了VB一个可以改变箭头方向的气泡提示。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

'新建一个类名。名称为clsTip
Option Explicit
'* 模块名称:clsTip.cls
'* 功能:一个可以改变箭头方向的气泡提示类
Private Type TOOLINFO
cbSize As Long
dwFlags As Long
hwnd As Long
dwID As Long
rtRect(3) As Long
hInst As Long
lpszText As String
lParam As Long
End Type
Private Declare Sub InitCommonControls Lib “comctl32” ()
Private Declare Function CreateWindowEx Lib “user32” Alias “CreateWindowExA” _
(ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, _
ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hwndParent As Long, ByVal hMenu As Long, _
ByVal hInstance As Long, lpParam As Any) As Long
Private Const TOOLTIPS_CLASS As String = “tooltips_class32”
Private Declare Function DestroyWindow Lib “user32” (ByVal hwnd As Long) As Long
’ ToolTips Style
Public Enum StyleConstants
TTS_COMMON = &H0
TTS_BALLOON = &H40
End Enum
Private Const TTS_ALWAYSTIP As Long = &H1
Private Const TTS_NOANIMATE As Long = &H10
Private Const TTS_NOFADE As Long = &H20
Private Const TTS_NOPREFIX As Long = &H2
Private Const TTDT_AUTOPOP = 2
Private Const TTDT_INITIAL = 3
’ ToolTips Flags
Private Const TTF_ABSOLUTE As Long = &H80
Private Const TTF_CENTERTIP As Long = &H2
Private Const TTF_DI_SETITEM As Long = &H8000
Private Const TTF_IDISHWND As Long = &H1
Private Const TTF_RTLREADING As Long = &H4
Private Const TTF_SUBCLASS As Long = &H10
Private Const TTF_TRACK As Long = &H20
Private Const TTF_TRANSPARENT As Long = &H100
’ ToolTips Icon
Public Enum IconConstants
TTI_NONE = 0
TTI_INFO = 1
TTI_WARNING = 2
TTI_ERROR = 3
End Enum
'ToolTips Arrow Orientation
Public Enum OrientationConstants
Down = 0
Up = 1
End Enum
’ ToolTips Message
Private Const WM_USER As Long = &H400
Private Const TTM_SETDELAYTIME As Long = (WM_USER + 3)
Private Const TTM_ADDTOOL As Long = (WM_USER + 4)
Private Const TTM_DELTOOL As Long = (WM_USER + 5)
Private Const TTM_SETTOOLINFO As Long = (WM_USER + 9)
Private Const TTM_UPDATETIPTEXTA = (WM_USER + 12)
Private Const TTM_TRACKACTIVATE As Long = (WM_USER + 17)
Private Const TTM_TRACKPOSITION As Long = (WM_USER + 18)
Private Const TTM_SETTIPBKCOLOR As Long = (WM_USER + 19)
Private Const TTM_SETTIPTEXTCOLOR As Long = (WM_USER + 20)
Private Const TTM_SETTITLE As Long = (WM_USER + 32)
Private Declare Function GetCursorPos Lib “user32” (ByVal lpPoint As Long) As Long
Private Declare Function SetCursorPos Lib “user32” (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function ShowCursor Lib “user32” (ByVal bShow As Long) As Long
Private Declare Function GetForegroundWindow Lib “user32” () As Long
Private Declare Function ClientToScreen Lib “user32” (ByVal hwnd As Long, ByVal lpPoint As Long) As Long
Private Declare Function GetClientRect Lib “user32” (ByVal hwnd As Long, ByVal lpRect As Long) As Long
Private Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function PostMessage Lib “user32” Alias “PostMessageA” (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindowLong Lib “user32” Alias “GetWindowLongA” (ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib “user32” Alias “SetWindowLongA” (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_STYLE = (-16)
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 Const HWND_NOTOPMOST = -2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private Declare Function CallWindowProc Lib “user32” Alias “CallWindowProcA” (ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Sub CopyMemory Lib “kernel32” Alias “RtlMoveMemory” (Destination As Any, _
Source As Any, ByVal Length As Long)
Private Declare Function SetTimer Lib “user32” (ByVal hwnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib “user32” (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Private Declare Function GetWindowRect Lib “user32” (ByVal hwnd As Long, ByVal lpRect As Long) As Long

Dim m_hwndTip As Long
Dim m_hwndParent As Long
Dim m_TipInfo As TOOLINFO
Dim m_Title As String
Dim m_Icon As IconConstants
Dim m_Style As StyleConstants
Dim m_Orientation As OrientationConstants
Dim m_Delay As Long
Dim m_ForeColor As Long, m_BackColor As Long
Dim m_idTimer As Long

Private Sub Class_Initialize()
InitCommonControls
m_Icon = TTI_INFO
m_TipInfo.cbSize = Len(m_TipInfo)
m_TipInfo.dwFlags = TTF_IDISHWND Or TTF_TRANSPARENT Or TTF_SUBCLASS 'Or TTF_TRACK
m_TipInfo.hInst = App.hInstance
m_Delay = 2000
End Sub

Private Sub Class_Terminate()
If m_idTimer <> 0 Then KillTimer 0, m_idTimer
If m_hwndTip <> 0 Then DestroyWindow m_hwndTip
m_idTimer = 0
m_hwndTip = 0
End Sub

Public Sub Show(ByVal hwndParent As Long, Optional ByVal szText As String = vbNullString, _
Optional ByVal szTitle As String = vbNullString, Optional X As Long, Optional Y As Long)

Dim hwnd As Long
Dim objPos(1) As Long, rtWin(3) As Long, ptPos As Long

Call Class_Terminate

m_Title = szTitle
m_TipInfo.lpszText = szText
m_hwndParent = IIf(hwndParent, hwndParent, GetForegroundWindow)
m_hwndTip = CreateWindowEx(0, TOOLTIPS_CLASS, "", TTS_NOPREFIX Or TTS_ALWAYSTIP Or m_Style, _
    0, 0, 0, 0, m_hwndParent, 0, App.hInstance, ByVal 0&)
m_TipInfo.hwnd = m_hwndParent
m_TipInfo.dwID = m_hwndParent

If X > 0 And Y > 0 Then
    objPos(0) = X: objPos(1) = Y
    ClientToScreen m_hwndParent, VarPtr(objPos(0))
Else
    GetCursorPos VarPtr(objPos(0))
End If
ptPos = objPos(1) * &H10000 + objPos(0)

SendMessage m_hwndTip, TTM_SETDELAYTIME, TTDT_INITIAL, ByVal 0
SendMessage m_hwndTip, TTM_SETTITLE, m_Icon, ByVal m_Title
If m_ForeColor <> Empty Then SendMessage m_hwndTip, TTM_SETTIPTEXTCOLOR, m_ForeColor, 0&
If m_BackColor <> Empty Then SendMessage m_hwndTip, TTM_SETTIPBKCOLOR, m_BackColor, 0&
SendMessage m_hwndTip, TTM_ADDTOOL, 0&, m_TipInfo

If m_Orientation = Up Then
    SendMessage m_hwndTip, TTM_TRACKPOSITION, 0, ByVal ptPos
    SendMessage m_hwndTip, TTM_TRACKACTIVATE, 1, m_TipInfo
Else
    SendMessage m_hwndTip, TTM_TRACKACTIVATE, 1, m_TipInfo
    GetWindowRect m_hwndTip, VarPtr(rtWin(0))
    objPos(0) = objPos(0) - 16
    objPos(1) = objPos(1) - (rtWin(3) - rtWin(1)) + 1
    SetWindowPos m_hwndTip, HWND_NOTOPMOST, objPos(0), objPos(1), 0, 0, _
        SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE Or SWP_SHOWWINDOW
End If
m_idTimer = SetTimer(0, 0, m_Delay, GetClassProcAddr(Me, 22))

End Sub

Public Sub Hide()
Call Class_Terminate
End Sub

Public Property Get Title() As String
Title = m_Title
End Property
Public Property Let Title(ByVal New_Value As String)
m_Title = New_Value
If m_hwndTip <> 0 Then SendMessage m_hwndTip, TTM_SETTITLE, m_Icon, ByVal m_Title
End Property

Public Property Get Text() As String
Text = m_TipInfo.lpszText
End Property
Public Property Let Text(ByVal New_Value As String)
m_TipInfo.lpszText = New_Value
If m_hwndTip <> 0 Then SendMessage m_hwndTip, TTM_UPDATETIPTEXTA, 0&, m_TipInfo
End Property

Public Property Get Style() As StyleConstants
Style = m_Style
End Property
Public Property Let Style(ByVal New_Value As StyleConstants)
m_Style = New_Value
End Property

Public Property Get Icon() As IconConstants
Icon = m_Icon
End Property
Public Property Let Icon(ByVal New_Value As IconConstants)
m_Icon = New_Value
If m_hwndTip <> 0 Then SendMessage m_hwndTip, TTM_SETTITLE, m_Icon, ByVal m_Title
End Property

Public Property Get Orientation() As OrientationConstants
Orientation = m_Orientation
End Property
Public Property Let Orientation(ByVal New_Value As OrientationConstants)
m_Orientation = New_Value
If New_Value = Up Then
m_TipInfo.dwFlags = TTF_IDISHWND Or TTF_TRANSPARENT Or TTF_TRACK
Else
m_TipInfo.dwFlags = TTF_IDISHWND Or TTF_TRANSPARENT Or TTF_SUBCLASS
End If
End Property

Public Property Get BackColor() As OLE_COLOR
BackColor = m_BackColor
End Property
Public Property Let BackColor(ByVal New_Value As OLE_COLOR)
m_BackColor = New_Value
If m_hwndTip <> 0 Then SendMessage m_hwndTip, TTM_SETTIPBKCOLOR, m_BackColor, 0&
End Property

Public Property Get ForeColor() As OLE_COLOR
ForeColor = m_ForeColor
End Property
Public Property Let ForeColor(ByVal New_Value As OLE_COLOR)
m_ForeColor = New_Value
If m_hwndTip <> 0 Then SendMessage m_hwndTip, TTM_SETTIPTEXTCOLOR, m_ForeColor, 0&
End Property

Public Property Get Delay() As Long
Delay = m_Delay
End Property
Public Property Let Delay(ByVal New_Value As Long)
m_Delay = New_Value
End Property

Private Function GetClassProcAddr(obj As Object, ByVal Index As Long, _
Optional ByVal ParamCount As Long = 4, Optional ByVal HasReturnValue As Boolean) As Long
Static lReturn As Long, pReturn As Long
Static AsmCode(50) As Byte
Dim i As Long, pThis As Long, pVtbl As Long, pFunc As Long

pThis = ObjPtr(obj)
CopyMemory pVtbl, ByVal pThis, 4
CopyMemory pFunc, ByVal pVtbl + (6 + Index) * 4, 4
pReturn = VarPtr(lReturn)

For i = 0 To UBound(AsmCode)                                '填充nop
    AsmCode(i) = &H90
Next
AsmCode(0) = &H55                                           'push   ebp
AsmCode(1) = &H8B: AsmCode(2) = &HEC                        'mov    ebp,esp
AsmCode(3) = &H53                                           'push   ebx
AsmCode(4) = &H56                                           'push   esi
AsmCode(5) = &H57                                           'push   edi
If HasReturnValue Then
    AsmCode(6) = &HB8                                       'mov    offset lReturn
    CopyMemory AsmCode(7), pReturn, 4
    AsmCode(11) = &H50                                      'push   eax
End If
For i = 0 To ParamCount - 1                                 'push   dword ptr[ebp+xx]
    AsmCode(12 + i * 3) = &HFF
    AsmCode(13 + i * 3) = &H75
    AsmCode(14 + i * 3) = (ParamCount - i) * 4 + 4
Next
i = i * 3 + 12
AsmCode(i) = &HB9                                           'mov    ecx,this
CopyMemory AsmCode(i + 1), pThis, 4
AsmCode(i + 5) = &H51                                       'push ecx
AsmCode(i + 6) = &HE8                                       'call 相对地址
CopyMemory AsmCode(i + 7), pFunc - VarPtr(AsmCode(i + 6)) - 5, 4
If HasReturnValue Then
    AsmCode(i + 11) = &HB8                                  'mov    eax,offset lReturn
    CopyMemory AsmCode(i + 12), pReturn, 4
    AsmCode(i + 16) = &H8B                                  'mov    eax,dword ptr[eax]
    AsmCode(i + 17) = &H0
End If
AsmCode(i + 18) = &H5F                                      'pop    edi
AsmCode(i + 19) = &H5E                                      'pop    esi
AsmCode(i + 20) = &H5B                                      'pop    ebx
AsmCode(i + 21) = &H8B: AsmCode(i + 22) = &HE5              'mov    esp,ebp
AsmCode(i + 23) = &H5D                                      'pop    ebp
AsmCode(i + 24) = &HC3                                      'ret
GetClassProcAddr = VarPtr(AsmCode(0))

End Function

Private Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, _
ByVal dwTime As Long)
Call Class_Terminate
End Sub

'----------------------------------------------------------------------------------------
'窗口调用,窗口添加两个Command

Option Explicit
Dim m_Tip As clsTip

Private Sub Command1_Click()
Me.Circle (20, 50), 2, vbRed
m_Tip.Orientation = Down
m_Tip.Delay = 1500 '1500毫秒后气泡自动消失
m_Tip.Show Me.hwnd, “这是一个可以指定位置和箭头方向气泡提示!” & vbCrLf & _
“第二行信息”, “信息”, 20, 50
End Sub

Private Sub Command2_Click()
m_Tip.Hide '也可以手动消失
End Sub

Private Sub Form_Load()
Set m_Tip = New clsTip
m_Tip.Style = TTS_BALLOON
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set m_Tip = Nothing
End Sub文章来源地址https://www.toymoban.com/news/detail-471188.html

到了这里,关于VB一个可以改变箭头方向的气泡提示的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • chatgpt帮我写的一个小程序气泡框代码

    效果图 这是一个气泡框 .bubble { position: relative; padding: 10px; border-radius: 8px; background-color: #ddd; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); } .triangle { position: absolute; width: 0; height: 0; top: -10px; left: 50%; margin-left: -10px; border-left: 10px solid transparent; border-right: 10px solid transparent; border-bottom: 10px soli

    2024年02月02日
    浏览(44)
  • 【能源转型的新方向】人工智能和机器学习如何改变能源市场的结构和竞争

    作者:禅与计算机程序设计艺术 随着传统能源部门将进入“被动”消费时代,我国的整体能源消费结构正在发生巨大的变化。传统能源部门会变得越来越多、越来越便宜,而现在更多的采用“主动”模式,比如用风量计来测算电网中各个节点的发电功率,甚至利用远程监控的

    2024年02月07日
    浏览(50)
  • 发NLP方向顶会这24个研究方向可以卷

    大家好,这里是 NewBeeNLP。 我们粉丝大多是nlp和推荐系统方向的大学生,研究生,博士生。春节来临,经我们不断努力,最终争取到了研梦非凡春节特惠价导师meeting福利! | NewbeeNLP公众号粉丝福利 1小时SCI科研论文指导导师meeting 原价2999元,NewbeeNLP粉丝专享价9.9元(第二批)

    2024年02月21日
    浏览(44)
  • 基于Vue2.0仿Element UI的el-tooltip实现一个气泡框组件,支持多数据类型的显示和内容为空时不显示气泡框

    场景:因为有个需求就是鼠标经过可多选的 el-select 选择器时,需要有个气泡框显示已选的内容,其实 el-tooltip 气泡框可以满足需求,就是用 el-tooltip 气泡框来包裹 el-select 选择器,但是当选择器一个也没选中,即内容为空时不应该也显示气泡框,有点影响美观。应该就是若内

    2024年02月13日
    浏览(47)
  • VSCode 前进和后退 (返回上一个浏览位置/下一个浏览位置)小箭头设置

    在VSCode写代码的过程中经常需要调到另一个函数,这时候需要快捷返回到原函数的位置,常用的快捷键是Alt+ LeftArrow,前进的快捷键是Alt+ RightArrow。 VSCode中还有一个直接点击就能前进和后退的快捷按钮,接下来就设置一下。 右键点击顶部菜单条,会弹出一个框,选中第二个就

    2024年02月11日
    浏览(55)
  • 改变语序可以降重吗 ai写作

    大家好,今天来聊聊改变语序可以降重吗 ai写作,希望能给大家提供一点参考。 以下是针对论文重复率高的情况,提供一些修改建议和技巧,可以借助此类工具: 改变语序可以降重吗? 作为网站编辑,我们经常遇到论文降重的问题。许多学者和学生在撰写论文时,为了提高

    2024年01月19日
    浏览(39)
  • 用VB和access制作一个登录系统

    第一步: 打开你的access数据库 创建两个表,一个用来记录医生的id和密码,另一个记录患者的id 第二部: vs中的操作: 新建一个项目 选择VB下的Windows窗口项目 ,新建它

    2024年02月10日
    浏览(38)
  • 学网络安全可以参考什么方向?该怎么学?

    在这个圈子技术门类中,工作岗位主要有以下三个方向: 安全研发 安全研究:二进制 方向 安全研究:网络渗透方向 下面逐一说明一下。 安全研发 安全行业的研发岗主要有两种分类: 与安全业务关系不大的研发岗位 与安全业务紧密相关的研发岗位 你可以把网络安全理解成

    2024年02月06日
    浏览(54)
  • ChatGPT会改变物流领域吗?可以为企业赋能吗?

    近期大火的ChatGPT,其实是一个对话的AI模型,就像一个聊天机器人。目前一些大公司客户服务网站上的自动聊天机器人虽然智能水平不如ChatGPT,但它们属于同一类技术。 从实战来看,ChatGPT堪称“小灵通”,从答疑解惑、编写代码、到创作诗歌和钢琴曲什么都会,就算不会也

    2023年04月26日
    浏览(37)
  • 我的创作纪念日——一年的时间可以改变很多

    不知不觉来到CSDN已经创作一年了。打心底讲,对于在CSDN开始坚持创作的原因,我用一句话来概括最合适不过了——“无心插柳柳成荫” 为什么这么说呢? 这要从我的一篇博客说起——《输入命令Javac报错详解》: 那也是我第一次接触到Java这门语言,想必大家在最开始学习

    2023年04月08日
    浏览(38)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包