当前位置: 网学 > 编程文档 > VB > 正文

Windows下面向任务栏编程的若干问题

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/16
下载{$ArticleTitle}原创论文样式
为当单击图标时的弹出菜单。在frmcaution中加入一个panel,命名为“pnlmessage”,用于显示消息。在frmcaution中加入一个多媒体控件,命名为“mm”,用于播放音乐。在frmcaution中加入一个时间控件“Time1”。
3、在工程中加入一个标准模块mdlCommon,并在其中放置如下代码:
''API函数声明
Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
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
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public 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

Public prevWndProc As Long ''原有的窗口消息处理函数
Public Message As String ''消息内容
Public TipInterval As Integer ''提示时间间隔
Public TipTime As String ''提示时间
Public Time As Integer ''累计时间

Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_USER + 100 Then
If lParam = WM_LBUTTONDOWN Or lParam = WM_RBUTTONDOWN Then
''当按下鼠标左键或右键时弹出菜单
frmCaution.PopupMenu frmCaution.mnuaa
End If
End If
''其它的消息交给系统处理,prevWndProc为原来的窗口消息处理函数的句柄
WndProc = CallWindowProc(prevWndProc, hwnd, Msg, wParam, lParam)
End Function
以上程序限于篇幅略去了数据结构和常量的定义。该定义可从“API文本浏览器”中获得。
4、编写frmcaution的Form_Load()过程。
Private Sub Form_Load()
Load frmSound
prevWndProc = GetWindowLong(Me.hwnd, GWL_WNDPROC) ''获取系统确省的窗口消息处理函数句柄
SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf WndProc ''指定WndProc为新的消息处理函数
''加入图标
Dim nid As NOTIFYICONDATA
nid.cbSize = Len(nid)
nid.hwnd = Me.hwnd
nid.uID = 9998
nid.uFlags = NIF_ICON + NIF_TIP + NIF_MESSAGE
nid.hIcon = Me.Icon
nid.uCallbackMessage = WM_USER + 100 ''定义消息编号
Shell_NotifyIcon NIM_ADD, nid
''设置显示界面
pnlMessage.Left = (Me.ScaleWidth - pnlMessage.Width) / 2
pnlMessage.Top = (Me.ScaleHeight - pnlMessage.Height) / 2
TipInterval = 30 ''提醒时间间隔默认为30分钟
TipTime = "" ''提醒时间默认为空
Time = 0
Message = "亲爱的主人,建议您先休息5分钟!"
mm.Filename = frmSound!filSound.List(0)
End Sub
5、编写frmcaution的Form_Unload()过程。
Private Sub Form_Unload(Cancel As Integer)
Dim nid As NOTIFYICONDATA
''恢复原来的窗口消息处理函数
SetWindowLong Me.hwnd, GWL_WNDPROC, prevWndProc
''删除图标
nid.cbSize = Len(nid)
nid.hwnd = Me.hwnd
nid.uID = uID
Shell_NotifyIcon NIM_DELETE, nid
mm.Command = "close"
End Sub
6、编写Timer1_Timer()过程。
Private Sub Timer1_Timer()
If

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号