| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4374 人关注过本帖, 2 人收藏
标题:请教,关于系统托盘类Systray.VCX使用
只看楼主 加入收藏
mywisdom88
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:191
帖 子:3147
专家分:8408
注 册:2015-3-25
收藏
得分:0 
回复 9楼 吹水佬
吹斑竹
1、鼠标不选择,点其它地方时,怎么把 菜单去掉
2、你现在是鼠标右键,怎么加1个鼠标左键?
2016-03-28 14:03
aaaaaa
Rank: 8Rank: 8
等 级:贵宾
威 望:21
帖 子:796
专家分:937
注 册:2012-9-4
收藏
得分:0 
以下是引用mywisdom88在2016-3-27 18:20:06的发言:

刚测试了1下,基本上可以。
但也还是有个问题,就是,如果我把你的这个Image Capture对应的表单调整最大化,然后调出这个表单,然后,就点不出这个托盘了。


这个是以前我收集的一个示例,我没有用过。
如果最大化就点不出这个托盘了,而规范窗口可以点出这个托盘的,在最小化窗口到托盘时,先把最大化的窗口切换到规范窗口,这个可以增加一条语句就可以了。

Win 7 应该支持托盘的,我的机子就是 Win 7。

民工子弟学校22班团小组长阳光模特队长冲锋篮球队前锋小苹果合唱队领唱蓝天舞蹈队编舞
2016-03-28 14:08
mywisdom88
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:191
帖 子:3147
专家分:8408
注 册:2015-3-25
收藏
得分:0 
回复 12楼 aaaaaa
好像不行,我是说,在显示表单时,只要表单最大化后,在托盘那里,就再也点不出菜单了。
2016-03-28 14:26
aaaaaa
Rank: 8Rank: 8
等 级:贵宾
威 望:21
帖 子:796
专家分:937
注 册:2012-9-4
收藏
得分:0 
在我发的示例中,没有表单最大化后按钮,屏蔽掉了。
自己再试试吧,托盘的东东不感兴趣,做表单,拉控件,写文档,这是我们班里女同学做的事情。

民工子弟学校22班团小组长阳光模特队长冲锋篮球队前锋小苹果合唱队领唱蓝天舞蹈队编舞
2016-03-28 14:49
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10607
专家分:43182
注 册:2014-5-20
收藏
得分:0 
以下是引用mywisdom88在2016-3-28 14:03:28的发言:
吹斑竹
1、鼠标不选择,点其它地方时,怎么把 菜单去掉
2、你现在是鼠标右键,怎么加1个鼠标左键?

改了一下:
    PROCEDURE myNotifyEvent(hWnd, wMsg, wParam, lParam)
        IF BETWEEN(lparam, 0x201, 0x204)    && 左点击或右点击
            SetForegroundWindow(hWnd)       && 设置前台窗口,这样点击其他地方时弹出菜单会自动消失。

示例有点简单,只想提供点思路帮助理解创建托盘图标的原理,有好多API用到的参数没列明,可查相关API函数的使用方法。
程序代码:
DECLARE LONG Shell_NotifyIcon    IN Shell32 LONG, STRING@
DECLARE LONG LoadImage           IN User32 LONG, STRING@, LONG, LONG, LONG, LONG
DECLARE LONG CreatePopupMenu     IN User32
DECLARE LONG AppendMenu          IN User32 LONG, LONG, LONG, STRING@
DECLARE LONG TrackPopupMenu      IN User32 LONG, LONG, LONG, LONG, LONG, LONG, LONG
DECLARE LONG GetCursorPos        IN User32 STRING@
DECLARE LONG PostMessage         IN User32 LONG, LONG, LONG, LONG
DECLARE LONG SetForegroundWindow IN User32 LONG

_screen.Visible = .F.
of = CREATEOBJECT("form1")
of.show
READ EVENTS
CLEAR ALL 
RETURN


