trayicon keeps disappearing when hovering over with mouse.

Started by white scorpion, April 18, 2005, 07:18:44 PM

Previous topic - Next topic

white scorpion

Hi all,

i'm trying to figure out how to use the trayicon in a program without a GUI. I want the trayicon to stay put even when you hover over it with the mouse while now it is disappearing :(
does anyone know of an easy solution so that i don't have to write the complete framework for a GUI ?

here's the code i have so far:


.586
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\shell32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\shell32.lib

IconName        EQU 1000

.DATA
AppName     db "TrayIcon example.",0
nope        db "Not added.",0
yep         db "Tray icon has been added successfully.",0
.DATA?

hInstance DWORD ?
hIcon     DWORD ?
nfdat NOTIFYICONDATA <>

.CODE
start:

invoke GetModuleHandle,NULL
mov hInstance,eax

invoke LoadIcon,hInstance,IconName
mov hIcon,eax

mov nfdat.cbSize,sizeof NOTIFYICONDATA
push hInstance
pop nfdat.hwnd

mov nfdat.uID,0
push hIcon
pop nfdat.hIcon
mov nfdat.uFlags,NIF_ICON

invoke Shell_NotifyIcon,NIM_ADD,addr nfdat
.IF eax!=TRUE
    invoke MessageBox,NULL,addr nope,addr AppName,MB_ICONERROR
    invoke CloseHandle,hInstance
    invoke CloseHandle,hIcon
    invoke ExitProcess,1
.ENDIF
invoke MessageBox,NULL,addr yep,addr AppName,MB_OK
invoke Shell_NotifyIcon,NIM_DELETE,addr nfdat
invoke CloseHandle,hInstance
invoke CloseHandle,hIcon       
invoke ExitProcess,0

end start


here's the rc file:

#include "\masm32\include\resource.h"


#define IconName                                  1000

IconName ICON   "wscorpion.ico"


and of course an icon of a white scorpion on a black background, but that doesn't really matter i think  :toothy

Many Thanks in advance!

pbrennick

In the taskbar properties there is a checkbox that causes inactive icons to be hidden.  Just uncheck it.

Paul

Tedd

I tend to just create a basic window, but never show it - so you don't need to handle many messages.
No snowflake in an avalanche feels responsible.

pbrennick

white scorpion,
That is a pretty neat trick, I assembled your program and tested it because I thought I was missing the point and as it turns out, I was.  Anyway the NIM_DELETE flag will tell the icon to delete itself once it gets focus.  Very funny!

Paul

white scorpion

let me be more specific. i don't mean the icon disappears by "unused icons", and i'm also positive it doens't disappear by using the NIM_DELETE flag (yeah it does, but only when you have pressed ok on the messagebox), but the problem is that when you hover over with the mouse it just vanishes, i've tried figuring out using iczelion's tutorial (part 23) since his example doesn't have the same problem, but i can't :(

try running the program, keep the messagebox untouched and then touch the trayicon with your mouse, you will see what i mean..

Thanks anyway for the responses...

pbrennick

Well, now it has become a mission because I do not know why it is happening.  It has to be something being triggered by the mouseover event.  Pretty cool, dude!!

Paul

thomasantony

Hi white scorpion,
    I compiled your code. The program works Ok in win98SE. The trayicon appears and after I click Ok in the messagebox, it disappears. Its gotta be something with your local settings. I suppose you use winxp

Thomas :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

pbrennick

Thomas,
Run the program, don't touch the message box, move the mouse arrow over the icon without clicking.  Does the icon disappear?

Paul

pbrennick

I just tested it on Windows ME and the icon will disappear there, also.

Paul

thomasantony

Nop.
     The icon is still there and I didn't bring the mouse even remotely near the messagebox. I hovered the mouse over the icon and even clicked it. It stayed there. I have a screenshot. I had placed the pointer on the icon but it didn't appear in the screenshot. The icon is there. I have marked it.

Thomas

[attachment deleted by admin]
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free


Gustav


It's just a guess, but you are using hInstance as a HWND. Isn't this a bug? When the mouse is over the icon, the shell wants to send you a message and this may fail, so the shell deletes the icon.

MichaelW

The icon disappears on mouse over under Windows 2000. Changing nfdat.hwnd to zero did not change the behavior. Substituting NIM_SETFOCUS for NIM_DELETE did not change the behavior. Substituting NIM_MODIFY for NIM_DELETE did not change the behavior. I ran out of time trying to use an NIM_SETVERSION message to specify pre-version 5.0 behavior because the MASM32 NOTIFYICONDATAA structure does not include the required members.

eschew obfuscation

pbrennick

Hi Michael,
It would appear that White Scorpion has stumbled upon a very interesting problem.  I, also tried diffent f values without any different resulta.

Paul

thomasantony

Hi Paul,
   Did you try running it in Ollydbg or something. You can see if something is going on while you put the mouse over the icon.

Thomas :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free