Jump to content

Recommended Posts

Posted (edited)

In this thread it was discussed about fading out a label from dark to white.  So I suggested to use an ownerdraw label to perform such a task.  After a bit of searching, I did not find good example, on this forum, of doing it with a label.  So there you go :

; From Nine
#include <WinAPIDiag.au3>
#include <GDIPlus.au3>
#include <GUIConstants.au3>

; Blend - Fade - Text - OWNERDRAW - label

Opt("MustDeclareVars", True)

Global Const $tagDRAWITEMSTRUCT = "uint CtlType;uint CtlID;uint itemID;uint itemAction;uint itemState;hwnd hwndItem;hwnd hDC;" & $tagRECT & ";ulong_ptr itemData;"
Global Const $SS_OWNERDRAW = 0x0D

Example()

Func Example()
  _GDIPlus_Startup()

  Local $hGUI = GUICreate("Example", 400, 200, -1, -1, $WS_OVERLAPPEDWINDOW)
  GUISetBkColor(0xFFFF00)
  Local $idLabel = GUICtrlCreateLabel("", 75, 20, 250, 40, $SS_OWNERDRAW)

  GUIRegisterMsg($WM_DRAWITEM, WM_DRAWITEM)

  GUISetState()

  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
      Case $idLabel
        ConsoleWrite("Label was clicked" & @CRLF)
    EndSwitch
  WEnd

  _GDIPlus_Shutdown()
EndFunc   ;==>Example

Func WM_DRAWITEM($hWnd, $iMsg, $wParam, $lParam)
  Local $tData = DllStructCreate($tagDRAWITEMSTRUCT, $lParam)

  Local $hGraphic = _GDIPlus_GraphicsCreateFromHDC($tData.hdc)
  Local $hBrush = _GDIPlus_LineBrushCreate(0, 20, $tData.right, 20, 0xFF606060, 0xFFFFFFFF)

  Local $hFormat = _GDIPlus_StringFormatCreate()
  _GDIPlus_StringFormatSetAlign($hFormat, 1)
  Local $hFamily = _GDIPlus_FontFamilyCreate("Arial")
  Local $hFont = _GDIPlus_FontCreate($hFamily, 28, 2)
  Local $tLayout = _GDIPlus_RectFCreate(0, Int(($tData.bottom - 40) / 2), $tData.right, 40)
  Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, "AutoIt Rulez !", $hFont, $tLayout, $hFormat)
  _GDIPlus_GraphicsClear($hGraphic, 0xFFFF0000)
  _GDIPlus_GraphicsDrawStringEx($hGraphic, "AutoIt Rulez !", $hFont, $aInfo[0], $hFormat, $hBrush)

  _GDIPlus_StringFormatDispose($hFormat)
  _GDIPlus_FontFamilyDispose($hFamily)
  _GDIPlus_FontDispose($hFont)
  _GDIPlus_BrushDispose($hBrush)
  _GDIPlus_GraphicsDispose($hGraphic)

  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DRAWITEM

 

Edited by Nine
  • 2 weeks later...
Posted

here is a native solution to get the Windows Installed Key,   (from a VBS translation)

