News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

traymenu not visible after reload

Started by TouEnMasm, December 16, 2015, 01:06:17 AM

Previous topic - Next topic

TouEnMasm

Hello,
This one show a menu on the taskbar with an icon and a tooltip.
He works one time,but don't want to be visible the second time i reload it,any idea ?
Intel(R) Core(TM) i3-4150 CPU @ 3.50GHz
Microsoft Windows 10 Famille Version: 10.0.10586

Fa is a musical note to play with CL

jj2007

No source, the usual crappy error messages instead. Can't help you, Yves :P

fearless

Prob need to see some code to help figure out the issue. Specifically NOTIFYICONDATA data and Shell_NotifyIcon calls and how menu, tooltip and icons are handled for the tray menu

TouEnMasm

Here it is
I try two versions,same thing.
I need to use the task manager to end the prog when it is invisible.If ended like a child process
it"s not possible to view it new.



;===============================================================================================
Principal PROC hInst:dword

LOCAL WindowClass : WNDCLASSEX
LOCAL Msg         : MSG
LOCAL hWindow     : HWND
ZEROLOCALES hWindow

mov    WindowClass.cbSize, SIZEOF WNDCLASSEX
mov    WindowClass.style, CS_HREDRAW or CS_VREDRAW or CS_DBLCLKS
mov    WindowClass.lpfnWndProc, OFFSET WindowProc
mov    WindowClass.cbClsExtra, NULL
mov    WindowClass.cbWndExtra, NULL

push   hInst
pop    WindowClass.hInstance

mov    WindowClass.hbrBackground, COLOR_APPWORKSPACE + 1
mov    WindowClass.lpszMenuName, NULL
mov    WindowClass.lpszClassName, OFFSET ClassName


;Programm-Symbol: PEACE
invoke LoadIcon, hInstance, ProgIcon
mov    WindowClass.hIcon, eax
mov    WindowClass.hIconSm, eax

invoke LoadCursor, hInstance, IDC_ARROW
mov    WindowClass.hCursor, eax

invoke RegisterClassEx, ADDR WindowClass

invoke CreateWindowEx, NULL, ADDR ClassName, ADDR ProgrammName,\
NULL,\        ; 0=nicht sichtbar, daher müssen auch keine anderen Angaben gemacht werden! WS_OVERLAPPED+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX+WS_MAXIMIZEBOX+WS_VISIBLE,\
CW_USEDEFAULT, CW_USEDEFAULT, 100, 100, NULL, NULL,\
hInst, NULL
mov    hWindow, eax

@@:
invoke GetMessage, ADDR Msg, NULL, 0, 0
.if eax == 1
invoke TranslateMessage, ADDR Msg
invoke DispatchMessage, ADDR Msg
jmp @B
.endif

mov    eax, Msg.wParam
ret

Principal ENDP
;===============================================================================================
; WindowProc
;===============================================================================================
WindowProc PROC uses esi edi ebx hWindow:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

LOCAL pt           : POINT
LOCAL StartInfo    : STARTUPINFO,retour:dword,NumLigne
ZEROLOCALES NumLigne

.if uMsg == WM_CREATE
invoke CreatePopupMenu
mov    hPopupMenu, eax
.if MenuTxt.Tache == 3
;-----------
mov NumLigne,0
NewLine:
mov eax,MenuTxt.NBlignesODOA
add eax,MenuTxt.NBlignes
.if eax > NumLigne
inc NumLigne
Push NumLigne
Pop MenuTxt.NumeroLigne
invoke ScrutationFichierTexte,addr MenuTxt
;passer espace tab
@@:
.if byte ptr [esi] == " " || byte ptr [esi] == 9
inc esi
jmp @B
.endif
.if byte ptr [esi] == 0 || byte ptr [esi] == ";"
jmp NewLine
.endif
;cherche ,
@@:
.if byte ptr [esi] != "," && byte ptr [esi] != 0
inc esi
jmp @B
.endif
.If byte ptr [esi] == 0 ;pas de virgule
jmp NewLine
.endif
mov byte ptr [esi],0 ;deux chaines zero,texte menu 0,chemin 00
invoke ScrutationFichierTexte,addr MenuTxt ;rappel pointeur esi
invoke AppendMenu, hPopupMenu, MF_STRING,FreeIDM,esi
inc FreeIDM ;pour le suivant
jmp NewLine
.endif
.endif