DEFINE CLASS form1 as Form
    ShowWindow = 2
    ShowInTaskbar = .F.
    AutoCenter = .T.
    
    hMenu = 0
    ADD OBJECT edit1 as editbox WITH top=10,left=10,width=this.Width-20,height=this.Height-20
    
    PROCEDURE Unload
        LOCAL stData
        stData = BINTOC(88, "4RS");
               + BINTOC(this.hWnd, "4RS"); 
               + BINTOC(101, "4RS");
               + REPLICATE(0h00, 76)
        Shell_NotifyIcon(2, @stData)
        CLEAR EVENTS 
    ENDPROC
    
    PROCEDURE Init
        BINDEVENT(this.hWnd, 0x401, this, "myNotifyEvent")
        BINDEVENT(this.hWnd, 0x111, this, "myCommand")
        this.Show
        PostMessage(this.hWnd, 0x111, 0x102, 0)
        LOCAL stData
        stData = BINTOC(88, "4RS");
               + BINTOC(this.hWnd, "4RS"); 
               + BINTOC(101, "4RS");
               + BINTOC(7, "4RS");
               + BINTOC(0x401, "4RS");
               + BINTOC(LoadImage(0, "systray_demo.ico", 1, 0, 0, 0x10), "4RS");
               + "点击弹出菜单" + REPLICATE(0h00, 50)
        Shell_NotifyIcon(0, @stData)
    ENDPROC
    
    PROCEDURE myNotifyEvent(hWnd, wMsg, wParam, lParam)
        IF BETWEEN(lparam, 0x201, 0x204)    && 左点击或右点击
            IF this.hMenu == 0
                this.hMenu = CreatePopupMenu()
                AppendMenu(this.hMenu, 0, 0x101, "显示窗口")
                AppendMenu(this.hMenu, 0, 0x102, "隐藏窗口")
                AppendMenu(this.hMenu, 0, 0x103, "关闭窗口")
            ENDIF
            LOCAL stPOINT, nX, nY
            stPOINT = REPLICATE(0h00, 8)
            GetCursorPos(@stPOINT)
            nX = CTOBIN(LEFT(stPOINT, 4), "4RS")
            nY = CTOBIN(RIGHT(stPOINT, 4), "4RS")    
            SetForegroundWindow(hWnd)       && 设置前台窗口,这样点击其他地方时弹出菜单会自动消失。
            TrackPopupMenu(this.hMenu, 2, nX, nY, 0, hWnd, 0)
        ENDIF
    ENDPROC
    
    PROCEDURE myCommand(hWnd, wMsg, wParam, lParam)
        DO CASE 
        CASE wParam == 0x101
            this.Visible = .T.
        CASE wParam == 0x102
            this.Visible = .F.
        CASE wParam == 0x103
            this.Release 
        ENDCASE
    ENDPROC
ENDDEFINE


[此贴子已经被作者于2016-3-28 16:00编辑过]

2016-03-28 15:26
mywisdom88
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:191
帖 子:3147
专家分:8408
注 册:2015-3-25
收藏
得分:0 
*我想把左右鼠标分开菜单,好像有问题,不知道怎么搞,我这样第1次左的化,以后显示都是左。。第1次是右,以后显示都是右
PROCEDURE myNotifyEvent(hWnd, wMsg, wParam, lParam)
        SetForegroundWindow(hWnd)           && 设置前台窗口,这样点击其他地方时弹出菜单会自动消失。
        IF BETWEEN(lparam, 0x201, 0x204)    && 左点击或右点击
            IF lparam==0x204
               MESSAGEBOX("右")
               IF this.hMenu == 0
                  this.hMenu = CreatePopupMenu()
                  AppendMenu(this.hMenu, 0, 0x101, "显示窗口-右")
                  AppendMenu(this.hMenu, 0, 0x102, "隐藏窗口-右")
                  AppendMenu(this.hMenu, 0, 0x103, "关闭窗口-右")
                  AppendMenu(this.hMenu, 0, 0x104, "自己家的-右")
               ENDIF
            ELSE
               MESSAGEBOX("左")
               IF this.hMenu == 0
                  this.hMenu = CreatePopupMenu()
                  AppendMenu(this.hMenu, 0, 0x201, "显示窗口-左")
                  AppendMenu(this.hMenu, 0, 0x202, "隐藏窗口-左")
                  AppendMenu(this.hMenu, 0, 0x203, "关闭窗口-左")
                  AppendMenu(this.hMenu, 0, 0x204, "自己家的-左")
               ENDIF
            ENDIF
            
            LOCAL stPOINT, nX, nY
            stPOINT = REPLICATE(0h00, 8)
            GetCursorPos(@stPOINT)
            nX = CTOBIN(LEFT(stPOINT, 4), "4RS")
            nY = CTOBIN(RIGHT(stPOINT, 4), "4RS")   
            TrackPopupMenu(this.hMenu, 2, nX, nY, 0, hWnd, 0)
        ENDIF
    ENDPROC