Spoiler
Option Explicit
Dim objshell,path,DigitalID, Result
Set objshell = CreateObject("WScript.Shell")
'Set registry key path
Path = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
'Registry key value
DigitalID = objshell.RegRead(Path & "DigitalProductId")
Dim ProductName,ProductID,ProductKey,ProductData
'Get ProductName, ProductID, ProductKey
ProductName = "Product Name: " & objshell.RegRead(Path & "ProductName")
ProductID = "Product ID: " & objshell.RegRead(Path & "ProductID")
ProductKey = "Installed Key: " & ConvertToKey(DigitalID)
ProductData = ProductName & vbNewLine & ProductID & vbNewLine & ProductKey
'Show messbox if save to a file
If vbYes = MsgBox(ProductData & vblf & vblf & "Save to a file?", vbYesNo + vbQuestion, "BackUp Windows Key Information") then
Save ProductData
End If
'Convert binary to chars
Function ConvertToKey(Key)
Const KeyOffset = 52
Dim isWin8, Maps, i, j, Current, KeyOutput, Last, keypart1, insert
'Check if OS is Windows 8
isWin8 = (Key(66) \ 6) And 1
Key(66) = (Key(66) And &HF7) Or ((isWin8 And 2) * 4)
i = 24
Maps = "BCDFGHJKMPQRTVWXY2346789"
Do
Current= 0
j = 14
Do
Current = Current* 256
Current = Key(j + KeyOffset) + Current
Key(j + KeyOffset) = (Current \ 24)
Current=Current Mod 24
j = j -1
Loop While j >= 0
i = i -1
KeyOutput = Mid(Maps,Current+ 1, 1) & KeyOutput
Last = Current
Loop While i >= 0

If (isWin8 = 1) Then
keypart1 = Mid(KeyOutput, 2, Last)
insert = "N"
KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
If Last = 0 Then KeyOutput = insert & KeyOutput
End If
ConvertToKey = Mid(KeyOutput, 1, 5) & "-" & Mid(KeyOutput, 6, 5) & "-" & Mid(KeyOutput, 11, 5) & "-" & Mid(KeyOutput, 16, 5) & "-" & Mid(KeyOutput, 21, 5)
End Function
'Save data to a file
Function Save(Data)
Dim fso, fName, txt,objshell,UserName
Set objshell = CreateObject("wscript.shell")
'Get current user name
'UserName = objshell.ExpandEnvironmentStrings("%UserName%")
'Create a text file on desktop
fName = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\WindowsKeyInfo.txt"
'WScript.Echo "fName: " & fName
Set fso = CreateObject("Scripting.FileSystemObject")
Set txt = fso.CreateTextFile(fName)
txt.Writeline Data
txt.Close
End Function

 


Thank to 🏆 argumentum  for helping me get rid of the "WScript.Shell" Object

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Global $info = ShowKeyPlus()
ConsoleWrite($info & @CRLF)

Func ShowKeyPlus()
    Local $sProductName, $sProductID, $sProductKey, $sProductData, $sDigitalID, $aDigitalID

    $sProductName = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName")
    $sProductID = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductId")
    $sDigitalID = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductId")

    Local $n, $sRet = "", $aArray = StringSplit($sDigitalID, "", 0)
    For $n = 4 To $aArray[0] Step 2
        $sRet &= Int("0x" & $aArray[$n - 1] & $aArray[$n]) & ","
    Next
    $aDigitalID = StringSplit(StringTrimRight($sRet, 1), ",", 2)
    If Not IsArray($aDigitalID) Or UBound($aDigitalID) < 164 Then
        MsgBox(16, "Error", "Could not read the DigitalProductId from the registry.")
        Exit
    EndIf

    $sProductKey = ConvertToKey($aDigitalID)

    $sProductData = "Product Name: " & $sProductName & @CRLF & _
                    "Product ID: " & $sProductID & @CRLF & _
                    "Installed Key: " & $sProductKey

    Return $sProductData
EndFunc

