资源预览内容
第1页 / 共31页
第2页 / 共31页
第3页 / 共31页
第4页 / 共31页
第5页 / 共31页
第6页 / 共31页
第7页 / 共31页
第8页 / 共31页
第9页 / 共31页
第10页 / 共31页
亲,该文档总共31页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
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 is 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, CallWindowProc, 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 follows: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, and 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 the 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 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, LongUCallbackMessage 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.HWndfrm.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, 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 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, 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 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 the 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 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
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号