2016-03-28 17:15
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10607
专家分:43182
注 册:2014-5-20
收藏
得分:15 
回复 16楼 mywisdom88
加多一个弹出菜单,顺便优化一下:
程序代码:
DECLARE LONG Shell_NotifyIcon    IN Shell32 LONG, STRING@
DECLARE LONG LoadImage           IN User32 LONG, STRING@, LONG, LONG, LONG, LONG
DECLARE LONG CreatePopupMenu     IN User32
DECLARE LONG AppendMenu          IN User32 LONG, LONG, LONG, STRING@
DECLARE LONG TrackPopupMenu      IN User32 LONG, LONG, LONG, LONG, LONG, LONG, LONG
DECLARE LONG GetCursorPos        IN User32 STRING@
DECLARE LONG PostMessage         IN User32 LONG, LONG, LONG, LONG
DECLARE LONG SetForegroundWindow IN User32 LONG

_screen.Visible = .F.
of = CREATEOBJECT("form1")
of.show
READ EVENTS
CLEAR ALL 
RETURN


DEFINE CLASS form1 as Form
    ShowWindow = 2
    ShowInTaskbar = .F.
    AutoCenter = .T.
    
    hLMenu = 0
    hRMenu = 0
    
    ADD OBJECT edit1 as editbox WITH top=10,left=10,width=this.Width-20,height=this.Height-20
    
    PROCEDURE Unload
        LOCAL stData
        stData = BINTOC(88, "4RS");
               + BINTOC(this.hWnd, "4RS"); 
               + BINTOC(101, "4RS");
               + REPLICATE(0h00, 76)
        Shell_NotifyIcon(2, @stData)
        CLEAR EVENTS 
    ENDPROC
    
    PROCEDURE Init
        BINDEVENT(this.hWnd, 0x401, this, "myNotifyEvent")
        BINDEVENT(this.hWnd, 0x111, this, "myCommand")
        this.Show
        PostMessage(this.hWnd, 0x111, 0x102, 0)    && 这时用异步消息才可以隐藏窗口

        this.hLMenu = CreatePopupMenu()
        AppendMenu(this.hLMenu, 0, 0x101, "显示窗口-左")
        AppendMenu(this.hLMenu, 0, 0x102, "隐藏窗口-左")
        AppendMenu(this.hLMenu, 0, 0x103, "关闭窗口-左")
        AppendMenu(this.hLMenu, 0, 0x104, "自己家的-左")

        this.hRMenu = CreatePopupMenu()
        AppendMenu(this.hRMenu, 0, 0x201, "显示窗口-右")
        AppendMenu(this.hRMenu, 0, 0x202, "隐藏窗口-右")
        AppendMenu(this.hRMenu, 0, 0x203, "关闭窗口-右")
        AppendMenu(this.hRMenu, 0, 0x204, "自己家的-右")

        LOCAL stData
        stData = BINTOC(88, "4RS");
               + BINTOC(this.hWnd, "4RS"); 
               + BINTOC(101, "4RS");
               + BINTOC(7, "4RS");
               + BINTOC(0x401, "4RS");
               + BINTOC(LoadImage(0, "vfp.ico", 1, 0, 0, 0x10), "4RS");
               + "点击弹出菜单" + REPLICATE(0h00, 50)
        Shell_NotifyIcon(0, @stData)
    ENDPROC
    
    PROCEDURE myNotifyEvent(hWnd, wMsg, wParam, lParam)
        IF BETWEEN(lparam, 0x201, 0x204)    && 左点击或右点击
            LOCAL stPOINT, nX, nY
            stPOINT = REPLICATE(0h00, 8)
            GetCursorPos(@stPOINT)
            nX = CTOBIN(LEFT(stPOINT, 4), "4RS")
            nY = CTOBIN(RIGHT(stPOINT, 4), "4RS")    
            SetForegroundWindow(hWnd)       && 设置前台窗口,这样点击其他地方时弹出菜单会自动消失。
            TrackPopupMenu(IIF(lparam == 0x201, this.hLMenu, this.hRMenu), 2, nX, nY, 0, hWnd, 0)
        ENDIF
    ENDPROC
    
    PROCEDURE myCommand(hWnd, wMsg, wParam, lParam)
        DO CASE 
        CASE wParam == 0x101
            this.Visible = .T.
        CASE wParam == 0x102
            this.Visible = .F.
        CASE wParam == 0x103
            this.Release 
        CASE wParam == 0x104
            MESSAGEBOX("自己家的-左")
        CASE wParam == 0x201
            this.Visible = .T.
        CASE wParam == 0x202
            this.Visible = .F.
        CASE wParam == 0x203
            this.Release 
        CASE wParam == 0x204
            MESSAGEBOX("自己家的-右")
        ENDCASE
    ENDPROC