Func ConvertToKey($aKeyBytes)
    Local Const $iKeyOffset = 52
    Local Const $sMaps = "BCDFGHJKMPQRTVWXY2346789"
    Local $isWin8, $i, $j, $iCurrent, $sKeyOutput = "", $iLast

    $isWin8 = BitAND(Int($aKeyBytes[66] / 6), 1)
    $aKeyBytes[66] = BitOR(BitAND($aKeyBytes[66], 0xF7), BitShift(BitAND($isWin8, 2), 2))

    For $i = 24 To 0 Step -1
        $iCurrent = 0
        For $j = 14 To 0 Step -1
            $iCurrent = $iCurrent * 256
            $iCurrent = $iCurrent + $aKeyBytes[$j + $iKeyOffset]

            $aKeyBytes[$j + $iKeyOffset] = Floor($iCurrent / 24)
            $iCurrent = Mod($iCurrent, 24)
        Next
        If $i > 0 Then $sKeyOutput = StringMid($sMaps, $iCurrent + 1, 1) & $sKeyOutput
        $iLast = $iCurrent
    Next

    If $isWin8 = 1 Then
        Local $sKeyPart1 = StringMid($sKeyOutput, 1, $iLast)
        Local $sInsert = "N"
        $sKeyOutput = $sKeyPart1 & $sInsert & StringMid($sKeyOutput, $iLast + 1)
    EndIf

    Return StringMid($sKeyOutput, 1, 5) & "-" & _
           StringMid($sKeyOutput, 6, 5) & "-" & _
           StringMid($sKeyOutput, 11, 5) & "-" & _
           StringMid($sKeyOutput, 16, 5) & "-" & _
           StringMid($sKeyOutput, 21, 5)
EndFunc

 

I know that I know nothing

  • 3 weeks later...
Posted (edited)
; moved to the example below

_NowCalc() or _NowCalc(1) returns Local time
_NowCalc(0) returns System time / UTC 

I should push the mod. in all _Now*() for the standard Date.au3 UDF 🤔

Why do I need this ?, ok, I'll tell you.
I wanted a ProcessStartAge() to know if I should kill it because is taking too long. :laser:
So.., I wanted to use System time instead of local for..., just in case. Like this:

Exit ConsoleWrite('--- ProcessStartAge: ' & ProcessStartAge(@AutoItPID) & ' minutes ( will be zero if all works well )'& @CRLF) ; ---- ProcessStartAge: 0 min.
Func ProcessStartAge($sProcessOrPID) ; https://www.autoitscript.com/forum/index.php?showtopic=139260&view=findpost&p=1545875
    Local $sReturn = ProcessStartDate($sProcessOrPID, 0, 0)
    If @error Then Return SetError(@error, @extended, $sReturn)
    Return _DateDiff('n', $sReturn, _NowCalc_Mod(0))
EndFunc   ;==>ProcessStartAge

Func ProcessStartDate($sProcessOrPID, $iRet_tSYSTEMTIME = 0, $iLocalTime = 0)
    Local $aFT, $tFT, $tST, $iID = ProcessExists($sProcessOrPID)
    If $iID Then ; https://www.autoitscript.com/forum/index.php?showtopic=139260&view=findpost&p=1538034
        $aFT = _WinAPI_GetProcessTimes($iID)
        If @error Or UBound($aFT) <> 3 Then Return SetError(@error, _WinAPI_GetLastError(), "GetProcessTimes FAILED")
        $tST = _Date_Time_FileTimeToSystemTime($iLocalTime ? _Date_Time_FileTimeToLocalFileTime($aFT[0]) : $aFT[0])
        If $iRet_tSYSTEMTIME Then Return $tST
        Return _Date_Time_SystemTimeToDateTimeStr($tST, 1)
    EndIf
    Return SetError(11, 0, "Process does not exist")
EndFunc   ;==>ProcessStartDate

Func _NowCalc_Mod($iLocalTime = 1) ; https://www.autoitscript.com/forum/index.php?showtopic=139260&view=findpost&p=1545875
    Local $tLocalTime = ($iLocalTime ? _Date_Time_GetLocalTime() : _Date_Time_GetSystemTime())
    If @error Then Return SetError(@error, @extended, "")
    Return SetError(0, $iLocalTime, $tLocalTime.Year & "/" & StringRight('00' & $tLocalTime.Month, 2) & "/" & StringRight('00' & $tLocalTime.Day, 2) & " " & _
            StringRight('00' & $tLocalTime.Hour, 2) & ":" & StringRight('00' & $tLocalTime.Minute, 2) & ":" & StringRight('00' & $tLocalTime.Second, 2))
EndFunc   ;==>_NowCalc_Mod

