Jump to content

GUI/Tray Menu with icons and colors


Holger
 Share

Recommended Posts

Hi,

For a long time I am looking for a way to get the height and width of Menu.
I found that the size is not the same in all cases. for example when the DPI settings are unusual. so it there is a need to find a way to get the information in some way.. 

I have an idea how to calculate the new size based on the DPI settings but I don't like this and I sow that It may not work properly....
I hope there is a better way - a direct way to get this information. If so then I would love to receive a code that return this information.

 

Thank you.

Screenshot_6.png

Edited by Guest
Link to comment
Share on other sites

  • 1 month later...

Hi,

For a long time I am looking for a way to get the height and width of Menu.
I found that the size is not the same in all cases. for example when the DPI settings are unusual. so it there is a need to find a way to get the information in some way.. 

I have an idea how to calculate the new size based on the DPI settings but I don't like this and I sow that It may not work properly....
I hope there is a better way - a direct way to get this information. If so then I would love to receive a code that return this information.

 

Thank you.

Screenshot_6.png

For what, you need that size? Get more info.

Link to comment
Share on other sites

Take a look at how the WM_MEASUREITEM ("Sent to the owner window of a combo box, list box, list-view control, or menu item when the control or menu is created.") message is processed in this UDF. There you can get the default values set by the system for the width and height of the menu items and change them ("If an application processes this message, it should return TRUE.").

Link to comment
Share on other sites

  • 10 months later...

Hi all!

I notice a bug or maybe im doing something wrong, but if i use  "_TrayIconSetToolTip()"

it buggs out after a while and the program starts to take 25% CPU and becomes unrespnosive?

Or im i updateing the tooltip wrong?

cant find any error when running in debugmode, some times the script runns for hours Before it happens..

Can anyone help?

 

(have only tryed under Windows 10)

 

Local $conn = _IsInternetConnectedEx()
                If $conn = "1" Then
                    _TrayIconSetIcon($nTrayIcon1, @ScriptFullPath, -1)
                    _TrayIconSetToolTip($nTrayIcon1, "Datornamn: " & @ComputerName & @CRLF & "IPAdress: " & @IPAddress1 & " ," & @IPAddress2 & @CRLF & "Gateway: " & _GetGatewayIP())
;                   _TrayIconSetState($nTrayIcon1, 1)
                Else
                    _TrayIconSetIcon($nTrayIcon1, @ScriptFullPath, -5)
                    _TrayIconSetToolTip($nTrayIcon1, "Datornamn: " & @ComputerName & @CRLF & "IPAdress: " & @IPAddress1 & " ," & @IPAddress2 & @CRLF & "Gateway: " & _GetGatewayIP( & @CRLF & " Internet error: , Other errors")
;                   _TrayIconSetState($nTrayIcon1, 1)
                EndIf
            EndIf

 

Edited by lgvlgv
Link to comment
Share on other sites

lgvlgv, I have the same question as nickston:

Are you sure that the problems are related to this UDF, and not to functions _IsInternetConnectedEx() or _GetGatewayIP()?

Link to comment
Share on other sites

Im sure it has to be "_TrayIconSetToolTip()" if i remark it the script never stop.
if i only change the Icon and "traytip" it runs for ever..but its really  TrayIconSetToolTip im after :)
as soon as i add (_TrayIconSetToolTip) the script runs for a few min to an hour, then goes 20% CPU and becomes unresponsive?

 

Link to comment
Share on other sites

Think it Changes the iconset tooltip "value" wrong som how, it works some/a few times then hangs program, but the function is over my head..

Global $sNOTIFYICONDATAW    = "dword;" & _      ; Struct size
           "hwnd;" & _       ; Callback window handle
           "uint;" & _       ; Icon ID
           "uint;" & _       ; Flags
           "uint;" & _       ; Callback message ID
           "hwnd;" & _       ; Icon handle
           "wchar[128];" & _ ; ToolTip text
           "dword;" & _      ; Icon state
           "dword;" & _      ; Icon state mask
           "wchar[256];" & _ ; Balloon ToolTip text
           "uint;" & _       ; Timeout / Version -> NIM_SETVERSION values 0, 3, 4
           "wchar[64];" & _  ; Balloon ToolTip title text
           "dword"           ; Balloon ToolTip info flags
 

 


;**********************************************************************
; _TrayIconSetToolTip($NotificationID, $sToolTip)
;**********************************************************************
Func _TrayIconSetToolTip($nID = -1, $sToolTip = $sDefaultTT)
 If $nID = -1 Then $nID = $TRAYLASTID
 If $TRAYMSGWND = 0 Or $nID <= 0 Then Return 0

 Local $stNID = DllStructCreate($sNOTIFYICONDATAW)
 DllStructSetData($stNID, 1, DllStructGetSize($stNID))
 DllStructSetData($stNID, 2, $TRAYMSGWND)
 DllStructSetData($stNID, 3, $nID)
 DllStructSetData($stNID, 4, $NIF_TIP)
 DllStructSetData($stNID, 7, $sToolTip)

 Return Shell_NotifyIcon($NIM_MODIFY, DllStructGetPtr($stNID))