ENDDEFINE
2016-03-28 20:05
mywisdom88
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:191
帖 子:3147
专家分:8408
注 册:2015-3-25
收藏
得分:0 
回复 17楼 吹水佬
吹斑竹,我把你这段代码,放进我顶层表单上,表单有菜单的。
发现,只要把你这段代码上进去,能出托盘,但顶层表单的菜单,上面的菜单,就用不了,怎么点都没反应了。。
2016-03-31 23:40
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10607
专家分:43182
注 册:2014-5-20
收藏
得分:0 
回复 18楼 mywisdom88
示例不太严谨,相关消息被拦截了,添加消息反弹就可以。
程序代码:
** 
** Systray_Demo.prg
**
DECLARE LONG Shell_NotifyIcon    IN Shell32 LONG, STRING@
DECLARE LONG LoadImage           IN User32 LONG, STRING@, LONG, LONG, LONG, LONG
DECLARE LONG CreatePopupMenu     IN User32
DECLARE LONG AppendMenu          IN User32 LONG, LONG, LONG, STRING@
DECLARE LONG TrackPopupMenu      IN User32 LONG, LONG, LONG, LONG, LONG, LONG, LONG
DECLARE LONG GetCursorPos        IN User32 STRING@
DECLARE LONG PostMessage         IN User32 LONG, LONG, LONG, LONG
DECLARE LONG SendMessage         IN User32 LONG, LONG, LONG, LONG
DECLARE LONG SetForegroundWindow IN User32 LONG

_screen.Visible = .F.
of = CREATEOBJECT("form1")
of.show
READ EVENTS
CLEAR ALL 
RETURN