...and that's the full story :) 

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • 2 weeks later...
Posted (edited)

This script forces all new and existing tray icons in Windows 11 to always show on the taskbar (instead of being hidden in the overflow). It does this by running a PowerShell command that sets the IsPromoted registry value for every app under HKCU:\Control Panel\NotifyIconSettings to 1, then restarts Explorer so changes take effect.

You must compile this script if you want to run it every reboot.

 

$Startup = @StartupDir & "\" & @ScriptName
    If Not FileExists($Startup) Then
    FileCopy(@ScriptFullPath, $Startup, 1)
EndIf

Run(@ComSpec & " /c powershell -NoProfile -Command ""Get-ChildItem 'HKCU:\Control Panel\NotifyIconSettings' | ForEach-Object { Set-ItemProperty -Path $_.PsPath -Name IsPromoted -Value 1 }""", "", @SW_HIDE)
Edited by FadeSoft
Posted (edited)
Exit ConsoleWrite(@CRLF & '>' & WM_NOTIFY_LEGEND(-2) & '<' & @CRLF & @CRLF) ; >NM_CLICK<
Func WM_NOTIFY_LEGEND($iInt)
    Local Static $aNM_Array[25] = ["NM_FIRST", "NM_OUTOFMEMORY", "NM_CLICK", "NM_DBLCLK", "NM_RETURN", "NM_RCLICK", "NM_RDBLCLK", _
            "NM_SETFOCUS", "NM_KILLFOCUS", "", "", "", "NM_CUSTOMDRAW", "NM_HOVER", "NM_NCHITTEST", "NM_KEYDOWN", _
            "NM_RELEASEDCAPTURE", "NM_SETCURSOR", "NM_CHAR", "NM_TOOLTIPSCREATED", "NM_LDOWN", "NM_RDOWN", "NM_THEMECHANGED", _
            "NM_FONTCHANGED", "NM_CUSTOMTEXT/NM_TVSTATEIMAGECHANGING"]
    ; NM_CUSTOMTEXT uses NMCUSTOMTEXT struct
    ; NM_TVSTATEIMAGECHANGING uses NMTVSTATEIMAGECHANGING struct

    Local Static $aLVN_Array[90] = ["LVN_ITEMCHANGING", "LVN_ITEMCHANGED", "LVN_INSERTITEM", "LVN_DELETEITEM", "LVN_DELETEALLITEMS", _
            "LVN_BEGINLABELEDITA", "LVN_ENDLABELEDITA", "", "LVN_COLUMNCLICK", "LVN_BEGINDRAG", "", "LVN_BEGINRDRAG", "", "LVN_ODCACHEHINT", _
            "LVN_ITEMACTIVATE", "LVN_ODSTATECHANGED", "", "", "", "", "", "LVN_HOTTRACK", "", "", "", "", "", "", "", "", "", "", "", "", _
            "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "LVN_GETDISPINFOA", "LVN_SETDISPINFOA", "LVN_ODFINDITEMA", "", _
            "", "LVN_KEYDOWN", "LVN_MARQUEEBEGIN", "LVN_GETINFOTIPA", "LVN_GETINFOTIPW", "", "", "", "LVN_INCREMENTALSEARCHA", _
            "LVN_INCREMENTALSEARCHW", "LVN_COLUMNDROPDOWN", "", "LVN_COLUMNOVERFLOWCLICK", "", "", "", "", "", "", "", "", _
            "LVN_BEGINLABELEDITW", "LVN_ENDLABELEDITW", "LVN_GETDISPINFOW", "LVN_SETDISPINFOW", "LVN_ODFINDITEMW", "LVN_BEGINSCROLL", _
            "LVN_ENDSCROLL", "", "", "LVN_LINKCLICK", "", "", "LVN_GETEMPTYMARKUP", "", ""]

    Local $iNumber = Int(StringReplace($iInt, "-", ""))
    Switch $iNumber     ; https://chromium.googlesource.com/chromium/deps/perl/+/master/c/i686-w64-mingw32/include/commctrl.h
        Case 0 To 99     ; NM ; #define NM_FIRST (0U- 0U) ; #define NM_LAST (0U- 99U)
            Switch $iNumber
                Case 0 To 24
                    If $aNM_Array[$iNumber] <> "" Then Return $aNM_Array[$iNumber]
            EndSwitch

        Case 100 To 199     ; LVN ; #define LVN_FIRST (0U-100U) ; #define LVN_LAST (0U-199U)
            $iNumber -= 100
            Switch $iNumber
                Case 0 To 88
                    If $aLVN_Array[$iNumber] <> "" Then Return $aLVN_Array[$iNumber]
            EndSwitch

