也写个简单的示例:测试环境 Win10 + VFP9
程序代码:
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
_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 lparam == 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")
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