Guest Posted June 27, 2015 Posted June 27, 2015 (edited) 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. Edited June 27, 2015 by Guest
nickston Posted July 31, 2015 Posted July 31, 2015 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.For what, you need that size? Get more info.
KaFu Posted August 1, 2015 Posted August 1, 2015 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."). OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
lgvlgv Posted June 21, 2016 Posted June 21, 2016 (edited) 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 June 21, 2016 by lgvlgv
nickston Posted June 22, 2016 Posted June 22, 2016 Why do you think what problem in _TrayIconSetToolTip
LarsJ Posted June 22, 2016 Posted June 22, 2016 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()? Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
lgvlgv Posted June 22, 2016 Posted June 22, 2016 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?
lgvlgv Posted June 22, 2016 Posted June 22, 2016 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
nickston Posted June 22, 2016 Posted June 22, 2016 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() .
Bilgus Posted June 22, 2016 Posted June 22, 2016 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
lgvlgv Posted June 22, 2016 Posted June 22, 2016 Thx, i tryed with same as Ballon, and it hasen hang yet? "WCHAR[256]" WCHAR[128] made it run out of Control again...
lgvlgv Posted June 22, 2016 Posted June 22, 2016 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.
lgvlgv Posted June 22, 2016 Posted June 22, 2016 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
Bilgus Posted June 22, 2016 Posted June 22, 2016 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
Bilgus Posted June 22, 2016 Posted June 22, 2016 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
lgvlgv Posted June 22, 2016 Posted June 22, 2016 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.
lgvlgv Posted June 22, 2016 Posted June 22, 2016 (edited) 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 June 22, 2016 by lgvlgv
Bilgus Posted June 22, 2016 Posted June 22, 2016 all of those are less than 127, so was this without the problem or did the hang still happen?
lgvlgv Posted June 22, 2016 Posted June 22, 2016 (edited) 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 June 22, 2016 by lgvlgv
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now