;       Case 200 To 299 ; coded this way you can add more events,
;                                   and if you do, share the code =)

    EndSwitch
    Return "UNCLASSIFIED:" & $iInt
EndFunc   ;==>WM_NOTIFY_LEGEND

The function could be expanded but I use it as a Listview helper while coding.

Edited by argumentum
better

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted
1 hour ago, argumentum said:
Exit ConsoleWrite(@CRLF & WM_NOTIFY_LEGEND(-2) & @CRLF & @CRLF)
Func WM_NOTIFY_LEGEND($iInt)
    Local Static $aNM_Array = ["NM_FIRST", "NM_OUTOFMEMORY", "NM_CLICK", "NM_DBLCLK", "NM_RETURN", "NM_RCLICK", "NM_RDBLCLK", _
            "NM_SETFOCUS", "NM_KILLFOCUS", "", "", "", "NM_CUSTOMDRAW", "NM_HOVER", "NM_NCHITTEST", "NM_KEYDOWN", _
            "NM_RELEASEDCAPTURE", "NM_SETCURSOR", "NM_CHAR", "NM_TOOLTIPSCREATED", "NM_LDOWN", "NM_RDOWN", "NM_THEMECHANGED", _
            "NM_FONTCHANGED","NM_CUSTOMTEXT/NM_TVSTATEIMAGECHANGING"]
            ; NM_CUSTOMTEXT uses NMCUSTOMTEXT struct
            ; NM_TVSTATEIMAGECHANGING uses NMTVSTATEIMAGECHANGING struct
    Local $iNumber = Int(StringReplace($iInt, "-", ""))
    Switch $iNumber
        Case 0 To 8, 12 To 24
            Return $aNM_Array[$iNumber]
    EndSwitch
    Return SetError(1, 0, "NM_UNCLASSIFIED:" & $iInt)
EndFunc   ;==>WM_NOTIFY_LEGEND

 

Some description please

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted (edited)
6 hours ago, mLipok said:

Some description please

Is "self-descripting"(TM) :P
WM_NOTIFY_LEGEND($NM_CLICK) returns "NM_CLICK" on a listview.

The problem is that it may be too silly of a function, but when you see "-2" and you'd like to know what a "-2" mean, you'd "WM_NOTIFY_LEGEND(-2)"

Actually, I'd like to know what those -100, -101, 102, ... , are. But could not find any info. All I found new are these "NM_FONTCHANGED","NM_CUSTOMTEXT" :(

Edit: ..maybe the problem is my interpretation of the word "legend" that for some reason means "title", or "caption", or "what it reads" if that makes any linguistic sense. And I still feel ( as irrational as it may be ), that the given word ( legend ) should be descriptive as is the most befitting for the function it provides yet, I don't find much to support my feeling of the word. 🤷‍♂️

Edit2: maybe call it WM_NOTIFY_meaning() ?, let me know.

Edit3: I asked my AI and it say:

Spoiler

Why "LEGEND" Might Be a Stretch

  • "Legend" typically refers to a key (e.g., in charts or UI elements) that explains symbols or abbreviations. For example, a legend might clarify what a red triangle means in a chart.
  • "Caption" or "Title" are more direct for a brief explanation of content (e.g., a photo’s caption or a section’s title).
  • "Meaning" or "Definition" are better for returning the interpretation of a value (e.g., "42" → "the answer to life, the universe, and everything").