DEFINE CLASS form1 as Form
    ShowWindow = 2
    ShowInTaskbar = .F.
    AutoCenter = .T.
    
    hLMenu = 0
    hRMenu = 0    && 如果不是分配给一个窗口,调用DestroyMenu来释放菜单资源。
    
    ADD OBJECT edit1 as editbox WITH top=10,left=10,width=this.Width-20,height=this.Height-50
    
    PROCEDURE Unload
        LOCAL stData
        stData = BINTOC(88, "4RS");
               + BINTOC(this.hWnd, "4RS"); 
               + BINTOC(101, "4RS");
               + REPLICATE(0h00, 76)
        Shell_NotifyIcon(2, @stData)
        CLEAR EVENTS 
    ENDPROC
    
    PROCEDURE Init
        BINDEVENT(this.hWnd, 0x401, this, "myNotifyEvent")    && 处理自定义消息(0x401)
        BINDEVENT(this.hWnd, 0x111, this, "myCommand")        && 处理系统消息(WM_COMMAND 0x111)
        this.Show
        PostMessage(this.hWnd, 0x111, 0x102, 0)    && 这时用异步消息才可以隐藏窗口

        myMenu(this)    && 窗口菜单

        this.hLMenu = CreatePopupMenu()    && 托盘菜单
        AppendMenu(this.hLMenu, 0, 0x101, "显示窗口-左")
        AppendMenu(this.hLMenu, 0, 0x102, "隐藏窗口-左")
        AppendMenu(this.hLMenu, 0, 0x103, "关闭窗口-左")
        AppendMenu(this.hLMenu, 0, 0x104, "自己家的-左")

        this.hRMenu = CreatePopupMenu()
        AppendMenu(this.hRMenu, 0, 0x201, "显示窗口-右")
        AppendMenu(this.hRMenu, 0, 0x202, "隐藏窗口-右")
        AppendMenu(this.hRMenu, 0, 0x203, "关闭窗口-右")
        AppendMenu(this.hRMenu, 0, 0x204, "自己家的-右")

        LOCAL stData
        stData = BINTOC(88, "4RS");
               + BINTOC(this.hWnd, "4RS"); 
               + BINTOC(101, "4RS");
               + BINTOC(7, "4RS");
               + BINTOC(0x401, "4RS");
               + BINTOC(LoadImage(0, "vfp.ico", 1, 0, 0, 0x10), "4RS");
               + "点击弹出菜单" + REPLICATE(0h00, 50)
        Shell_NotifyIcon(0, @stData)
    ENDPROC
    
    PROCEDURE myNotifyEvent(hWnd, wMsg, wParam, lParam)
        IF BETWEEN(lparam, 0x201, 0x204)    && 左点击或右点击
            LOCAL stPOINT, nX, nY
            stPOINT = REPLICATE(0h00, 8)
            GetCursorPos(@stPOINT)
            nX = CTOBIN(LEFT(stPOINT, 4), "4RS")
            nY = CTOBIN(RIGHT(stPOINT, 4), "4RS")    
            SetForegroundWindow(hWnd)       && 设置前台窗口,这样点击其他地方时弹出菜单会自动消失。
            TrackPopupMenu(IIF(lparam == 0x201, this.hLMenu, this.hRMenu), 2, nX, nY, 0, hWnd, 0)
        ENDIF
    ENDPROC
    
    PROCEDURE myCommand(hWnd, wMsg, wParam, lParam)
        DO CASE 
        CASE wParam == 0x101
            this.Visible = .T.
        CASE wParam == 0x102
            this.Visible = .F.
        CASE wParam == 0x103
            this.Release 
        CASE wParam == 0x104
            MESSAGEBOX("自己家的-左")
        CASE wParam == 0x201
            this.Visible = .T.
        CASE wParam == 0x202
            this.Visible = .F.
        CASE wParam == 0x203
            this.Release 
        CASE wParam == 0x204
            MESSAGEBOX("自己家的-右")
        OTHERWISE
            SendMessage(hWnd, wMsg, wParam, lParam)    && 消息反弹
        ENDCASE
    ENDPROC
ENDDEFINE


FUNCTION myMenu(oThis)
    DEFINE MENU menu1 BAR AT LINE 0 IN (oThis.name)

    DEFINE PAD pad1 OF menu1 PROMPT "pad1"
    DEFINE PAD pad2 OF menu1 PROMPT "pad2"
    ON PAD pad1 OF menu1 ACTIVATE POPUP pop1
    ON PAD pad2 OF menu1 ACTIVATE POPUP pop2

    DEFINE POPUP pop1
    DEFINE BAR 1 OF pop1 PROMPT "pop1_bar1"
    DEFINE BAR 2 OF pop1 PROMPT "pop1_bar2"
    ON SELECTION POPUP pop1 selpop(POPUP(), PROMPT())

    DEFINE POPUP pop2
    DEFINE BAR 1 OF pop2 PROMPT "pop2_bar1"
    DEFINE BAR 2 OF pop2 PROMPT "pop2_bar2"
    ON SELECTION POPUP pop2 selpop(POPUP(), PROMPT())

    ACTIVATE MENU menu1
ENDFUNC

FUNCTION selpop(cPopup, cPrompt)
    MESSAGEBOX(cPopup + "---" + cPrompt)
ENDFUNC
2016-04-01 09:20
mywisdom88
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:191
帖 子:3147
专家分:8408
注 册:2015-3-25
收藏
得分:0 
虽然,很多地方看不明白,但经过吹斑竹修改后,可以了。好像主要在这里
OTHERWISE
SendMessage(hWnd, wMsg, wParam, lParam)    && 消息反弹
2016-04-01 09:47
快速回复:请教,关于系统托盘类Systray.VCX使用
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024964 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved