vb托盘程序代码(vb tray program code)

上传人:bao****ty 文档编号:117007756 上传时间:2019-11-18 格式:DOC 页数:31 大小:60KB
返回 下载 相关 举报
vb托盘程序代码(vb tray program code)_第1页
第1页 / 共31页
vb托盘程序代码(vb tray program code)_第2页
第2页 / 共31页
vb托盘程序代码(vb tray program code)_第3页
第3页 / 共31页
vb托盘程序代码(vb tray program code)_第4页
第4页 / 共31页
vb托盘程序代码(vb tray program code)_第5页
第5页 / 共31页
点击查看更多>>
资源描述

《vb托盘程序代码(vb tray program code)》由会员分享,可在线阅读,更多相关《vb托盘程序代码(vb tray program code)(31页珍藏版)》请在金锄头文库上搜索。

1、vb托盘程序代码(VB tray program code)VB tray program Xiangjie flash flashMany software running in the system tray area (that is, the lower right corner of the desktop display area) a small icon, it is running a logo, we can use the small icon pop-up menu to control the state of the application. This case i

2、s given a tray program function relatively complete, we can see how to add, delete, change tray icon with the API Shell_NotifyIcon function; and patients also demonstrated a method to add the menu for the tray icon and floating tips.The program (attached) used in the Shell_NotifyIcon, SendMessage, C

3、allWindowProc, SetWindowLong, API function, Shell_NotifyIcon is the main function of it is used to add, delete, change the system tray area (taskbar status area) icon, so lets take a look at the function declaration and parameters:Before you use the API function, you must declare in the program as f

4、ollows:Declare, Function, Shell_NotifyIcon, Lib, shell32.dll, Alias, Shell_NotifyIconA, ByVal, As, dwMessage, Long, As, NOTIFYICONDATA, lpData, As, LongThe meaning of each parameter is as follows:Argument: meaningDwMessage sets the value for the message, which can be several constant values: 0, 1, a

5、nd 2NIM_ADD = 0 adds icons to the system status barNIM_MODIFY = 1 modifies the icons in the system status barNIM_DELETE = 2 deletes the icon in the system status barLpData is used to pass into the NOTIFYICONDATA data structure variable, as follows:Type NOTIFYICONDATACbSize As Long needs to fill in t

6、he length of the NOTIFYICONDATA data structureHWnd As Long sets the handle to the windowThe ID value set by the Uid As Long for the iconThe UFlags As Long sets uCallbackMessage, hIcon, and szTip to be validUCallbackMessage As Long message numberHIcon As Long displays icons on the status barSzTip As

7、String * 64 prompt informationEnd TypeThe return value is Long, nonzero means success, and zero means failureBefore using the API function, we should first define the structure type NOTIFYICONDATA:Public Type NOTIFYICONDATACbSize, As, Long, HWnd, As, LongUid, As, Long, UFlags, As, LongUCallbackMessa

8、ge As LongHIcon As LongSzTip, As, String * 64End TypeThen define a NOTIFYICONDATA variable TheData to record the data that sets the tray iconPrivate TheData As NOTIFYICONDATAAt this point, you can use this function to set the system tray icon, as follows:1, add IconWith TheData.Uid = 0.HWnd = frm.HW

9、ndfrm.HWnd is the handle to the programs main form.cbSize = Len (TheData).HIcon = frm.Icon.Handlefrm.Icon.Handle points to the icon of the main form.UFlags = NIF_ICON.UCallbackMessage = TRAY_CALLBACKThe role is to allow the return message to be explained in detail in the next section.UFlags =.UFlags

10、, Or, NIF_MESSAGE.cbSize = Len (TheData)End WithShell_NotifyIcon, NIM_ADD, TheDataas defined earlier, NIM_ADD is set to add mode , and then add2. Delete the iconWith TheData.UFlags = 0End WithShell_NotifyIcon, NIM_DELETE, TheDataas defined earlier, NIM_DELETE is set to delete mode3, change iconWith

11、TheData.HIcon = pic.Handlepic is a picture maniac PictureBox, which stores icon files.UFlags = NIF_ICONEnd WithShell_NotifyIcon, NIM_MODIFY, TheDataas defined earlier, NIM_MODIFY is set to change mode4, add floating hint information for iconsWith TheData.SzTip = tip & vbNullChartip is string string,

12、 store prompt information.UFlags = NIF_TIPIndicates that the floating prompt should be setEnd WithShell_NotifyIcon, NIM_MODIFY, TheDataas defined earlier, NIM_MODIFY is set to modify modeThrough the above several sections of code, we can add, delete, change the system tray icon according to our own

13、needs, and add the floating hint information on the system icon. But the tray icon at this time is isolated and we cant use it to control the behavior of the application. What can I do? Dont worry. Look down, please.If you download and run this example program, youll see that if we right-click on th

14、e tray icon, a right-click menu pops up. If you click the corresponding menu item, the main window of the program changes along with it, so you can control the behavior of the program. If the main form is minimized, we click the left button on the tray icon, and the form will revert to its original

15、size. In fact, the implementation of the above functions relies on the messaging mechanism of the WINDOWS operating system, and it is not easy to fully understand the mechanism, but we can understand it as follows.Think of the WINDOWS operating system as a human brain,It receives, processes, and sends various kinds of information to our organs (of course, metaphor for each application), that is, it is the center of the message. Each application (or even every buttons, lab

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号