...the more dig into it the more am unsure.

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • 2 weeks later...
Posted (edited)

I don't know if something like this has already been posted.

 

DarkMode API Calls (undocumented):

;Coded by UEZ build 2025-10-10
;IMMERSIVE_HC_CACHE_MODE
Enum $IHCM_USE_CACHED_VALUE, $IHCM_REFRESH
Enum $Default, $AllowDark, $ForceDark, $ForceLight, $Max ;$iPreferredAppMode
;~ Enum $DWMWA_USE_IMMERSIVE_DARK_MODE = (@OSBuild <= 18985) ? 19 : 20

Func _WinAPI_ShouldAppsUseDarkMode()
    Local $aResult = DllCall("UxTheme.dll", "bool", 132)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_ShouldAppsUseDarkMode

Func _WinAPI_AllowDarkModeForWindow($hWND, $bAllow = True)
    Local $aResult = DllCall("UxTheme.dll", "bool", 133, "hwnd", $hWND, "bool", $bAllow)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_AllowDarkModeForWindow

Func _WinAPI_AllowDarkModeForApp($bAllow = True) ;Windows 10 Build 17763
    Return _WinAPI_SetPreferredAppMode($bAllow ? 1 : 0) ; 1 = AllowDark, 0 = Default
EndFunc   ;==>_WinAPI_AllowDarkModeForApp

Func _WinAPI_SetPreferredAppMode($iPreferredAppMode) ;Windows 10 Build 18362+
    Local $aResult = DllCall("UxTheme.dll", "long", 135, "long", $iPreferredAppMode)
    If @error Then Return SetError(1, 0, False)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_SetPreferredAppMode

Func _WinAPI_FlushMenuThemes()
    Local $aResult = DllCall("UxTheme.dll", "none", 136)
    If @error Then Return SetError(1, 0, False)
    Return True
EndFunc   ;==>_WinAPI_FlushMenuThemes

Func _WinAPI_RefreshImmersiveColorPolicyState()
    Local $aResult = DllCall("UxTheme.dll", "none", 104)
    If @error Then Return SetError(1, 0, False)
    Return True
EndFunc   ;==>_WinAPI_RefreshImmersiveColorPolicyState

Func _WinAPI_IsDarkModeAllowedForWindow($hWND)
    Local $aResult = DllCall("UxTheme.dll", "bool", 137, "hwnd", $hWND)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_IsDarkModeAllowedForWindow

Func _WinAPI_GetIsImmersiveColorUsingHighContrast($iIMMERSIVE_HC_CACHE_MODE)
    Local $aResult = DllCall("UxTheme.dll", "bool", 106, "long", $iIMMERSIVE_HC_CACHE_MODE)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_GetIsImmersiveColorUsingHighContrast

Func _WinAPI_OpenNcThemeData($hWND, $tClassList)
    Local $aResult = DllCall("UxTheme.dll", "hwnd", 49, "hwnd", $hWND, "struct*", $tClassList)
    If @error Then Return SetError(1, 0, False)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_OpenNcThemeData

Func _WinAPI_ShouldSystemUseDarkMode()
    Local $aResult = DllCall("UxTheme.dll", "bool", 138)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_ShouldSystemUseDarkMode

Func _WinAPI_IsDarkModeAllowedForApp()
    Local $aResult = DllCall("UxTheme.dll", "bool", 139)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_IsDarkModeAllowedForApp

 

Requires OSBuild > 17762!

 

API may change in next Windows updates!

Edited by UEZ
Update

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)
On 9/24/2025 at 11:41 PM, argumentum said:

Actually, I'd like to know what those -100, -101, 102

A little late to the party - but FWIW:

LVN_FIRST = -100
LVN_ITEMCHANGING = LVN_FIRST - 0
LVN_ITEMCHANGED = LVN_FIRST - 1
....
LVN_LAST = -199

