我們知道,在.Net framework 中,具有很多已經封裝好的強大類庫,並且QTP可以通過DotNetFactory這個保留對象來創建這些類庫中的實例,來實現一些原本VBS所不具備的功能。
在System.Windows.Forms命名空間下包含了絕大多數windows控件的類庫。在這個例子中, 主要是通過創建一個NotifyIcon控件來實現一個任務欄氣泡提示信息的彈出.
代碼如下:
'Create a new instance of Notification
Set objNotification = DotNetFactory.CreateInstance("System.Windows.Forms.NotifyIcon")
'Set the Icon for the Notification
objNotification.Icon = DotNetFactory.CreateInstance("System.Drawing.SystemIcons","System.Drawing").Information
'Set the Icon for the balloontipicon
set BalloonTipIcon = DotNetFactory.CreateInstance("System.Windows.Forms.ToolTipIcon").Info
'display the ballontip with certain infomation
objNotification.Visible = true
objNotification.ShowBalloonTip 0, "Tip", "test balloonTip", BalloonTipIcon
'do something here
wait 2
'Relase and close the notification
objNotification.Dispose