invoke AppendMenu, hPopupMenu, MF_SEPARATOR, NULL, NULL
invoke AppendMenu, hPopupMenu, MF_STRING, IDM_HelpMenu , ADDR HelpText
invoke AppendMenu, hPopupMenu, MF_STRING, IDM_Info  , ADDR InfoText
invoke AppendMenu, hPopupMenu, MF_STRING, IDM_Ende  , ADDR EndeText



;Programm in den Tray verlegen

mov    NotifIcon.cbSize, SIZEOF NOTIFYICONDATA
push   hWindow
pop    NotifIcon.hWnd
mov    NotifIcon.uID, IDI_TRAY_ICON
mov    NotifIcon.uFlags, NIF_ICON+NIF_MESSAGE+NIF_TIP+NIF_STATE
mov    NotifIcon.uCallbackMessage, WM_SHELLNOTIFY
invoke LoadIcon, hInstance, ProgIcon                          ;Programm-Symbol
mov    NotifIcon.hIcon, eax
mov   NotifIcon.dwState,0 ;visible
mov NotifIcon.uVersion,NOTIFYICON_VERSION_4
invoke lstrcpy, ADDR NotifIcon.szTip, ADDR ProgrammName

;ajoute un menu dans la barre
invoke Shell_NotifyIcon, NIM_ADD, ADDR NotifIcon
.if eax == FALSE
invoke MessageBox, NULL,TXT("Shell_NotifyIcon failed"), ADDR ProgrammName, MB_YESNO or MB_ICONINFORMATION
.endif
invoke Shell_NotifyIcon,NIM_SETVERSION, ADDR NotifIcon

;invoke Shell_NotifyIcon,NIM_MODIFY, ADDR NotifIcon
;invoke Shell_NotifyIcon,NIM_SETFOCUS, ADDR NotifIcon

.elseif uMsg==WM_COMMAND
;HIWORD wParam,edx ;évènements des contrôles edx
;LOWORD wParam,eax ;IDentificateurs de  commandes eax
;mov ebx,lParam ; handle du controle

;suite


.if lParam==0
mov    eax, wParam
and   eax,0ffffh
.if eax >= StartFreeIDM && eax <= StartFreeIDM + 100
;chercher le chemin d'éxécution
invoke TrieurMenu,eax

.elseif eax==IDM_Ende
;mov    DeletIcon.cbSize, SIZEOF NOTIFYICONDATA
;push   hWindow
;pop    DeletIcon.hWnd
;mov    DeletIcon.uID, IDI_TRAY_ICON
invoke Shell_NotifyIcon, NIM_DELETE,addr NotifIcon ;Tray-Icon löschen
mov MenuTxt.Tache,4
invoke ScrutationFichierTexte,addr MenuTxt
invoke PostMessage,hWindow,WM_CLOSE,0,0
.elseif eax==IDM_Info

cmp    StatusInfo, 1
jz     Raus
inc    StatusInfo
invoke LoadIcon, NULL, IDI_INFORMATION
mov    NotifIcon.hIcon, eax
invoke Shell_NotifyIcon, NIM_MODIFY, ADDR NotifIcon
invoke LoadIcon, hInstance, ProgIcon
invoke ShellAbout, NULL,ADDR InfoBoxTitel, ADDR InfoBoxText, eax
dec    StatusInfo
invoke LoadIcon, hInstance, ProgIcon                          ;Programm-Symbol
mov    NotifIcon.hIcon, eax
invoke Shell_NotifyIcon, NIM_MODIFY, ADDR NotifIcon