Edit: While I'm at it... From CommCtrl.h 

//====== WM_NOTIFY codes (NMHDR.code values) ==================================

#define NM_FIRST                (0U-  0U)       // generic to all controls
#define NM_LAST                 (0U- 99U)

#define LVN_FIRST               (0U-100U)       // listview
#define LVN_LAST                (0U-199U)

// Property sheet reserved      (0U-200U) -  (0U-299U) - see prsht.h

#define HDN_FIRST               (0U-300U)       // header
#define HDN_LAST                (0U-399U)

#define TVN_FIRST               (0U-400U)       // treeview
#define TVN_LAST                (0U-499U)

#define TTN_FIRST               (0U-520U)       // tooltips
#define TTN_LAST                (0U-549U)

#define TCN_FIRST               (0U-550U)       // tab control
#define TCN_LAST                (0U-580U)

// Shell reserved               (0U-580U) -  (0U-589U)

#define CDN_FIRST               (0U-601U)       // common dialog (new)
#define CDN_LAST                (0U-699U)

#define TBN_FIRST               (0U-700U)       // toolbar
#define TBN_LAST                (0U-720U)

#define UDN_FIRST               (0U-721U)        // updown
#define UDN_LAST                (0U-729U)
#define DTN_FIRST               (0U-740U)       // datetimepick
#define DTN_LAST                (0U-745U)       // DTN_FIRST - 5

#define MCN_FIRST               (0U-746U)       // monthcal
#define MCN_LAST                (0U-752U)       // MCN_FIRST - 6

#define DTN_FIRST2              (0U-753U)       // datetimepick2
#define DTN_LAST2               (0U-799U)

#define CBEN_FIRST              (0U-800U)       // combo box ex
#define CBEN_LAST               (0U-830U)

#define RBN_FIRST               (0U-831U)       // rebar
#define RBN_LAST                (0U-859U)

#define IPN_FIRST               (0U-860U)       // internet address
#define IPN_LAST                (0U-879U)       // internet address

#define SBN_FIRST               (0U-880U)       // status bar
#define SBN_LAST                (0U-899U)

#define PGN_FIRST               (0U-900U)       // Pager Control
#define PGN_LAST                (0U-950U)

#ifndef WMN_FIRST
#define WMN_FIRST               (0U-1000U)
#define WMN_LAST                (0U-1200U)
#endif

#if (NTDDI_VERSION >= NTDDI_WINXP)
#define BCN_FIRST               (0U-1250U)
#define BCN_LAST                (0U-1350U)
#endif


#if (NTDDI_VERSION >= NTDDI_VISTA)
#define TRBN_FIRST              (0U-1501U)       // trackbar
#define TRBN_LAST               (0U-1519U)
#endif

#if (NTDDI_VERSION >= NTDDI_WIN10_RS5)
#define EN_FIRST                (0U-1520U)      // edit control
#define EN_LAST                 (0U-1540U)
#endif

#define MSGF_COMMCTRL_BEGINDRAG     0x4200
#define MSGF_COMMCTRL_SIZEHEADER    0x4201
#define MSGF_COMMCTRL_DRAGSELECT    0x4202
#define MSGF_COMMCTRL_TOOLBARCUST   0x4203

 

Edited by MattyD
Posted
3 hours ago, UEZ said:

DarkMode API Calls:

Thank you for sharing these. :)

I do have a question about _WinAPI_IsDarkModeAllowedForWindow($hWND) though:

No matter what, I always get a return of -256 from this function.

For example, I will check it on an app before applying dark mode to it and check it after applying dark mode. It returns -256 regardless.

Same for running that function against all running/visible window processes on the system, -256 return.

Do you know why that could be?

Posted
1 hour ago, WildByDesign said:

Thank you for sharing these. :)

I do have a question about _WinAPI_IsDarkModeAllowedForWindow($hWND) though:

No matter what, I always get a return of -256 from this function.