EndFunc

Link to comment
Share on other sites

look here:

_TrayIconSetToolTip($nTrayIcon1, "Datornamn: " & @ComputerName & @CRLF & "IPAdress: " & @IPAddress1 & " ," & @IPAddress2 & @CRLF & "Gateway: " & _GetGatewayIP())

remove

_GetGatewayIP()

from last parameter. Make new var, for ex $GetwayIP, and set it's by

_GetGatewayIP()

then add That var to set tooltip.

Try that, And try to comment

_GetGatewayIP()

.

Link to comment
Share on other sites

59 minutes ago, lgvlgv said:

maybe wchar need to be bigger? i have no idea? :)

you know there is a msdn page outlining the data structure

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

I wonder if something has been depreciated in W10 with backwards compability with Win2000 are you tring to send a  $sToolTip  longer than 63 or baloontip longer than 255 characters?

perhaps try the Version 4 structure?

Replace the original define with this:        

Global $sNOTIFYICONDATAW    = "dword;" & _      ; Struct size
           "hwnd;" & _       ; Callback window handle
           "uint;" & _       ; Icon ID
           "uint;" & _       ; Flags
           "uint;" & _       ; Callback message ID
           "hwnd;" & _       ; Icon handle
           "WCHAR[64];" & _ ; ToolTip text
           "dword;" & _      ; Icon state
           "dword;" & _      ; Icon state mask
           "WCHAR[256];" & _ ; Balloon ToolTip text
           "uint;" & _       ; Timeout / Version -> NIM_SETVERSION values 0, 3, 4
           "WCHAR[64];" & _  ; Balloon ToolTip title text
           "dword"           ; Balloon ToolTip info flags
           if @OSVersion = "WIN_10" THEN $sNOTIFYICONDATAW &= ";BYTE[128];" & _  ; Guid
                                                          "hwnd"           ; Balloon ToolTip IconHandle

 

Link to comment
Share on other sites

im trying what u say now and so far its good :)

i notice that Before it cut of the last " ms."  in the tip.

      _TrayIconSetToolTip($nTrayIcon1, @ComputerName & @CRLF & "IP: " & @IPAddress1 & @CRLF & "Gateway: " & _GetGatewayIP() & @CRLF & " Internet: " & $iPing & " Ms.")
 

The longest tip in my script is ..

      _TrayIconSetToolTip($nTrayIcon1, @ComputerName & @CRLF & "IPAdress: " & @IPAddress1 & "Gate: " & _GetGatewayIP() & @CRLF & " Internet error: " & @error & ", Host is unreachable.")
 

where @computername of course can change in size.

 

 

Link to comment
Share on other sites

4 hours ago, nickston said:

Why do you think what problem in 

_TrayIconSetToolTip

 

2 hours ago, Bilgus said:

you know there is a msdn page outlining the data structure

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

I wonder if something has been depreciated in W10 with backwards compability with Win2000 are you tring to send a  $sToolTip  longer than 63 or baloontip longer than 255 characters?

perhaps try the Version 4 structure?

Replace the original define with this:        

Global $sNOTIFYICONDATAW    = "dword;" & _      ; Struct size
           "hwnd;" & _       ; Callback window handle
           "uint;" & _       ; Icon ID
           "uint;" & _       ; Flags
           "uint;" & _       ; Callback message ID
           "hwnd;" & _       ; Icon handle
           "WCHAR[64];" & _ ; ToolTip text
           "dword;" & _      ; Icon state
           "dword;" & _      ; Icon state mask
           "WCHAR[256];" & _ ; Balloon ToolTip text
           "uint;" & _       ; Timeout / Version -> NIM_SETVERSION values 0, 3, 4
           "WCHAR[64];" & _  ; Balloon ToolTip title text
           "dword"           ; Balloon ToolTip info flags
           if @OSVersion = "WIN_10" THEN $sNOTIFYICONDATAW &= ";BYTE[128];" & _  ; Guid
                                                          "hwnd"           ; Balloon ToolTip IconHandle

 

Thank u all, ur super, all seems running nice now without errors :)

 

Link to comment
Share on other sites

sorry I think that 

"WCHAR[64];" & _ ; ToolTip text

is supposed to be 

"WCHAR[128];" & _ ; ToolTip text

for Win2000 and later 

 