Raus:

.elseif eax == IDM_HelpMenu
;afficher la messagebox
invoke MessageBox,NULL,addr menupath,ADDR Helpexplain,MB_OK

.endif

.endif
.elseif uMsg==WM_SHELLNOTIFY
;NOTIFYICON_VERSION_4
;LOWORD(lParam) contains notification events, such as NIN_BALLOONSHOW, NIN_POPUPOPEN, or WM_CONTEXTMENU.
;• HIWORD(lParam) contains the icon ID. Icon IDs are restricted to a length of 16 bits.
;• GET_X_LPARAM(wParam) returns the X anchor coordinate for notification events NIN_POPUPOPEN, NIN_SELECT, NIN_KEYSELECT, and all mouse messages between WM_MOUSEFIRST and WM_MOUSELAST. If any of those messages are generated by the keyboard, wParam is set to the upper-left corner of the target icon. For all other messages, wParam is undefined.
;• GET_Y_LPARAM(wParam) returns the Y anchor coordinate for notification events and messages as defined for the X anchor
;invoke MessageBox,NULL,TXT("WM_SHELLNOTIFY"),TXT("WM_SHELLNOTIFY"),MB_OK
mov eax,lParam
shr eax,16
;.if wParam==IDI_TRAY_ICON old version
.if eax == IDI_TRAY_ICON
;invoke MessageBox,NULL,TXT("IDI_TRAY_ICON"),TXT("WM_SHELLNOTIFY"),MB_OK
;.if (lParam==WM_LBUTTONDOWN) || (lParam==WM_RBUTTONDOWN)       ;old version
mov eax,lParam
and eax,0FFFFh
.if eax==WM_LBUTTONDOWN || eax ==WM_RBUTTONDOWN
invoke GetCursorPos, ADDR pt
invoke TrackPopupMenu, hPopupMenu, TPM_LEFTALIGN, pt.x, pt.y, NULL, hWindow, NULL
.endif
.endif
.elseif uMsg==WM_CLOSE
invoke DestroyMenu,hPopupMenu
invoke DestroyWindow,hWindow
.elseif uMsg==WM_DESTROY
;invoke MessageBox,NULL,TXT("destroy"),ADDR Helpexplain,MB_OK
invoke PostQuitMessage, NULL
.else
invoke DefWindowProc, hWindow, uMsg, wParam, lParam
mov retour,eax
.endif
mov eax,retour
ret

WindowProc ENDP

Fa is a musical note to play with CL

TouEnMasm


Found,the trayicon is sometimes in the taskbar (visible) and sometimes in the hidden icones,need to open
the hidden icône window.
How to made it appear allways in the taskbar or allways in the hidden icones?
Fa is a musical note to play with CL

fearless

From what i gather, it is an os designed feature that user can turn on/off notication icons being visible. On win7 it is located at Control Panel\All Control Panel Items\Notification Area Icons. Ive mine set to "show all icons and notifications on the taskbar", but its possible a user can have some of them hidden, and some visible. Dont know if there is an option to force it to be visible, unless there is an option in NOTIFYICONDATA somewhere. I imagine a balloon popup alert/message will show automatically the icon (and balloon alert) and then hide it again after, if its set by user to be hidden.

Code seems fine, the example works on win7, icon changes to info when choosing info option on traymenu and back to wrench/spanner otherwise.

TouEnMasm

https://msdn.microsoft.com/en-us/library/windows/desktop/cc144179(v=vs.85).aspx#tbnotify_Taskbar_Display_Options

add WS_EX_APPWINDOW and the icon is never in the hidden part of the taskbar
Fa is a musical note to play with CL

fearless

Thanks, thats useful to know. Might add it into one of my projects that has a traymenu and icons for showing cpu temp, hdd temp on my qnap nas, that way user wont have to go into the settings to unhide them.