For example, I will check it on an app before applying dark mode to it and check it after applying dark mode. It returns -256 regardless.

Same for running that function against all running/visible window processes on the system, -256 return.

Do you know why that could be?

If I'm not mistaken this is the return value for True in the Windows Bool representation.

Code updated above.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted
12 minutes ago, UEZ said:

If I'm not mistaken this is the return value for True in the Windows Bool representation.

Why is True -256 instead of using the sane value of 1 as everyone else :wacko: (including the C standard)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted
6 hours ago, UEZ said:

If I'm not mistaken this is the return value for True in the Windows Bool representation.

I don't think that's quite right... the definition looks to be in ntdef.h

#define FALSE   0
#define TRUE    1

_WinAPI_IsDarkModeAllowedForWindow returns the same value with an invalid handle, so I think we're missing something.

Posted

yeah. not sure what ordinal #137 does - but it clearly doesn't return bool. 

So I'd say if it ever was IsDarkModeAllowedForWindow in win8 or something, it probably isn't now. - well, at least it doesn't work in the way people on the interweb think it does.

FWIW if you do a DllCall("UxTheme.dll", "int", 135) beforehand you get something other than 0xFFFFFF00 (-256) when calling #137...

Posted (edited)
6 hours ago, MattyD said:

yeah. not sure what ordinal #137 does - but it clearly doesn't return bool. 

So I'd say if it ever was IsDarkModeAllowedForWindow in win8 or something, it probably isn't now. - well, at least it doesn't work in the way people on the interweb think it does.

FWIW if you do a DllCall("UxTheme.dll", "int", 135) beforehand you get something other than 0xFFFFFF00 (-256) when calling #137...

That's the problem of non documented functions, how to Interpret the values.

My assumption was that anything other than zero is “true” for functions that always return two identical conditions, 0 or not 0.


According to https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types 

A Boolean variable (should be TRUE or FALSE).
This type is declared in WinDef.h as follows:
typedef int BOOL;

Int can be more than 0 / 1.

 

https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/8ce7b38c-d3cc-415d-ab39-944000ea77ff

2.1.8 Boolean

06/10/2025

A Boolean data type is a primitive that has one of two possible values: TRUE and FALSE, which are defined as follows:

TRUE: A sender MUST use any nonzero value to denote a TRUE. A receiver MUST interpret any nonzero value as TRUE.

FALSE: A sender MUST use a zero value to denote a FALSE. A receiver MUST interpret a zero value as FALSE.

 

I don't know why the coder of functions "135" returns -256 and not 1 aka true if this is the proper interpretation...

 

Btw, code updated:

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

  

Yeah, totally understand where you're coming from, but I don't think that's what we're seeing here.

If I'm a MS developer writing a func that returns BOOL, then I'm returning TRUE or FALSE.  Or supervisors are throwing style guides at me... I would hope that's the case anyway!  BOOL can only mean "true" or "false" regardless of the actual value - so a different datatype should be used if we're returning something with more meaning than that.  But that aside -

Assuming our fn definition is correct, and by going by the logic: everything <> 0 = true , then I would expect a bad window handle must return 0. But it doesn't...

3 hours ago, UEZ said:

That's the problem of non documented functions, how to Interpret the values.

100% agree to this.  But more to the point - we also can't verify the number and type of params,  or even the function name..  I suspect the definition doing the rounds on the internet is incorrect, but I'm more than happy to proven wrong!.

Edited by MattyD
Posted (edited)
29 minutes ago, MattyD said:

I suspect the definition doing the rounds on the internet is incorrect, but I'm more than happy to proven wrong!.

I agree. I think that it's either this, or as you also mentioned that it may have been something in win8 but has since changed or no longer works.

All of the other related functions return 0 or 1. So in that regard, I am going to avoid using IsDarkModeAllowedForWindow but I will definitely make good use of the other dark mode functions.

Edited by WildByDesign

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
  • Recently Browsing   0 members

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