;Below is a C Type Struct not autoit btw...
typedef struct _NOTIFYICONDATAW {
  DWORD cbSize;
  HWND hWnd;
  UINT uID;
  UINT uFlags;
  UINT uCallbackMessage;
  HICON hIcon;
#if _WIN32_IE >= 0x0500
  WCHAR szTip[128];
  DWORD dwState;
  DWORD dwStateMask;
  WCHAR szInfo[256];
  _ANONYMOUS_UNION union {
    UINT uTimeout;
    UINT uVersion;
  } DUMMYUNIONNAME;
  WCHAR szInfoTitle[64];
  DWORD dwInfoFlags;
#else
  WCHAR szTip[64];
#endif
#if _WIN32_IE >= 0x600
  GUID guidItem;
#endif
#if _WIN32_WINNT >= 0x600
  HICON hBalloonIcon;
#endif
} NOTIFYICONDATAW,*PNOTIFYICONDATAW;

So you are saying you changed 

"WCHAR[64];" & _ ; ToolTip text

to "WCHAR[256] and it works properly?

I was under the assumption DllStructSetData() won't cause a buffer overflow and after some testing I'm confident that is the case but I did notice MSDN states:

 

szTip

Type: TCHAR[64]

A null-terminated string that specifies the text for a standard tooltip. It can have a maximum of 64 characters, including the terminating null character.

For Windows 2000 and later, szTip can have a maximum of 128 characters, including the terminating null character.

can you try adding some code to limit tooltip size to 127 Wchars and add a Null to the end of the string?

Global $sNOTIFYICONDATAW    = "dword;" & _      ; Struct size
           "hwnd;" & _       ; Callback window handle
           "uint;" & _       ; Icon ID
           "uint;" & _       ; Flags
           "uint;" & _       ; Callback message ID
           "hwnd;" & _       ; Icon handle
           "wchar[128];" & _ ; ToolTip text
           "dword;" & _      ; Icon state
           "dword;" & _      ; Icon state mask
           "wchar[256];" & _ ; Balloon ToolTip text
           "uint;" & _       ; Timeout / Version -> NIM_SETVERSION values 0, 3, 4
           "wchar[64];" & _  ; Balloon ToolTip title text
           "dword"           ; Balloon ToolTip info flags


;**********************************************************************
; _TrayIconSetToolTip($NotificationID, $sToolTip)
;**********************************************************************
Func _TrayIconSetToolTip($nID = -1, $sToolTip = $sDefaultTT)
 If $nID = -1 Then $nID = $TRAYLASTID
 If $TRAYMSGWND = 0 Or $nID <= 0 Then Return 0

 Local $stNID = DllStructCreate($sNOTIFYICONDATAW)
 DllStructSetData($stNID, 1, DllStructGetSize($stNID))
 DllStructSetData($stNID, 2, $TRAYMSGWND)
 DllStructSetData($stNID, 3, $nID)
 DllStructSetData($stNID, 4, $NIF_TIP)
 DllStructSetData($stNID, 7, StringLeft($sToolTip,127) & CHRW(0))
 Return Shell_NotifyIcon($NIM_MODIFY, DllStructGetPtr($stNID))
EndFunc

 

Link to comment
Share on other sites

You could probably get away with 

DllStructSetData($stNID, 7, StringLeft($sToolTip,127))

as that last character would automatically be a null (0) (though I like being explicit..).

In the same vein if a tooltip was anything less it too would have a null termination as well since I think the Element is initialized with 128 Nulls(0).

So I think it is an inadvertent buffer overflow you are dealing with..

maybe also put ConsoleWrite(stringlen($sToolTip)) in the function and see if any of them >127 while it runs for good measure

Link to comment
Share on other sites

12 minutes ago, Bilgus said:

You could probably get away with 

DllStructSetData($stNID, 7, StringLeft($sToolTip,127))

as that last character would automatically be a null (0) (though I like being explicit..).

In the same vein if a tooltip was anything less it too would have a null termination as well since I think the Element is initialized with 128 Nulls(0).

So I think it is an inadvertent buffer overflow you are dealing with..

maybe also put ConsoleWrite(stringlen($sToolTip)) in the function and see if any of them >127 while it runs for good measure

Im trying this now, tho other run for an hour and i thought problem soved :)

like u say must be a "buffer overflow"

i let u know if it fails, thx all for the help.

Link to comment
Share on other sites

the stringlen report in the diffrent senarios i have

Nolink: 57

Error1: 74
Error2: 78
Error3: 73
Error4: 57
Good: 61

My computername is Spel2, but it could be i think 15 characters long in windows.

Edited by lgvlgv
Link to comment
Share on other sites

2 hours ago, Bilgus said:

all of those are less than 127, so was this without the problem or did the hang still happen?

 

Still hangs after a while, i put it now for fun to 63 on laptop computer, still hole tooltip is showing? and all look ok?

i got 2 computer one laptop(surface) on WiFi and a WS on cable.

The WS on cable still goes strong with 127, the laptop hang and is now put on 63 just for fun..

The Laptop only lasted a few min and is back on 127 :)

ops: now the WS also died last tip "62"

 

 


 

Edited by lgvlgv
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...