我的朋友问我关于ms访问的非阻塞吐司通知.我的第一个想法是,检查谷歌你会发现大量的样本.他对他得到的样品不满意.
原文链接:https://www.f2er.com/windows/372124.html他想要(JQuery)非阻塞通知.用户需要知道但不一定需要互动的东西.
由于在VBA中无法进行线程化,我想,如果你能编写自己的.dll怎么办?所以我最终编写了一个.NET DLL,可以通过(windows)VBA代码访问并显示Toast通知.
(实际的dll创建和从vba访问.NET dll是我将在稍后介绍的另一个主题)(You can read more in my blog根据您的意愿留下评论或建议.)
现在,您可以从这里下载我创建的DLL:
HERE
编辑:以上下载链接和GitHub链接已更新为我认为属于作者的工作链接.
如果您担心下载未知的DLL:VirusTotal Scan report
将DLL添加到应用程序的根文件夹,并将以下代码添加到您的应用程序.
'Module level public variable Public gTOASTER As Object ' to save window metrics Public Type RECT Left As Long ' x1 Top As Long ' y1 Right As Long ' x2 Bottom As Long ' y2 End Type #If VBA7 Then Public Declare PtrSafe Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As LongPtr Public Declare PtrSafe Function KRISH_VBA_TOOLS Lib "VBA_TOOLS.dll" () As Object Public Declare PtrSafe Function GetWindowRect Lib "user32" (ByVal hWnd As LongPtr,ByRef lpRect As RECT) As LongPtr #Else Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal strFilePath As String) As Long Public Declare Function KRISH_VBA_TOOLS Lib "VBA_TOOLS.dll" () As Object Public Declare Function GetWindowRect Lib "user32" (ByVal hWnd As LongPtr,ByRef lpRect As RECT) As LongPtr #End If Public Function FN_TOAST_DLL(iMessage As String,Optional iCLOSE_DURATION As Long = 3000,Optional iType As String = "success",Optional iANIME_DURATION As Long = 1000,Optional iFONT_COLOR As String = "#FFFFFF",Optional iX As Long = 0,Optional iY As Long = 0,Optional iANIME_DIRECTION As Integer = 1,Optional iPARENT_HWND As Long = 0) On Error GoTo LABEL_EXIT_ROUTINE: If gTOASTER Is Nothing Then LoadLibrary (FN_APP_GET_BASE_PATH & "VBA_TOOLS.dll") Set gTOASTER = KRISH_VBA_TOOLS() GoTo LABEL_TOAST Else GoTo LABEL_TOAST End If On Error GoTo 0 Exit Function LABEL_EXIT_ROUTINE: msgBox iMessage & vbnewline & err.description Exit Function LABEL_TOAST: 'set background color. (pass any html color code) Select Case iType Case "error" iType = "#F76160" Case "success" iType = "#26ad82" Case Else iType = "#26ad82" End Select 'if parent object is provided show the toast on top of the parent. if custom x,y is provided use x,y coordinated. if none provided use access app's locaiton. Dim mRect As RECT If iPARENT_HWND <= 0 Then If iX = 0 And iY = 0 Then GetWindowRect Application.hWndAccessApp,mRect iANIME_DIRECTION = 0 'anim direction 0 to down and 1 to up End If Else ' iPARENT_HWND > 0 Then 'parent_hwnd is null GetWindowRect iPARENT_HWND,mRect End If 'set up some offsets iX = mRect.Left + 360 iY = mRect.Top + 1 On Error Resume Next gTOASTER.FN_SHOW_TOAST iMessage,iCLOSE_DURATION,iType,iANIME_DURATION,iFONT_COLOR,iX,iY,iANIME_DIRECTION End Function Public Function FN_APP_GET_BASE_PATH() Dim FN As String FN = Application.CurrentProject.path If VBA.Right(Application.CurrentProject.path,1) <> "\" Then FN = FN & "\" FN_APP_GET_BASE_PATH = FN End Function
如果要自定义fn_toast_dll函数,则从DLL中获取参数列表:
' /// <summary> ' /// ' /// </summary> ' /// <param name="iMessage">Message to display</param> ' /// <param name="iDuration">Duration in Milliseconds to keep the toast before fading out..</param> ' /// <param name="iBG_COLOR">HTML color code for your toast background...</param> ' /// <param name="iANIME_DURATION">Millisecond value used to for fading in and out the Toast.. 1/4 is used to fade in rest to fade out..</param> ' /// <param name="iFONT_COLOR">HTML Color code for the font..</param> ' /// <param name="iX">x position on the screen. where the toast should appear</param> ' /// <param name="iY">y position on the screen where the toast should appear</param> ' /// <param name="iANIM_DIRECTION">{0,1} 0 will show/add further notifications downwards and 1 upwards.</param> ' /// <returns></returns>
FN_TOAST_DLL "hello this is a green test" ' By default a success message with 3 seconds will be "toasted" FN_TOAST_DLL "hello this is an error",15000,"error"
用法:
您可以将此用于任何非交互式警报,例如登录成功,操作取消警报或任何用户无需按OK确认您的消息.
目标
我将在GitHub上传Dll项目,并请求其他VBA C#专家的贡献,使其更加更加漂亮,并且可供所有VBA开发人员使用.