Sign in to follow this  
Followers 0
Tankbuster

Multiple Tray Icons from one.exe/.au3

5 posts in this topic

#1 ·  Posted (edited)

Hello,

I searched this forum for a guide to display with one exe/au3 more than one tray icon.

I found a old post, but in this post (multiple tray icons) the poster was misunderstood (so I guess, because to the others it was not clear why)

So to avoid confusion I will explain what I want:

As you know in Windows7 and Server2008 the services run in a isolated session 0. This session is not able to display dialogues and icons.

The several services (my own programs) sometimes want to inform the logged in user about their state by displaying icons and sometimes a user gui for more complex messages (with autolose).

To achieve this I thought about this solution:

My services write to the eventlog. and now the EventReader reads the eventlog and checks for messages about my services.

For a small example lets say two services write to the eventlog, now to not run a instance for each service I want my script to display a tray Icon for each service.

So the question is:

Is there a option to display and change multiple tray icon based on a handle?

If not I will start a instance for each service.

If I was not clear in explaining, just ask, I will try to give you a better answer.

//edit:

Ah, I forgot:

Multi Icons from one exe at the same time.

Edited by Tankbuster

Share this post


Link to post
Share on other sites



Look at _WinAPI_ShellNotifyIcon() from WinAPIEx.au3.

#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global $hWnd = WinGetHandle(AutoItWinGetTitle())
Global $tNOTIFYICONDATA = DllStructCreate($tagNOTIFYICONDATA)

OnAutoItExitRegister('OnAutoItExit')

DllStructSetData($tNOTIFYICONDATA, 'Size', DllStructGetSize($tNOTIFYICONDATA))
DllStructSetData($tNOTIFYICONDATA, 'hWnd', WinGetHandle(AutoItWinGetTitle()))
DllStructSetData($tNOTIFYICONDATA, 'Flags', $NIF_ICON)

DllStructSetData($tNOTIFYICONDATA, 'ID', 2)
DllStructSetData($tNOTIFYICONDATA, 'hIcon', _WinAPI_ShellExtractIcons(@SystemDir & '\shell32.dll', 166, 16, 16))
_WinAPI_ShellNotifyIcon($NIM_ADD, $tNOTIFYICONDATA)

DllStructSetData($tNOTIFYICONDATA, 'ID', 3)
DllStructSetData($tNOTIFYICONDATA, 'hIcon', _WinAPI_ShellExtractIcons(@SystemDir & '\shell32.dll', 130, 16, 16))
_WinAPI_ShellNotifyIcon($NIM_ADD, $tNOTIFYICONDATA)

While 1
    Sleep(1000)
WEnd

Func OnAutoItExit()
    DllStructSetData($tNOTIFYICONDATA, 'ID', 2)
    _WinAPI_ShellNotifyIcon($NIM_DELETE, $tNOTIFYICONDATA)
    DllStructSetData($tNOTIFYICONDATA, 'ID', 3)
    _WinAPI_ShellNotifyIcon($NIM_DELETE, $tNOTIFYICONDATA)
EndFunc   ;==>OnAutoItExit

Share this post


Link to post
Share on other sites

Thank you very much.

I just downloaded your WinAPI.

But it looks like you saved my day.

I will now read your original post to get the complete picture.

Share this post


Link to post
Share on other sites

.....sorry, I have to ask a second (and third) question......

I want to set also the TOOL TIP, so I tried:

#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global $hWnd = WinGetHandle(AutoItWinGetTitle())
Global $tNOTIFYICONDATA = DllStructCreate($tagNOTIFYICONDATA)

OnAutoItExitRegister('OnAutoItExit')

DllStructSetData($tNOTIFYICONDATA, 'Size', DllStructGetSize($tNOTIFYICONDATA))
DllStructSetData($tNOTIFYICONDATA, 'hWnd', WinGetHandle(AutoItWinGetTitle()))
DllStructSetData($tNOTIFYICONDATA, 'Flags', $NIF_ICON)

DllStructSetData($tNOTIFYICONDATA, 'ID', 2)
DllStructSetData($tNOTIFYICONDATA, 'hIcon', _WinAPI_ShellExtractIcons(@SystemDir & '\shell32.dll', 166, 16, 16))
DllStructSetData($tNOTIFYICONDATA, 'Tip', "huhu")
_WinAPI_ShellNotifyIcon($NIM_ADD, $tNOTIFYICONDATA)

DllStructSetData($tNOTIFYICONDATA, 'ID', 3)
DllStructSetData($tNOTIFYICONDATA, 'hIcon', _WinAPI_ShellExtractIcons(@SystemDir & '\shell32.dll', 130, 16, 16))
_WinAPI_ShellNotifyIcon($NIM_ADD, $tNOTIFYICONDATA)

While 1
    for $n = 100 to 150 
    Sleep(100)
    DllStructSetData($tNOTIFYICONDATA, 'ID', 2)
    DllStructSetData($tNOTIFYICONDATA, 'Tip', "Hello World "&$n)
    DllStructSetData($tNOTIFYICONDATA, 'hIcon', _WinAPI_ShellExtractIcons(@SystemDir & '\shell32.dll', $n, 16, 16))
    _WinAPI_ShellNotifyIcon($NIM_MODIFY, $tNOTIFYICONDATA)
    next

WEnd

Func OnAutoItExit()
    DllStructSetData($tNOTIFYICONDATA, 'ID', 2)
    _WinAPI_ShellNotifyIcon($NIM_DELETE, $tNOTIFYICONDATA)
    DllStructSetData($tNOTIFYICONDATA, 'ID', 3)
    _WinAPI_ShellNotifyIcon($NIM_DELETE, $tNOTIFYICONDATA)
EndFunc   ;==>OnAutoItExit

LINE 27: DllStructSetData($tNOTIFYICONDATA, 'Tip', "Hello World "&$n)

But that does not work. Do I have to set also the CallBackMessage? (how?) How does NIF_TIP is related to this?

Questions:

1) How do I set the ToolTipText of a tray icon created with the WinAPIx?

2) How to change the text? (NIM_MODIFY? NIF_TIP?)

3) Is there also an example for a callbackfunction eg to create a tray menu item like the TrayCreateItem and how to proceed the callback function calls ? WM_MOUSEDOWN/Click

I read your support post here (and I tried even the Russian autoit forum http://autoit-script.ru/index.php/topic,47.0.html - with no luck). I already understood that I have to "learn" your APIx, because it looks like there are a lot of functions I could get a bonus for my apps. (BTW: Simply for the .CHM file you should get 5 stars !)

As you already know, I'm not much experienced in this kind of area...sorry to bother you again.

Share this post


Link to post
Share on other sites

Just to mentioned:

I solved the thing for myself by taking a close look to WinAPIx and ModernMenu.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0