回复 9楼 吹水佬
吹斑竹1、鼠标不选择,点其它地方时,怎么把 菜单去掉
2、你现在是鼠标右键,怎么加1个鼠标左键?
PROCEDURE myNotifyEvent(hWnd, wMsg, wParam, lParam) IF BETWEEN(lparam, 0x201, 0x204) && 左点击或右点击 SetForegroundWindow(hWnd) && 设置前台窗口,这样点击其他地方时弹出菜单会自动消失。
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编辑过]
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
** ** 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