Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/26/2023 in all areas

  1. BugFix version - 27 Dec 23 Fixed: No default value set for the MaxWidth parameter - took 12 years for someone to notice it! New UDF and new examples below and in zip. I just realised that although I have posted versions of this UDF many times in Help topics, I had never actually posted a "final" version here in Example scripts - better late than never, I suppose! StringSize takes a text string and calculates the size of label required to hold it as well as formatting the string to fit. Now AutoIt will, of course, size a label automatically to fit a text string, but it will not format the string in any way - what you use as the string is what you get in the label. If you do set any label sizes the text will be wrapped, but you can only determine the correct size of the label by trial and error. StringSize will, however, reformat the string to fit in a given width and tell you the required height so that you can read it all - whatever the font type or size - and you do not have to do the formatting beforehand. Here is a simple example to show what I mean (you need the UDF in the same folder for all the examples): And here is an example showing how StringSize can deal with different fonts and text sizes: You can see that the GUI is perfectly sized each time and that the button is always the right size and in the right place. StringSize returns an array which contains the formatted text to display and the size of the label needed to display it. All you need to do is to use the array elements when you create your label. Try changing the values in $aFont and $aSize if you want to try you own favourites - but beware, StringSize will return an error if you make the size so large that it cannot fit a word into the label width. NEW A more complex example showing how formatted and unformatted text can be sized correctly. The width of GUI holding the unformatted text varies randomly in width (the current value is displayed at top right): NEW And a final example showing how you can get your text in the largest possible font to fit in a given space: Finally here is the UDF itself: And all 5 files in zip format: StringSize.zip I hope you find this useful - I certainly do. M23
    1 point
  2. What about following Global Const $HKM_GETHOTKEY = $WM_USER + 2 Global Const $HOTKEYF_SHIFT=0x01;https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-sethotkey .... func onChange() $key=SendMessage($hInput, $HKM_GETHOTKEY) ConsoleWrite("onChange: " & $key & @CRLF) $loword=_WinAPI_LoWord($key) $lobyte=_WinAPI_LoByte($loword) $hibyte=_WinAPI_HiByte($loword) ConsoleWrite("LOBYTE=" & $lobyte & @CRLF) ConsoleWrite("HIBYTE=" & $hibyte & @CRLF) If ($lobyte<>0 And $hibyte=$HOTKEYF_SHIFT) Then ConsoleWrite("hotkey changed" & @CRLF) EndIf EndFunc HKM_GETHOTKEY has valuable information about how to get what keys are pressed. If you need further help feel free to ask.
    1 point
  3. Looks like GetTempPath looks for the %TMP% variable first. If you update %TMP%, the @TempDir macro updates. _PrintTempVars("----------Environment vars at script start----------") EnvSet("Temp", "C:\temp") EnvSet("Tmp", "C:\tmp") _PrintTempVars("----------Environment vars after update----------") Func _PrintTempVars($sTitle = "") $sTempMacro = @TempDir $sTempEnv = EnvGet("Temp") ConsoleWrite($sTitle & @CRLF & "Env:" & $sTempEnv & @CRLF & "@TempDir:" & $sTempMacro & @CRLF & @CRLF) EndFunc or if you delete the %TMP% environment variable, GetTempPath/@TempDir will use %TEMP% EnvSet("Temp", "C:\temp") EnvSet("Tmp")
    1 point
  4. ; NetFirewallPolicy2 COM UDF Library for AutoIt3 ; AutoIt Version : 3.3.14.5 ; Description ...: Windows Firewall Policy2 Interface, Provides access to the firewall policy for Windows Vista+ Including Test Script _NetFw_Get_CurrentProfileTypes Retrieves the currently active firewall profile(s) _NetFw_Get_FirewallEnabled Indicates whether a firewall is enabled locally _NetFw_Put_FirewallEnabled Specifies whether a firewall is enabled locally _NetFw_Get_ExcludedInterfaces Indicates a list of interfaces on which firewall settings are excluded _NetFw_Put_ExcludedInterfaces Specifies a list of interfaces on which firewall settings are excluded _NetFw_Get_BlockAllInboundTraffic Indicates whether the firewall should not allow inbound traffic _NetFw_Put_BlockAllInboundTraffic Specifies whether the firewall should not allow inbound traffic _NetFw_Get_NotificationsDisabled Indicates whether interactive firewall notifications are disabled _NetFw_Put_NotificationsDisabled Specifies whether interactive firewall notifications are disabled _NetFw_Get_UnicastResponsesToMulticastBroadcastDisabled Indicates whether the firewall should not allow unicast responses to multicast and broadcast traffic _NetFw_Put_UnicastResponsesToMulticastBroadcastDisabled Specifies whether the firewall should not allow unicast responses to multicast and broadcast traffic _NetFw_Get_Rules Retrieves the interface to collection of firewall rules _NetFw_Get_ServiceRestriction Retrieves the interface used to access the Windows Service Hardening store _NetFw_EnableRuleGroup Enables or disables a specified group of firewall rules _NetFw_IsRuleGroupEnabled Determines whether a specified group of firewall rules are enabled or disabled for the current profile _NetFw_RestoreLocalFirewallDefaults Restores the local firewall configuration to its default state _NetFw_Get_DefaultInboundAction Indicates the default action for inbound traffic _NetFw_Put_DefaultInboundAction Specifies the default action for inbound traffic _NetFw_Get_DefaultOutboundAction Indicates the default action for outbound traffic _NetFw_Put_DefaultOutboundAction Specifies the default action for outbound traffic _NetFw_Get_IsRuleGroupCurrentlyEnabled Determines whether a specified group of firewall rules are enabled or disabled for the current profile _NetFw_Get_LocalPolicyModifyState Determines if adding or setting a rule or group of rules will take effect in the current firewall profile UDF: Test Script:
    1 point
  5. Something like this? #Include <Array.au3> #Include <FontConstants.au3> #Include <WinAPI.au3> #Include <WindowsConstants.au3> GUICreate('MyGUI', 300, 200) $Label = GUICtrlCreateLabel('Simple Text', 20, 40, 100, 22) GUICtrlSetFont(-1, 12, 700, 2 + 4, 'Tahoma') GUISetState(@SW_SHOW) $aFont = GUICtrlGetFont($Label) _ArrayDisplay($aFont) Do Until GUIGetMsg() = -3 #cs [0] - Size [1] - Weight [2] - Attribute [3] - Name [4] - Quality #ce Func GUICtrlGetFont($CtrlID) Local $hWnd = GUICtrlGetHandle($CtrlID) If Not $hWnd Then Return 0 EndIf Local $Ret, $hDC, $hFont, $tFont Local $aFont = 0 $hDC = _WinAPI_GetDC($hWnd) $hFont = _SendMessage($hWnd, $WM_GETFONT) $tFont = DllStructCreate($tagLOGFONT) $Ret = DllCall('gdi32.dll', 'int', 'GetObjectW', 'ptr', $hFont, 'int', DllStructGetSize($tFont), 'ptr', DllStructGetPtr($tFont)) If (Not @error) And ($Ret[0]) Then Dim $aFont[5] = [0] $aFont[0] = -Round(DllStructGetData($tFont, 'Height') / _WinAPI_GetDeviceCaps($hDC, $LOGPIXELSY) * 72, 1) $aFont[1] = DllStructGetData($tFont, 'Weight') $aFont[2] = BitOR(2 * (DllStructGetData($tFont, 'Italic') <> 0), 4 * (DllStructGetData($tFont, 'Underline') <> 0), 8 * (DllStructGetData($tFont, 'Strikeout') <> 0)) $aFont[3] = DllStructGetData($tFont, 'FaceName') $aFont[4] = DllStructGetData($tFont, 'Quality') EndIf _WinAPI_ReleaseDC($hWnd, $hDC) Return $aFont EndFunc ;==>GUICtrlGetFont
    1 point
×
×
  • Create New...