Jump to content

Recommended Posts

Posted (edited)

I am currently working on a tool, but it seems that it does not work properly on some operating systems and the GUI size is not created correctly.

Can you please test and post the result if the GUI size is created correctly? Minimum should be 150x84 px, maximum @DesktopWidth / 2. 

#include <File.au3>
#include <FileConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <ListViewConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIShellEx.au3>
#include <WindowsConstants.au3>


Global $aTaskbar = WinGetPos("[CLASS:Shell_TrayWnd;INSTANCE:1]", "")
Global $i, $aShortcutDetails, $hIcon, $aFileList = ReadDesktopIcons()
If @error Then
    Dim $aFileList[1]
    $aFileList[0] = 0
    MsgBox($MB_ICONWARNING, "Warning", "No desktop icons!", 15)
EndIf

Global $iLen = 0, $l
For $i = 1 To $aFileList[0]
    $l = StringLen(StringRegExpReplace($aFileList[$i], ".*\\(.*)\..+", "$1"))
    $iLen = $l > $iLen ? $l : $iLen
Next

Global $iW = 0, $iH = 0
Global Const $hGUI = GUICreate("Toolbar Desktop by UEZ", $iW, $iH, $aTaskbar[1] ? -1 : -10000, $aTaskbar[1] ? -10000 : -1, BitOR($WS_MINIMIZEBOX, $WS_SIZEBOX), $WS_EX_TOPMOST)
GUISetFont(8, $FW_NORMAL, $GUI_FONTNORMAL, "Arial", $hGUI, $CLEARTYPE_QUALITY)
Global Const $hLV_Font = _WinAPI_CreateFont(15, 0, 0, 0, $FW_MEDIUM, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $PROOF_QUALITY, 0, "Segoe UI")
Global $hLV = _GUICtrlListView_Create($hGUI, "", 0, 0, 0, 0, BitOR($LVS_SINGLESEL, $LVS_NOCOLUMNHEADER, $LVS_LIST)), $iLV = _WinAPI_GetDlgCtrlID($hLV)
GUICtrlSendMsg($hLV, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_ONECLICKACTIVATE, $LVS_EX_TRACKSELECT)
_GUICtrlListView_SetExtendedListViewStyle($hLV, $LVS_EX_DOUBLEBUFFER)
_GUICtrlListView_InsertColumn($hLV, 0, "Desktop App")
Global Const $hImageList = _GUIImageList_Create(16, 16)

ConsoleWrite("Added " & $aFileList[0] & " items to the list" & @CRLF)

For $i = 1 To $aFileList[0]
    $hIcon = _WinAPI_ShellExtractAssociatedIcon($aFileList[$i], True)
    If $hIcon Then
        _GUIImageList_Add($hImageList, _WinAPI_Create32BitHBITMAP($hIcon))
    Else
        _GUIImageList_Add($hImageList, _GUICtrlListView_CreateSolidBitMap($hLV, 0xFFFFFF, 16, 16))
    EndIf
Next
Global $aIconAssignment[UBound($aFileList) - 1][2]
_GUICtrlListView_SetImageList($hLV, $hImageList, 1)
For $i = 1 To $aFileList[0]
    If StringInStr(FileGetAttrib($aFileList[$i]), "D") Then
        If StringRegExp($aFileList[$i], ".+\.\{(.*)\}") Then
            _GUICtrlListView_AddItem($hLV, StringRegExpReplace($aFileList[$i], ".*\\(.*)\..+", "$1"), $i - 1, $i - 1)
        Else
            _GUICtrlListView_AddItem($hLV, StringRegExpReplace($aFileList[$i], ".+\\(.+)", "$1"), $i - 1, $i - 1)
        EndIf
    Else
        _GUICtrlListView_AddItem($hLV, StringRegExpReplace($aFileList[$i], ".*\\(.*)\..+", "$1"), $i - 1, $i - 1)
    EndIf
    $aIconAssignment[$i - 1][0] = $i - 1
    $aIconAssignment[$i - 1][1] = $aFileList[$i]
Next

ConsoleWrite("Screen Dimensions: " & @DesktopWidth & " x " & @DesktopHeight & @CRLF)
Global $aDimLV = _GUICtrlListView_ApproximateViewRect($hLV)
ConsoleWrite("Listview Dimensions: " & $aDimLV[0] & " x " &  $aDimLV[1] & @CRLF)
Global $aPos = WinGetPos($hGUI), $aWinPos
$iW = $aDimLV[0] / $aDimLV[1] * 2.05 ;
$iW = Max(150, Min(@DesktopWidth / 2, $iW))
$iH = $iW * 9 / 16
WinMove($hGUI, "", (@DesktopWidth - $iW) / 2, (@DesktopHeight - $iH) / 2, $iW, $iH)
ConsoleWrite("Calculated GUI size: " & $iW & " x " & $iH & @CRLF)
ConsoleWrite("OS: " & @OSVersion & @CRLF)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUISetState(@SW_SHOW, $hGUI)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete($hGUI)
Exit

Func ReadDesktopIcons()
    Local $aFileList1 = _FileListToArray(@DesktopDir, "*", $FLTA_FILESFOLDERS, True)
    Local $aFileList2 = _FileListToArray(@DesktopCommonDir, "*", $FLTA_FILESFOLDERS, True)
    If BitOR(IsArray($aFileList1), IsArray($aFileList2)) = 0 Then Return SetError(1, 0, 0)

    Local $i, $j, $aFileList[$aFileList1[0] + $aFileList2[0] + 1], $c = 1
    For $i = 1 To $aFileList1[0]
        If StringRight($aFileList1[$i], 4) <> ".ini" Then
            $aFileList[$c] = $aFileList1[$i]
            $c += 1
        EndIf
    Next
    For $j = 1 To $aFileList2[0]
        If StringRight($aFileList2[$j], 4) <> ".ini" Then
            $aFileList[$c] = $aFileList2[$j]
            $c += 1
        EndIf
    Next
    $aFileList[0] = $c - 1
    ReDim $aFileList[$c]
    Return $aFileList
EndFunc   ;==>ReadDesktopIcons

Func Max($a, $b)
    Return $a > $b ? $a : $b
EndFunc   ;==>Max

Func Min($a, $b)
    Return $a < $b ? $a : $b
EndFunc   ;==>Min

Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    ControlMove($hGUI, "", $iLV, 0, 0, _WinAPI_LoWord($lParam), _WinAPI_HiWord($lParam))
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE^

 

You don't need to post a screenshot, the console output should be enough.

My results:

Added 29 items to the list
Screen Dimensions: 1920 x 1080
Listview Dimensions: 4236 x 19
Calculated GUI size: 457.042105263158 x 257.086184210526
OS: WIN_11

THANK YOU!

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
Added 64 items to the list
Screen Dimensions: 1920 x 1080
Listview Dimensions: 43714 x 19
Calculated GUI size: 960 x 540
OS: WIN_10

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted
54 minutes ago, UEZ said:

You don't need to post a screenshot, the console output should be enough.

My result (Win7, SP1, AutoIt 3.3.14.0) 

Added 46 items to the list
Screen Dimensions: 1920 x 1080
Listview Dimensions: 14170 x 19
Calculated GUI size: 960 x 540
OS: WIN_7

BTW : In case one still uses version 3.3.14.0 (like me), then the following include is required :

#include <WinAPIGdi.au3>

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Posted
Added 104 items to the list
Screen Dimensions: 2560 x 1080
Listview Dimensions: 40458 x 19
Calculated GUI size: 1280 x 720
OS: WIN_10

Added 24 items to the list
Screen Dimensions: 2255 x 928
Listview Dimensions: 6962 x 19
Calculated GUI size: 751.163157894737 x 422.52927631579 ; <-- VMware
OS: WIN_XP

Added 52 items to the list
Screen Dimensions: 1920 x 1080
Listview Dimensions: 18046 x 19
Calculated GUI size: 960 x 540 ; hardware PC
OS: WIN_2022    ; AMD Ryzen 9 5950X 16-Core Processor 3.40 GHz

Added 6 items to the list
Screen Dimensions: 2560 x 1080 ;    on this PC it looks tiny
Listview Dimensions: 950 x 19
Calculated GUI size: 150 x 84.375 ; Windows 11 Enterprise multi-session
OS: WIN_2022    ; Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz 3.20 GHz

Added 37 items to the list
Screen Dimensions: 2560 x 1080 ; Hyper-V PC
Listview Dimensions: 15690 x 19
Calculated GUI size: 1280 x 720
OS: WIN_10

it looks good everywhere but in the W11 for "virtual desktops" or "multi sessions" that is for licensing in Azure only.
..and I load it on an old PC because, I like testing everything that call my attention.

That Win11-MS shows as server OS but, go figure. The one on the 5950X is in fact an actual server OS mod. to run as desktop.

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

Posted (edited)
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>


Example()
Func Example()
        Local $hGUI, $aXY, $idListview, $hLV
        $hGUI = GUICreate("ListView Approximate View Rect", 400, 300, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_SIZEBOX), $WS_EX_TOPMOST)


        ; this works
;~         $idListview = GUICtrlCreateListView("", 5, 5, 390, 260, BitOR($LVS_SINGLESEL, $LVS_NOCOLUMNHEADER, $LVS_LIST), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))



        ; this fails to get the _GUICtrlListView_ApproximateViewRect()
        $idListview = _GUICtrlListView_Create($hGUI, "", 5, 5, 390, 260, BitOR($LVS_SINGLESEL, $LVS_NOCOLUMNHEADER, $LVS_LIST), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))



        GUICtrlSendMsg($idListview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_ONECLICKACTIVATE, $LVS_EX_TRACKSELECT)
        _GUICtrlListView_SetExtendedListViewStyle($idListview, $LVS_EX_DOUBLEBUFFER)
        GUISetState(@SW_SHOW)
        _GUICtrlListView_InsertColumn($idListview, 0, "Column 1", 100)
        For $iI = 0 To 9
            _GUICtrlListView_AddItem($idListview, "Row (your boat down the street #) " & $iI)
        Next
        _GUICtrlListView_SetColumnWidth($idListview, 0, $LVSCW_AUTOSIZE_USEHEADER)
        MsgBox($MB_SYSTEMMODAL, "Information", "Approximate View Rect")
        ; Resize view
        $aXY = _GUICtrlListView_ApproximateViewRect($idListview)
        _WinAPI_SetWindowPos(GUICtrlGetHandle($idListview), 0, 2, 2, $aXY[0], $aXY[1], $SWP_NOZORDER)
        ; Loop until the user exits.
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
        GUIDelete()
EndFunc   ;==>Example

...going down the rabbits hole, the build in Listview looks ok?, but the UDF one looks imbedded into the GUI 

Edit: the imbedded part is desired, the not getting the Aprox. view rect. is not.
...again, this is for the W11-MS version.

Edit2: ..I have no idea of what's going on :baby:

Edited by argumentum
oops

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

Posted
Added 54 items to the list
Screen Dimensions: 2560 x 1440
Listview Dimensions: 11234 x 19
Calculated GUI size: 1212.08947368421 x 681.800328947368
OS: WIN_10

 

Posted (edited)

@argumentum

the first  GUICtrlCreateListView    return the  the identifier (controlID) of the new control.

the second _GUICtrlListView_Create   return the  the the handle to the ListView control.

if that helps

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>


Example()
Func Example()
    Local $hGUI, $aXY, $idListview, $hLV
    $hGUI = GUICreate("ListView Approximate View Rect", 400, 300, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_SIZEBOX), $WS_EX_TOPMOST)


    ; CASE A
;~  $idListview = GUICtrlCreateListView("", 5, 5, 390, 260, BitOR($LVS_SINGLESEL, $LVS_NOCOLUMNHEADER, $LVS_LIST), BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))

    ; CASE B
    $idListview = _GUICtrlListView_Create($hGUI, "", 5, 5, 390, 260, BitOR($LVS_SINGLESEL, $LVS_NOCOLUMNHEADER, $LVS_LIST), BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))

    ConsoleWrite("$idListview=" & $idListview & @CRLF)

    GUICtrlSendMsg($idListview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_ONECLICKACTIVATE, $LVS_EX_TRACKSELECT)
    _GUICtrlListView_SetExtendedListViewStyle($idListview, $LVS_EX_DOUBLEBUFFER)
    GUISetState(@SW_SHOW)
    _GUICtrlListView_InsertColumn($idListview, 0, "Column 1", 100)
    For $iI = 0 To 9
        _GUICtrlListView_AddItem($idListview, "Row (your boat down the street #) " & $iI)
    Next
    _GUICtrlListView_SetColumnWidth($idListview, 0, $LVSCW_AUTOSIZE_USEHEADER)
    MsgBox($MB_SYSTEMMODAL, "Information", "Approximate View Rect")
    ; Resize view
    $aXY = _GUICtrlListView_ApproximateViewRect($idListview)
;~  _WinAPI_SetWindowPos(GUICtrlGetHandle($idListview), 0, 2, 2, $aXY[0], $aXY[1], $SWP_NOZORDER) ;This work in CASE A
    _WinAPI_SetWindowPos($idListview, 0, 2, 2, $aXY[0], $aXY[1], $SWP_NOZORDER) ;This work in CASE B
    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

conclusion:

if you use _GUICtrlListView_Create then  _WinAPI_SetWindowPos($idListview, 0, 2, 2, $aXY[0], $aXY[1], $SWP_NOZORDER)

else if you use GUICtrlCreateListView  then  _WinAPI_SetWindowPos(GUICtrlGetHandle($idListview), 0, 2, 2, $aXY[0], $aXY[1], $SWP_NOZORDER)

:)

Edited by ioa747
added conclusion

I know that I know nothing

Posted (edited)

You have all so much icons on your desktop that always $iW = @DesktopWidth / 2 is applied.

@AllenAA I can see that the calculated GUI size is not @DesktopWidth / 2. Does the GUI have scrollbar (all icons fit in the GUI)?

 

The problem is that for a few icons the GUI is not set properly. If you set the list to a much smaller amount then

ConsoleWrite("Added " & $aFileList[0] & " items to the list" & @CRLF)
$aFileList[0] = 6

the GUI will be created too tiny.

The goal is to adjust the GUI size so that the icons all fit in the GUI, of course only if the maximum GUI size is not exceeded.

@all: thank you for testing!

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
36 minutes ago, UEZ said:

You have all so much icons on your desktop that always $iW = @DesktopWidth / 2 is applied.

You can't blame our poor souls. We need all these files. :whistle:

I left just 2 items on desktop and here is what I get.

Quote

Added 2 items to the list
Screen Dimensions: 1920 x 1080
Listview Dimensions: 194 x 19
Calculated GUI size: 150 x 84.375
OS: WIN_11

image.png.a27acbfe1dad6d52663ea533bfbbbfd4.png

Posted
1 minute ago, Andreik said:

You can't blame our poor souls. We need all these files. :whistle:

I left just 2 items on desktop and here is what I get.

image.png.a27acbfe1dad6d52663ea533bfbbbfd4.png

With Win11 you no longer have the option to add the desktop shortcut to the taskbar and that's why I started programming the Toolbar Desktop App, which works fine on my notebook but not for other environments. I often use the shortcuts on the desktop for faster access and I don't want to go the route of pressing Win+D.

The challenge is to adjust the GUI size so that the icons all fit in the GUI, of course only if the maximum GUI size is not exceeded with the ration 16:9.

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

Can you please test if GUI will be resize properly according the amount of icons read to listview? Of course limit is @DesktopWidth / 2.

#include <File.au3>
#include <FileConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <ListViewConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIShellEx.au3>
#include <WindowsConstants.au3>


Global $aTaskbar = WinGetPos("[CLASS:Shell_TrayWnd;INSTANCE:1]", "")
Global $i, $aShortcutDetails, $hIcon, $aFileList = ReadDesktopIcons()
If @error Then
    Dim $aFileList[1]
    $aFileList[0] = 0
    MsgBox($MB_ICONWARNING, "Warning", "No desktop icons!", 15)
EndIf

Global $iLen = 0, $l
For $i = 1 To $aFileList[0]
    $l = StringLen(StringRegExpReplace($aFileList[$i], ".*\\(.*)\..+", "$1"))
    $iLen = $l > $iLen ? $l : $iLen
Next

Global $iW = 0, $iH = 0
Global Const $hGUI = GUICreate("Toolbar Desktop by UEZ", $iW, $iH, $aTaskbar[1] ? -1 : -10000, $aTaskbar[1] ? -10000 : -1, BitOR($WS_MINIMIZEBOX, $WS_SIZEBOX), $WS_EX_TOPMOST)
GUISetFont(8, $FW_NORMAL, $GUI_FONTNORMAL, "Arial", $hGUI, $CLEARTYPE_QUALITY)
Global $hLV = _GUICtrlListView_Create($hGUI, "", 0, 0, 0, 0, BitOR($LVS_SINGLESEL, $LVS_NOCOLUMNHEADER, $LVS_LIST)), $iLV = _WinAPI_GetDlgCtrlID($hLV)
GUICtrlSendMsg($hLV, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_ONECLICKACTIVATE, $LVS_EX_TRACKSELECT)
_GUICtrlListView_SetExtendedListViewStyle($hLV, $LVS_EX_DOUBLEBUFFER)
_GUICtrlListView_InsertColumn($hLV, 0, "Desktop App")
Global Const $hImageList = _GUIImageList_Create(16, 16)

ConsoleWrite("Added " & $aFileList[0] & " items to the list" & @CRLF)
;~ $aFileList[0] = 6
For $i = 1 To $aFileList[0]
    $hIcon = _WinAPI_ShellExtractAssociatedIcon($aFileList[$i], True)
    If $hIcon Then
        _GUIImageList_Add($hImageList, _WinAPI_Create32BitHBITMAP($hIcon))
    Else
        _GUIImageList_Add($hImageList, _GUICtrlListView_CreateSolidBitMap($hLV, 0xFFFFFF, 16, 16))
    EndIf
Next
Global $aIconAssignment[UBound($aFileList) - 1][2]
_GUICtrlListView_SetImageList($hLV, $hImageList, 1)
For $i = 1 To $aFileList[0]
    If StringInStr(FileGetAttrib($aFileList[$i]), "D") Then
        If StringRegExp($aFileList[$i], ".+\.\{(.*)\}") Then
            _GUICtrlListView_AddItem($hLV, StringRegExpReplace($aFileList[$i], ".*\\(.*)\..+", "$1"), $i - 1, $i - 1)
        Else
            _GUICtrlListView_AddItem($hLV, StringRegExpReplace($aFileList[$i], ".+\\(.+)", "$1"), $i - 1, $i - 1)
        EndIf
    Else
        _GUICtrlListView_AddItem($hLV, StringRegExpReplace($aFileList[$i], ".*\\(.*)\..+", "$1"), $i - 1, $i - 1)
    EndIf
    $aIconAssignment[$i - 1][0] = $i - 1
    $aIconAssignment[$i - 1][1] = $aFileList[$i]
Next

;~ ConsoleWrite("Screen Dimensions: " & @DesktopWidth & " x " & @DesktopHeight & @CRLF)
;~ Global $aDimLV = _GUICtrlListView_ApproximateViewRect($hLV)
;~ ConsoleWrite("Listview Dimensions: " & $aDimLV[0] & " x " &  $aDimLV[1] & @CRLF)
;~ Global $aPos = WinGetPos($hGUI), $aWinPos
;~ $iW = $aDimLV[0] / $aDimLV[1] * 2.05 ;
;~ $iW = Max(150, Min(@DesktopWidth / 2, $iW))
;~ $iH = $iW * 9 / 16
;~ WinMove($hGUI, "", (@DesktopWidth - $iW) / 2, (@DesktopHeight - $iH) / 2, $iW, $iH)
;~ ConsoleWrite("Calculated GUI size: " & $iW & " x " & $iH & @CRLF)
;~ ConsoleWrite("OS: " & @OSVersion & @CRLF)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

If $iW < @DesktopWidth / 2 And BitAND(_WinAPI_GetWindowLong($hLV, $GWL_STYLE), $WS_HSCROLL) Then
    While BitAND(_WinAPI_GetWindowLong($hLV, $GWL_STYLE), $WS_HSCROLL)
        $iW += 1.77778 ;ratio 16:9
        $iH += 1
        WinMove($hGUI, "", (@DesktopWidth - $iW) / 2, (@DesktopHeight - $iH) / 2, $iW, $iH)
        If $iW > @DesktopWidth / 2 Then ExitLoop
    WEnd
EndIf

GUISetState(@SW_SHOW, $hGUI)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete($hGUI)
Exit

Func ReadDesktopIcons()
    Local $aFileList1 = _FileListToArray(@DesktopDir, "*", $FLTA_FILESFOLDERS, True)
    Local $aFileList2 = _FileListToArray(@DesktopCommonDir, "*", $FLTA_FILESFOLDERS, True)
    If BitOR(IsArray($aFileList1), IsArray($aFileList2)) = 0 Then Return SetError(1, 0, 0)

    Local $i, $j, $aFileList[$aFileList1[0] + $aFileList2[0] + 1], $c = 1
    For $i = 1 To $aFileList1[0]
        If StringRight($aFileList1[$i], 4) <> ".ini" Then
            $aFileList[$c] = $aFileList1[$i]
            $c += 1
        EndIf
    Next
    For $j = 1 To $aFileList2[0]
        If StringRight($aFileList2[$j], 4) <> ".ini" Then
            $aFileList[$c] = $aFileList2[$j]
            $c += 1
        EndIf
    Next
    $aFileList[0] = $c - 1
    ReDim $aFileList[$c]
    Return $aFileList
EndFunc   ;==>ReadDesktopIcons

Func Max($a, $b)
    Return $a > $b ? $a : $b
EndFunc   ;==>Max

Func Min($a, $b)
    Return $a < $b ? $a : $b
EndFunc   ;==>Min

Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    ControlMove($hGUI, "", $iLV, 0, 0, _WinAPI_LoWord($lParam), _WinAPI_HiWord($lParam))
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

 

Thanks.

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

 

Added 70 items to the list
Screen Dimensions: 1920 x 1080
Listview Dimensions: 11396 x 19
Calculated GUI size: 960 x 540
OS: WIN_10

and for me it has a scrollbar, it has them in three columns, and even though some of them have huge names, they are all fine, (all icons fit in the GUI)

if I increase the shortcut name, then each column has the width of the gui,  and the name beyond the width of the gui cuts it out.

 

I know that I know nothing

Posted
4 minutes ago, UEZ said:

Can you please test if GUI will be resize properly according the amount of icons read to listview? Of course limit is @DesktopWidth / 2.

#include <File.au3>
#include <FileConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <ListViewConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIShellEx.au3>
#include <WindowsConstants.au3>


Global $aTaskbar = WinGetPos("[CLASS:Shell_TrayWnd;INSTANCE:1]", "")
Global $i, $aShortcutDetails, $hIcon, $aFileList = ReadDesktopIcons()
If @error Then
    Dim $aFileList[1]
    $aFileList[0] = 0
    MsgBox($MB_ICONWARNING, "Warning", "No desktop icons!", 15)
EndIf

Global $iLen = 0, $l
For $i = 1 To $aFileList[0]
    $l = StringLen(StringRegExpReplace($aFileList[$i], ".*\\(.*)\..+", "$1"))
    $iLen = $l > $iLen ? $l : $iLen
Next

Global $iW = 0, $iH = 0
Global Const $hGUI = GUICreate("Toolbar Desktop by UEZ", $iW, $iH, $aTaskbar[1] ? -1 : -10000, $aTaskbar[1] ? -10000 : -1, BitOR($WS_MINIMIZEBOX, $WS_SIZEBOX), $WS_EX_TOPMOST)
GUISetFont(8, $FW_NORMAL, $GUI_FONTNORMAL, "Arial", $hGUI, $CLEARTYPE_QUALITY)
Global $hLV = _GUICtrlListView_Create($hGUI, "", 0, 0, 0, 0, BitOR($LVS_SINGLESEL, $LVS_NOCOLUMNHEADER, $LVS_LIST)), $iLV = _WinAPI_GetDlgCtrlID($hLV)
GUICtrlSendMsg($hLV, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_ONECLICKACTIVATE, $LVS_EX_TRACKSELECT)
_GUICtrlListView_SetExtendedListViewStyle($hLV, $LVS_EX_DOUBLEBUFFER)
_GUICtrlListView_InsertColumn($hLV, 0, "Desktop App")
Global Const $hImageList = _GUIImageList_Create(16, 16)

ConsoleWrite("Added " & $aFileList[0] & " items to the list" & @CRLF)
;~ $aFileList[0] = 6
For $i = 1 To $aFileList[0]
    $hIcon = _WinAPI_ShellExtractAssociatedIcon($aFileList[$i], True)
    If $hIcon Then
        _GUIImageList_Add($hImageList, _WinAPI_Create32BitHBITMAP($hIcon))
    Else
        _GUIImageList_Add($hImageList, _GUICtrlListView_CreateSolidBitMap($hLV, 0xFFFFFF, 16, 16))
    EndIf
Next
Global $aIconAssignment[UBound($aFileList) - 1][2]
_GUICtrlListView_SetImageList($hLV, $hImageList, 1)
For $i = 1 To $aFileList[0]
    If StringInStr(FileGetAttrib($aFileList[$i]), "D") Then
        If StringRegExp($aFileList[$i], ".+\.\{(.*)\}") Then
            _GUICtrlListView_AddItem($hLV, StringRegExpReplace($aFileList[$i], ".*\\(.*)\..+", "$1"), $i - 1, $i - 1)
        Else
            _GUICtrlListView_AddItem($hLV, StringRegExpReplace($aFileList[$i], ".+\\(.+)", "$1"), $i - 1, $i - 1)
        EndIf
    Else
        _GUICtrlListView_AddItem($hLV, StringRegExpReplace($aFileList[$i], ".*\\(.*)\..+", "$1"), $i - 1, $i - 1)
    EndIf
    $aIconAssignment[$i - 1][0] = $i - 1
    $aIconAssignment[$i - 1][1] = $aFileList[$i]
Next

;~ ConsoleWrite("Screen Dimensions: " & @DesktopWidth & " x " & @DesktopHeight & @CRLF)
;~ Global $aDimLV = _GUICtrlListView_ApproximateViewRect($hLV)
;~ ConsoleWrite("Listview Dimensions: " & $aDimLV[0] & " x " &  $aDimLV[1] & @CRLF)
;~ Global $aPos = WinGetPos($hGUI), $aWinPos
;~ $iW = $aDimLV[0] / $aDimLV[1] * 2.05 ;
;~ $iW = Max(150, Min(@DesktopWidth / 2, $iW))
;~ $iH = $iW * 9 / 16
;~ WinMove($hGUI, "", (@DesktopWidth - $iW) / 2, (@DesktopHeight - $iH) / 2, $iW, $iH)
;~ ConsoleWrite("Calculated GUI size: " & $iW & " x " & $iH & @CRLF)
;~ ConsoleWrite("OS: " & @OSVersion & @CRLF)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

If $iW < @DesktopWidth / 2 And BitAND(_WinAPI_GetWindowLong($hLV, $GWL_STYLE), $WS_HSCROLL) Then
    While BitAND(_WinAPI_GetWindowLong($hLV, $GWL_STYLE), $WS_HSCROLL)
        $iW += 1.77778 ;ratio 16:9
        $iH += 1
        WinMove($hGUI, "", (@DesktopWidth - $iW) / 2, (@DesktopHeight - $iH) / 2, $iW, $iH)
        If $iW > @DesktopWidth / 2 Then ExitLoop
    WEnd
EndIf

GUISetState(@SW_SHOW, $hGUI)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete($hGUI)
Exit

Func ReadDesktopIcons()
    Local $aFileList1 = _FileListToArray(@DesktopDir, "*", $FLTA_FILESFOLDERS, True)
    Local $aFileList2 = _FileListToArray(@DesktopCommonDir, "*", $FLTA_FILESFOLDERS, True)
    If BitOR(IsArray($aFileList1), IsArray($aFileList2)) = 0 Then Return SetError(1, 0, 0)

    Local $i, $j, $aFileList[$aFileList1[0] + $aFileList2[0] + 1], $c = 1
    For $i = 1 To $aFileList1[0]
        If StringRight($aFileList1[$i], 4) <> ".ini" Then
            $aFileList[$c] = $aFileList1[$i]
            $c += 1
        EndIf
    Next
    For $j = 1 To $aFileList2[0]
        If StringRight($aFileList2[$j], 4) <> ".ini" Then
            $aFileList[$c] = $aFileList2[$j]
            $c += 1
        EndIf
    Next
    $aFileList[0] = $c - 1
    ReDim $aFileList[$c]
    Return $aFileList
EndFunc   ;==>ReadDesktopIcons

Func Max($a, $b)
    Return $a > $b ? $a : $b
EndFunc   ;==>Max

Func Min($a, $b)
    Return $a < $b ? $a : $b
EndFunc   ;==>Min

Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    ControlMove($hGUI, "", $iLV, 0, 0, _WinAPI_LoWord($lParam), _WinAPI_HiWord($lParam))
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

 

Thanks.

It looks fine.

image.png.929b67ee72bc28d77116c55c2212845c.png

Posted
32 minutes ago, ioa747 said:

 

Added 70 items to the list
Screen Dimensions: 1920 x 1080
Listview Dimensions: 11396 x 19
Calculated GUI size: 960 x 540
OS: WIN_10

and for me it has a scrollbar, it has them in three columns, and even though some of them have huge names, they are all fine, (all icons fit in the GUI)

if I increase the shortcut name, then each column has the width of the gui,  and the name beyond the width of the gui cuts it out.

 

The size of the GUI is limited and therefore a scroll bar may appear - this is intentional.

Thanks for testing.

@Andreik thank u2

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

I added this 2 lines:

Global $aPos = WinGetPos($hGUI)
ConsoleWrite('GUI->Size: ' & $aPos[2] & '|' & $aPos[3] & @CRLF)

and get consoleoutput:

GUI->Size: 136|39
Added 9 items to the list
Screen Dimensions: 1366 x 768
Listview Dimensions: 1028 x 19
Calculated GUI size: 150 x 84.375
OS: WIN_10

and i'm wondering why is the real size (136|90) different to calculated size(150x84.375)

Sorry tested at wrong point, testing after GuiSetState the console output is

Added 9 items to the list
Screen Dimensions: 1366 x 768
Listview Dimensions: 1028 x 19
Calculated GUI size: 150 x 84.375
OS: WIN_10
GUI->Size: 150|84

 

Posted (edited)

@argumentum I hope you don't mind me doing something similar in parallel.

I would like to test the code on different OS, need your support. It would make sense to have 2+ monitors, if possible with > 96 DPI. I don't know from which os it is possible to set different DPIs per monitor (WIn10+?).

I tested it on Win11 22H2 and worked properly on 3 monitors with 3 different DPIs (left 100%, middle 125 % (main), right 150%). Just run the code and move the GUI over all your monitors. Theoretically the GUI should be adjusted accordingly.

 

_WinAPI_DPI.au3:

;Coded by UEZ build 2023-08-15 beta
#include-once
#include <GDIPlus.au3>
#include <Misc.au3>
#include <WinAPISysWin.au3>
#include <WinAPIsysinfoConstants.au3>

#Region DPI Constants
;https://learn.microsoft.com/en-us/windows/win32/api/windef/ne-windef-dpi_awareness
Global Enum $DPI_AWARENESS_INVALID = -1, $DPI_AWARENESS_UNAWARE = 0, $DPI_AWARENESS_SYSTEM_AWARE = 1, $DPI_AWARENESS_PER_MONITOR_AWARE = 2

;https://learn.microsoft.com/en-us/windows/win32/hidpi/dpi-awareness-context
Global Const $DPI_AWARENESS_CONTEXT_UNAWARE = $DPI_AWARENESS_UNAWARE - 1
Global Const $DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = $DPI_AWARENESS_UNAWARE - 2
Global Const $DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = $DPI_AWARENESS_UNAWARE - 3
Global Const $DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = $DPI_AWARENESS_UNAWARE - 4
Global Const $DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED = $DPI_AWARENESS_UNAWARE - 5

; enum _MONITOR_DPI_TYPE
Global Enum $MDT_EFFECTIVE_DPI = 0, $MDT_ANGULAR_DPI, $MDT_RAW_DPI
Global Const $MDT_DEFAULT = $MDT_EFFECTIVE_DPI

;Windows Message Codes
Global Const $WM_DPICHANGED = 0x02E0, $WM_DPICHANGED_BEFOREPARENT = 0x02E2, $WM_DPICHANGED_AFTERPARENT = 0x02E3, $WM_GETDPISCALEDSIZE = 0x02E4
#EndRegion DPI Constants

#Region WinAPI DPI
;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-adjustwindowrectexfordpi
Func _WinAPI_AdjustWindowRectExForDpi($dpi, $dwStyle, $dwExStyle, $bMenu = False)
    Local $tRECT = DllStructCreate($tagRECT)
    Local $aResult = DllCall("user32.dll", "bool", "AdjustWindowRectExForDpi", "struct*", $tRECT, "dword", $dwStyle, "bool", $bMenu, "dword", $dwExStyle, "int", $dpi) ;requires Win10 v1607+ / no server support
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If $aResult[0] Then Return SetError(2, @extended, 0)
    Return $tRECT
EndFunc   ;==>_WinAPI_AdjustWindowRectExForDpi

;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfofordpi
Func _WinAPI_SystemParametersInfoForDpi($uiAction, $uiParam, $pvParam, $fWinIni, $dpi)
    Local $aResult = DllCall("user32.dll", "bool", "SystemParametersInfoForDpi", "uint", $uiAction, "uint", $uiParam, "struct*", $pvParam, "uint", $fWinIni, "uint", $dpi) ;requires Win10 v1607+ / no server support
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If Not $aResult[0] Then Return SetError(2, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_SystemParametersInfoForDpi

;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-inheritwindowmonitor
Func _WinAPI_InheritWindowMonitor($hWnd, $hWndInherit)
    Local $aResult = DllCall("user32.dll", "bool", "InheritWindowMonitor", "hwnd", $hWnd, "hwnd", $hWndInherit) ;requires Win10 v1803+ / Windows Server 2016+
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If Not $aResult[0] Then Return SetError(2, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_InheritWindowMonitor

;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-isvaliddpiawarenesscontext
Func _WinAPI_IsValidDpiAwarenessContext($DPI_AWARENESS_CONTEXT_value)
    Local $aResult = DllCall("user32.dll", "bool", "IsValidDpiAwarenessContext", @AutoItX64 ? "int64" : "int", $DPI_AWARENESS_CONTEXT_value) ;requires Win10 v1607+ / no server support
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If Not $aResult[0] Then Return SetError(2, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_IsValidDpiAwarenessContext

;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-logicaltophysicalpointforpermonitordpi
Func _WinAPI_LogicalToPhysicalPointForPerMonitorDPI($hWnd)
    Local $tPOINT = DllStructCreate($tagPOINT)
    Local $aResult = DllCall("user32.dll", "bool", "LogicalToPhysicalPointForPerMonitorDPI", "hwnd", $hWnd, "struct*", $tPOINT) ;requires Win 8.1+ / no server support
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If Not $aResult[0] Then Return SetError(2, @extended, 0)
    Return $tPOINT
EndFunc   ;==>_WinAPI_LogicalToPhysicalPointForPerMonitorDPI

;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-physicaltologicalpointforpermonitordpi
Func _WinAPI_PhysicalToLogicalPointForPerMonitorDPI($hWnd)
    Local $tPOINT = DllStructCreate($tagPOINT)
    Local $aResult = DllCall("user32.dll", "bool", "PhysicalToLogicalPointForPerMonitorDPI", "hwnd", $hWnd, "struct*", $tPOINT) ;requires Win 8.1+ / no server support
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If Not $aResult[0] Then Return SetError(2, @extended, 0)
    Return $tPOINT
EndFunc   ;==>_WinAPI_PhysicalToLogicalPointForPerMonitorDPI


Func _GDIPlus_GetDPI($hGUI = 0)
    _GDIPlus_Startup()
    Local $hGfx = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    If @error Then Return SetError(1, @extended, 0)
    Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetDpiX", "handle", $hGfx, "float*", 0)
    If @error Then Return SetError(2, @extended, 0)
    _GDIPlus_GraphicsDispose($hGfx)
    _GDIPlus_Shutdown()
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_GetDPI

Func _WinAPI_GetDPI($hWnd = 0)
    $hWnd = Not $hWnd ? _WinAPI_GetDesktopWindow() : $hWnd
    Local Const $hDC = _WinAPI_GetDC($hWnd)
    If @error Then Return SetError(1, 0, 0)
    Local Const $iDPI = _WinAPI_GetDeviceCaps($hDC, $LOGPIXELSX)
    If @error Or Not $iDPI Then
        _WinAPI_ReleaseDC($hWnd, $hDC)
        Return SetError(2, 0, 0)
    EndIf
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $iDPI
EndFunc   ;==>_WinAPI_GetDPI

;https://learn.microsoft.com/en-us/windows/win32/api/shellscalingapi/nf-shellscalingapi-getdpiformonitor
Func _WinAPI_GetDpiForPrimaryMonitor($hMOnitor = 0, $dpiType = $MDT_DEFAULT)
    If $hMOnitor = 0 Then
        Local $aMonitors = _WinAPI_EnumDisplayMonitors()
        If @error Or Not IsArray($aMonitors) Then Return SetError(1, 0, 0)
        Local $i
        For $i = 1 To $aMonitors[0][0]
            If _WinAPI_GetMonitorInfo($aMonitors[$i][0])[2] = 1 Then
                $hMOnitor = $aMonitors[$i][0]
                ExitLoop
            EndIf
        Next
    EndIf
    Local $tx = DllStructCreate("int dpiX"), $tY = DllStructCreate("int dpiY")
    Local $aResult = DllCall("Shcore.dll", "long", "GetDpiForMonitor", "handle", $hMOnitor, "long", $dpiType, "struct*", $tx, "struct*", $tY)
    If @error Or Not IsArray($aResult) Then Return SetError(2, 0, 0)
    Return $tx.dpiX
EndFunc   ;==>_WinAPI_GetDpiForPrimaryMonitor

;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdpiforwindow
Func _WinAPI_GetDpiForWindow($hWnd)
    Local $aResult = DllCall("user32.dll", "uint", "GetDpiForWindow", "hwnd", $hWnd) ;requires Win10 v1607+ / no server support
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If Not $aResult[0] Then Return SetError(2, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_GetDpiForWindow

;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdpiforsystem
Func _WinAPI_GetDpiForSystem()
    Local $aResult = DllCall("user32.dll", "uint", "GetDpiForSystem") ;requires Win10 v1607+ / no server support
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If Not $aResult[0] Then Return SetError(2, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_GetDpiForSystem

;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getthreaddpiawarenesscontext
Func _WinAPI_GetThreadDpiAwarenessContext()
    Local $aResult = DllCall("user32.dll", "uint", "GetThreadDpiAwarenessContext") ;requires Win10 v1607+ / no server support
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If Not $aResult[0] Then Return SetError(2, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_GetThreadDpiAwarenessContext

;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdpifromdpiawarenesscontext
Func _WinAPI_GetDpiFromDpiAwarenessContext($DPI_AWARENESS_CONTEXT_value)
    Local $aResult = DllCall("user32.dll", "uint", "GetDpiFromDpiAwarenessContext", @AutoItX64 ? "int64" : "int", $DPI_AWARENESS_CONTEXT_value) ;requires Win10 v1803+ / Windows Server 2016+
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If Not $aResult[0] Then Return SetError(2, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_GetDpiFromDpiAwarenessContext

;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getawarenessfromdpiawarenesscontext
Func _WinAPI_GetAwarenessFromDpiAwarenessContext($DPI_AWARENESS_CONTEXT_value)
    Local $aResult = DllCall("user32.dll", "uint", "GetAwarenessFromDpiAwarenessContext", @AutoItX64 ? "int64" : "int", $DPI_AWARENESS_CONTEXT_value) ;requires Win10 v1607+ / no server support
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If Not $aResult[0] Then Return SetError(2, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_GetAwarenessFromDpiAwarenessContext

;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdpiawarenesscontextforprocess
Func _WinAPI_GetDpiAwarenessContextForProcess($hProcess)
    Local $aResult = DllCall("user32.dll", "uint", "GetDpiAwarenessContextForProcess", "handle", $hProcess) ;requires Win10 v1803+ / Windows Server 2016+
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If Not $aResult[0] Then Return SetError(2, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_GetDpiAwarenessContextForProcess

;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemdpiforprocess
Func _WinAPI_GetSystemDpiForProcess($hProcess)
    Local $aResult = DllCall("user32.dll", "uint", "GetSystemDpiForProcess", "handle", $hProcess) ;requires Win10 v1803+ / Windows Server 2016+
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If Not $aResult[0] Then Return SetError(2, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_GetSystemDpiForProcess

;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowdpiawarenesscontext
Func _WinAPI_GetWindowDpiAwarenessContext($hWnd)
    Local $aResult = DllCall("user32.dll", "uint", "GetWindowDpiAwarenessContext", "hwnd", $hWnd) ;requires Win10 v1607+ / no server support
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If Not $aResult[0] Then Return SetError(2, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_GetWindowDpiAwarenessContext


;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setprocessdpiawarenesscontext
Func _WinAPI_SetProcessDpiAwarenessContext($DPI_AWARENESS_CONTEXT_value)
    Local $aResult = DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", $DPI_AWARENESS_CONTEXT_value) ;requires Win10 v1703+ / Windows Server 2016+
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If Not $aResult[0] Then Return SetError(2, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_SetProcessDpiAwarenessContext

;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setthreaddpiawarenesscontext
Func _WinAPI_SetThreadDpiAwarenessContext($DPI_AWARENESS_CONTEXT_value)
    Local $aResult = DllCall("user32.dll", "uint", "SetThreadDpiAwarenessContext", @AutoItX64 ? "int64" : "int", $DPI_AWARENESS_CONTEXT_value) ;requires Win10 v1703+ / Windows Server 2016+
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If Not $aResult[0] Then Return SetError(2, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_SetThreadDpiAwarenessContext

;https://learn.microsoft.com/en-us/windows/win32/api/shellscalingapi/nf-shellscalingapi-setprocessdpiawareness
Func _WinAPI_SetProcessDpiAwareness($PROCESS_DPI_AWARENESS = $DPI_AWARENESS_PER_MONITOR_AWARE)
    Local $aResult = DllCall("Shcore.dll", "long", "SetProcessDpiAwareness", "int", $PROCESS_DPI_AWARENESS) ;requires Win 8.1+ / Server 2012 R2+
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If $aResult[0] Then Return SetError(2, $aResult[0], 0)
    Return $aResult[0] ;0 is S_OK
EndFunc   ;==>_WinAPI_SetProcessDpiAwareness

Func _WinAPI_SetDPIAwareness($DPIAwareContext = $DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE, $iMode = 1)
    Switch @OSBuild
        Case 6000 To 9199
            Local $aResult = DllCall("user32.dll", "bool", "SetProcessDPIAware") ;requires Vista+ / Server 2008+
            If Not $aResult[0] Then Return SetError(1, 0, 0)
        Case 9200 To 13999
            $DPIAwareContext = ($DPIAwareContext < 0) ? 0 : ($DPIAwareContext > 2) ? 2 : $DPIAwareContext
            _WinAPI_SetProcessDpiAwareness($DPIAwareContext)
            If @error Then Return SetError(2, @error, 0)
        Case @OSBuild > 13999
            $DPIAwareContext = ($DPIAwareContext < -5) ? -5 : ($DPIAwareContext > -1) ? -1 : $DPIAwareContext
            $iMode = ($iMode < 1) ? 1 : ($iMode > 2) ? 2 : $iMode
            Local $iResult
            Switch $iMode
                Case 1
                    $iResult = _WinAPI_SetProcessDpiAwarenessContext($DPIAwareContext)
                    If Not $iResult Or @error Then Return SetError(3, 0, 0)
                Case 2
                    #cs
                        Return DPI_AWARENESS_CONTEXT values
                        $DPI_AWARENESS_CONTEXT_UNAWARE = 0x6010 / 24592
                        $DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = 0x9011 / 36881
                        $DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = 0x12 / 18
                        $DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = 0x22 / 34
                        $DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED = 0x40006010 / 1073766416
                    #ce
                    $iResult = _WinAPI_SetThreadDpiAwarenessContext($DPIAwareContext)
                    If Not $iResult Or @error Then Return SetError(4, 0, 0)
            EndSwitch
    EndSwitch
    Local $iDPI
    If @OSBuild < 9200 Then
        $iDPI = _WinAPI_GetDPI()
        If @error Or Not $iDPI Then Return SetError(5, 0, 0)
    Else
        $iDPI = _WinAPI_GetDpiForPrimaryMonitor()
        If @error Or Not $iDPI Then Return SetError(6, 0, 0)
    EndIf

    Return $iDPI
EndFunc   ;==>_WinAPI_SetDPIAwareness
#EndRegion WinAPI DPI

 

 

Example.au3:

; AutoIt GUI Example
; Created: 17/01/2005 - CyberSlug
; Modifed: 05/12/2011 - guinness
; Modifed: 09/06/2014 - mLipok
; Modifed: 15/10/2018 - mLipok
; Modifed: 14/08/2023 - UEZ

#AutoIt3Wrapper_Change2CUI=n
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so
#AutoIt3Wrapper_Res_HiDpi=n  ;must be n otherwise _WinAPI_SetDPIAwareness() function will fail!
#AutoIt3Wrapper_UseX64=n

#Region INCLUDE
#include <AVIConstants.au3>
#include <GuiConstantsEx.au3>
#include <TreeViewConstants.au3>

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WinAPIGdiDC.au3>
#include <WindowsConstants.au3>
#include "_WinAPI_DPI.au3"
#EndRegion INCLUDE

#Region INITIALIZATION and EXIT
Global $aCtrl[43][6], $ahWnd[2][10], $g_iDPI_ratio1, $g_iDPI_ratio2, $iw = 400, $ih = 200

_Example()
; Finished!
#EndRegion INITIALIZATION and EXIT

Func _Example()
    Local $AWARENESS
    Switch @OSBuild
        Case 9200 To 13999
            $AWARENESS = $DPI_AWARENESS_PER_MONITOR_AWARE
        Case @OSBuild > 13999
            $AWARENESS = $DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
    EndSwitch

    Local $iDPI = _WinAPI_SetDPIAwareness($AWARENESS, 2), $iDPI_def = 96
    If $iDPI = 0 Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to set DPI awareness!!!", 10)
    $g_iDPI_ratio1 = $iDPI / $iDPI_def
    $g_iDPI_ratio2 = $iDPI_def / $iDPI

    #Region GUI
    Local $sPath = RegRead("HKLM\SOFTWARE\" & (@AutoItX64 ? "WOW6432Node\" : "") & "AutoIt v3\AutoIt", "InstallDir")
    $sPath = ($sPath = "" ? @ProgramFilesDir & "\AutoIt3\" : $sPath & "\") ;assume default path

    $ahWnd[0][1] = 8.5 * $g_iDPI_ratio1
    $ahWnd[0][0] = GUICreate("DPI Sample GUI", 400 * $g_iDPI_ratio1, 400 * $g_iDPI_ratio1)
    GUISetIcon(@SystemDir & "\mspaint.exe", 0)
    GUISetFont($ahWnd[0][1], 400, 0, "Arial", $ahWnd[0][0], $CLEARTYPE_QUALITY)
    #EndRegion GUI

    #Region MENU
    $aCtrl[1][0] = GUICtrlCreateMenu("Menu &One")
    $aCtrl[2][0] = GUICtrlCreateMenu("Menu &Two")

    $aCtrl[3][0] = GUICtrlCreateMenu("Menu Th&ree")
    $aCtrl[4][0] = GUICtrlCreateMenu("Menu &Four")
    GUICtrlCreateMenuItem('SubMenu One &A', $aCtrl[1][0])
    GUICtrlCreateMenuItem('SubMenu One &B', $aCtrl[1][0])
    #EndRegion MENU

    #Region CONTEXT MENU
    $aCtrl[5][0] = GUICtrlCreateContextMenu()
    GUICtrlCreateMenuItem("Context Menu", $aCtrl[5][0])
    GUICtrlCreateMenuItem("", $aCtrl[5][0]) ; Separator
    GUICtrlCreateMenuItem("&Properties", $aCtrl[5][0])
    #EndRegion CONTEXT MENU

    #Region PIC
    $aCtrl[6][2] = 0    ;x
    $aCtrl[6][3] = 0    ;y
    $aCtrl[6][4] = 169  ;w
    $aCtrl[6][5] = 68   ;h
    $aCtrl[6][0] = GUICtrlCreatePic($sPath & "Examples\GUI\logo4.gif", $aCtrl[6][2] * $g_iDPI_ratio1, $aCtrl[6][3] * $g_iDPI_ratio1, $aCtrl[6][4] * $g_iDPI_ratio1, $aCtrl[6][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region PIC')
    $aCtrl[7][2] = 75
    $aCtrl[7][3] = 1
    $aCtrl[7][4] = 80
    $aCtrl[7][5] = 16
    $aCtrl[7][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[7][0] = GUICtrlCreateLabel("Sample Pic", $aCtrl[7][2] * $g_iDPI_ratio1, $aCtrl[7][3] * $g_iDPI_ratio1, $aCtrl[7][4] * $g_iDPI_ratio1, $aCtrl[7][5] * $g_iDPI_ratio1)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetFont(-1, $aCtrl[7][1] * $g_iDPI_ratio1)
    #EndRegion PIC

    #Region AVI
    $aCtrl[8][2] = 180
    $aCtrl[8][3] = 10
    $aCtrl[8][4] = 32
    $aCtrl[8][5] = 32
    $aCtrl[8][0] = GUICtrlCreateAvi($sPath & "Examples\GUI\SampleAVI.avi", 0, $aCtrl[8][2] * $g_iDPI_ratio1, $aCtrl[8][3] * $g_iDPI_ratio1, $aCtrl[8][4] * $g_iDPI_ratio1, $aCtrl[8][5] * $g_iDPI_ratio1, $ACS_AUTOPLAY)
    GUICtrlSetTip(-1, '#Region AVI') ; TODO
    $aCtrl[9][2] = 175
    $aCtrl[9][3] = 50
    $aCtrl[9][4] = 50
    $aCtrl[9][5] = 12
    $aCtrl[9][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[9][0] = GUICtrlCreateLabel("Sample avi", $aCtrl[9][2] * $g_iDPI_ratio1, $aCtrl[9][3] * $g_iDPI_ratio1, $aCtrl[9][4] * $g_iDPI_ratio1, $aCtrl[9][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region AVI - Label')
    GUICtrlSetFont(-1, $aCtrl[9][1] * $g_iDPI_ratio1)
    #EndRegion AVI

    #Region TAB
    $aCtrl[10][2] = 240
    $aCtrl[10][3] = 0
    $aCtrl[10][4] = 150
    $aCtrl[10][5] = 70
    $aCtrl[10][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[10][0] = GUICtrlCreateTab($aCtrl[10][2] * $g_iDPI_ratio1, $aCtrl[10][3] * $g_iDPI_ratio1, $aCtrl[10][4] * $g_iDPI_ratio1, $aCtrl[10][5] * $g_iDPI_ratio1)
    GUICtrlSetFont(-1, $aCtrl[10][1] * $g_iDPI_ratio1)
    $aCtrl[11][0] = GUICtrlCreateTabItem("One")
    GUICtrlSetTip(-1, '#Region TAB1')
    $aCtrl[12][2] = 244
    $aCtrl[12][3] = 35
    $aCtrl[12][4] = 140
    $aCtrl[12][5] = 24
    $aCtrl[12][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[12][0] = GUICtrlCreateLabel("Sample Tab with TabItems", $aCtrl[12][2] * $g_iDPI_ratio1, $aCtrl[12][3] * $g_iDPI_ratio1, $aCtrl[12][4] * $g_iDPI_ratio1, $aCtrl[12][5] * $g_iDPI_ratio1)
    GUICtrlSetFont(-1, $aCtrl[12][1] * $g_iDPI_ratio1)
    $aCtrl[13][0] = GUICtrlCreateTabItem("Two")
    GUICtrlSetTip(-1, '#Region TAB2')
    $aCtrl[14][0] = GUICtrlCreateTabItem("Three")
    GUICtrlSetTip(-1, '#Region TAB3')
    GUICtrlCreateTabItem("")
    #EndRegion TAB

    #Region COMBO
    $aCtrl[15][2] = 250
    $aCtrl[15][3] = 80
    $aCtrl[15][4] = 120
    $aCtrl[15][5] = 100
    $aCtrl[15][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[15][0] = GUICtrlCreateCombo("Sample Combo", $aCtrl[15][2] * $g_iDPI_ratio1, $aCtrl[15][3] * $g_iDPI_ratio1, $aCtrl[15][4] * $g_iDPI_ratio1, $aCtrl[15][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region COMBO')
    GUICtrlSetFont(-1, $aCtrl[15][1] * $g_iDPI_ratio1)
    #EndRegion COMBO

    #Region PROGRESS
    $aCtrl[16][2] = 60
    $aCtrl[16][3] = 80
    $aCtrl[16][4] = 150
    $aCtrl[16][5] = 20
    $aCtrl[16][0] = GUICtrlCreateProgress($aCtrl[16][2] * $g_iDPI_ratio1, $aCtrl[16][3] * $g_iDPI_ratio1, $aCtrl[16][4] * $g_iDPI_ratio1, $aCtrl[16][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region PROGRES')
    GUICtrlSetData(-1, 60)
    $aCtrl[17][2] = 5
    $aCtrl[17][3] = 82
    $aCtrl[17][4] = 50
    $aCtrl[17][5] = 18
    $aCtrl[17][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[17][0] = GUICtrlCreateLabel("Progress:", $aCtrl[17][2] * $g_iDPI_ratio1, $aCtrl[17][3] * $g_iDPI_ratio1, $aCtrl[17][4] * $g_iDPI_ratio1, $aCtrl[17][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region PROGRES - Label')
    GUICtrlSetFont(-1, $aCtrl[17][1] * $g_iDPI_ratio1)
    #EndRegion PROGRESS

    #Region EDIT
    $aCtrl[18][2] = 10
    $aCtrl[18][3] = 110
    $aCtrl[18][4] = 150
    $aCtrl[18][5] = 70
    $aCtrl[18][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[18][0] = GUICtrlCreateEdit(@CRLF & "  Sample Edit Control", $aCtrl[18][2] * $g_iDPI_ratio1, $aCtrl[18][3] * $g_iDPI_ratio1, $aCtrl[18][4] * $g_iDPI_ratio1, $aCtrl[18][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region EDIT')
    GUICtrlSetFont(-1, $aCtrl[18][1] * $g_iDPI_ratio1)
    #EndRegion EDIT

    #Region LIST
    $aCtrl[19][2] = 5
    $aCtrl[19][3] = 190
    $aCtrl[19][4] = 100
    $aCtrl[19][5] = 90
    $aCtrl[19][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[19][0] = GUICtrlCreateList("", $aCtrl[19][2] * $g_iDPI_ratio1, $aCtrl[19][3] * $g_iDPI_ratio1, $aCtrl[19][4] * $g_iDPI_ratio1, $aCtrl[19][5] * $g_iDPI_ratio1)
    GUICtrlSetFont(-1, $aCtrl[19][1] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region LIST')
    GUICtrlSetData(-1, "A.Sample|B.List|C.Control|D.Here", "B.List")
    #EndRegion LIST

    #Region ICON
    $aCtrl[20][2] = 175
    $aCtrl[20][3] = 120
    $aCtrl[20][4] = 32
    $aCtrl[20][5] = 32
    $aCtrl[20][0] = GUICtrlCreateIcon("explorer.exe", 0, $aCtrl[20][2] * $g_iDPI_ratio1, $aCtrl[20][3] * $g_iDPI_ratio1, $aCtrl[20][4] * $g_iDPI_ratio1, $aCtrl[20][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region ICON')
    $aCtrl[21][2] = 180
    $aCtrl[21][3] = 160
    $aCtrl[21][4] = 50
    $aCtrl[21][5] = 20
    $aCtrl[21][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[21][0] = GUICtrlCreateLabel("Icon", $aCtrl[21][2] * $g_iDPI_ratio1, $aCtrl[21][3] * $g_iDPI_ratio1, $aCtrl[21][4] * $g_iDPI_ratio1, $aCtrl[21][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region ICON - Label')
    GUICtrlSetFont(-1, $aCtrl[21][1] * $g_iDPI_ratio1)
    #EndRegion ICON

    #Region LIST VIEW
    $aCtrl[22][2] = 110
    $aCtrl[22][3] = 190
    $aCtrl[22][4] = 110
    $aCtrl[22][5] = 80
    $aCtrl[22][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[22][0] = GUICtrlCreateListView("Sample|ListView|", $aCtrl[22][2] * $g_iDPI_ratio1, $aCtrl[22][3] * $g_iDPI_ratio1, $aCtrl[22][4] * $g_iDPI_ratio1, $aCtrl[22][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region LIST VIEW')
    GUICtrlSetFont(-1, $aCtrl[22][1] * $g_iDPI_ratio1)
    GUICtrlCreateListViewItem("A|One", $aCtrl[22][0])
    GUICtrlCreateListViewItem("B|Two", $aCtrl[22][0])
    GUICtrlCreateListViewItem("C|Three", $aCtrl[22][0])
    #EndRegion LIST VIEW

    #Region GROUP WITH RADIO BUTTONS
    $aCtrl[23][2] = 230
    $aCtrl[23][3] = 120
    $aCtrl[23][4] = 110
    $aCtrl[23][5] = 80
    $aCtrl[23][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[23][0] = GUICtrlCreateGroup("Sample Group", $aCtrl[23][2] * $g_iDPI_ratio1, $aCtrl[23][3] * $g_iDPI_ratio1, $aCtrl[23][4] * $g_iDPI_ratio1, $aCtrl[23][5] * $g_iDPI_ratio1)
    GUICtrlSetFont(-1, $aCtrl[22][1] * $g_iDPI_ratio1)
    $aCtrl[24][2] = 250
    $aCtrl[24][3] = 140
    $aCtrl[24][4] = 80
    $aCtrl[24][5] = 32
    $aCtrl[24][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[24][0] = GUICtrlCreateRadio("Radio One", $aCtrl[24][2] * $g_iDPI_ratio1, $aCtrl[24][3] * $g_iDPI_ratio1, $aCtrl[24][4] * $g_iDPI_ratio1, $aCtrl[24][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region GROUP WITH RADIO BUTTONS- RADIO1')
    GUICtrlSetFont(-1, $aCtrl[24][1] * $g_iDPI_ratio1)
    GUICtrlSetState(-1, $GUI_CHECKED)
    $aCtrl[25][2] = 250
    $aCtrl[25][3] = 165
    $aCtrl[25][4] = 80
    $aCtrl[25][5] = 32
    $aCtrl[25][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[25][0] = GUICtrlCreateRadio("Radio Two", $aCtrl[25][2] * $g_iDPI_ratio1, $aCtrl[25][3] * $g_iDPI_ratio1, $aCtrl[25][4] * $g_iDPI_ratio1, $aCtrl[25][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region GROUP WITH RADIO BUTTONS- RADIO2')
    GUICtrlSetFont(-1, $aCtrl[25][1] * $g_iDPI_ratio1)
    GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
    #EndRegion GROUP WITH RADIO BUTTONS

    #Region UPDOWN
    $aCtrl[26][2] = 350
    $aCtrl[26][3] = 113
    $aCtrl[26][4] = 40
    $aCtrl[26][5] = 12
    $aCtrl[26][1] = 8 * $g_iDPI_ratio2
    $aCtrl[26][0] = GUICtrlCreateLabel("UpDown", $aCtrl[26][2] * $g_iDPI_ratio1, $aCtrl[26][3] * $g_iDPI_ratio1, $aCtrl[26][4] * $g_iDPI_ratio1, $aCtrl[26][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region UPDOWN - Label')
    GUICtrlSetFont(-1, $aCtrl[26][1] * $g_iDPI_ratio1)
    $aCtrl[27][2] = 350
    $aCtrl[27][3] = 130
    $aCtrl[27][4] = 40
    $aCtrl[27][5] = 20
    $aCtrl[27][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[27][0] = GUICtrlCreateInput("42", $aCtrl[27][2] * $g_iDPI_ratio1, $aCtrl[27][3] * $g_iDPI_ratio1, $aCtrl[27][4] * $g_iDPI_ratio1, $aCtrl[27][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region UPDOWN - Input')
    GUICtrlSetFont(-1, $aCtrl[27][1] * $g_iDPI_ratio1)
    $aCtrl[28][0] = GUICtrlCreateUpdown(-1)
    GUICtrlSetTip(-1, '#Region UPDOWN - Updown')
    #EndRegion UPDOWN

    #Region LABEL
    $aCtrl[29][2] = 350
    $aCtrl[29][3] = 165
    $aCtrl[29][4] = 40
    $aCtrl[29][5] = 40
    $aCtrl[29][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[29][0] = GUICtrlCreateLabel("Green" & @CRLF & "Label", $aCtrl[29][2] * $g_iDPI_ratio1, $aCtrl[29][3] * $g_iDPI_ratio1, $aCtrl[29][4] * $g_iDPI_ratio1, $aCtrl[29][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region LABEL')
    GUICtrlSetBkColor(-1, 0x00FF00)
    GUICtrlSetFont(-1, $aCtrl[29][1] * $g_iDPI_ratio1)
    #EndRegion LABEL

    #Region SLIDER
    $aCtrl[30][2] = 235
    $aCtrl[30][3] = 215
    $aCtrl[30][4] = 40
    $aCtrl[30][5] = 16
    $aCtrl[30][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[30][0] = GUICtrlCreateLabel("Slider:", $aCtrl[30][2] * $g_iDPI_ratio1, $aCtrl[30][3] * $g_iDPI_ratio1, $aCtrl[30][4] * $g_iDPI_ratio1, $aCtrl[30][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region SLIDER - Label')
    GUICtrlSetFont(-1, $aCtrl[30][1] * $g_iDPI_ratio1)
    $aCtrl[31][2] = 270
    $aCtrl[31][3] = 210
    $aCtrl[31][4] = 120
    $aCtrl[31][5] = 30
    $aCtrl[31][0] = GUICtrlCreateSlider($aCtrl[31][2] * $g_iDPI_ratio1, $aCtrl[31][3] * $g_iDPI_ratio1, $aCtrl[31][4] * $g_iDPI_ratio1, $aCtrl[31][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region SLIDER')
    GUICtrlSetData(-1, 30)
    #EndRegion SLIDER

    #Region INPUT
    $aCtrl[32][2] = 235
    $aCtrl[32][3] = 255
    $aCtrl[32][4] = 130
    $aCtrl[32][5] = 20
    $aCtrl[32][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[32][0] = GUICtrlCreateInput("Sample Input Box", $aCtrl[32][2] * $g_iDPI_ratio1, $aCtrl[32][3] * $g_iDPI_ratio1, $aCtrl[32][4] * $g_iDPI_ratio1, $aCtrl[32][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region INPUT')
    GUICtrlSetFont(-1, $aCtrl[32][1] * $g_iDPI_ratio1)
    #EndRegion INPUT

    #Region DATE
    $aCtrl[33][2] = 5
    $aCtrl[33][3] = 280
    $aCtrl[33][4] = 200
    $aCtrl[33][5] = 20
    $aCtrl[33][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[33][0] = GUICtrlCreateDate("", $aCtrl[33][2] * $g_iDPI_ratio1, $aCtrl[33][3] * $g_iDPI_ratio1, $aCtrl[33][4] * $g_iDPI_ratio1, $aCtrl[33][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region DATE')
    GUICtrlSetFont(-1, $aCtrl[33][1] * $g_iDPI_ratio1)
    $aCtrl[34][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[34][2] = 10
    $aCtrl[34][3] = 305
    $aCtrl[34][4] = 200
    $aCtrl[34][5] = 20
    $aCtrl[34][0] = GUICtrlCreateLabel("(Date control expands into a calendar)", $aCtrl[34][2] * $g_iDPI_ratio1, $aCtrl[34][3] * $g_iDPI_ratio1, $aCtrl[34][4] * $g_iDPI_ratio1, $aCtrl[34][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region DATE - Label')
    GUICtrlSetFont(-1, $aCtrl[34][1] * $g_iDPI_ratio1)
    #EndRegion DATE

    #Region BUTTON
    $aCtrl[35][2] = 10
    $aCtrl[35][3] = 330
    $aCtrl[35][4] = 100
    $aCtrl[35][5] = 30
    $aCtrl[35][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[35][0] = GUICtrlCreateButton("Click me :-)", $aCtrl[35][2] * $g_iDPI_ratio1, $aCtrl[35][3] * $g_iDPI_ratio1, $aCtrl[35][4] * $g_iDPI_ratio1, $aCtrl[35][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region BUTTON')
    GUICtrlSetFont(-1, $aCtrl[35][1] * $g_iDPI_ratio1)
    #EndRegion BUTTON

    #Region CHECKBOX
    $aCtrl[36][2] = 130
    $aCtrl[36][3] = 335
    $aCtrl[36][4] = 80
    $aCtrl[36][5] = 20
    $aCtrl[36][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[36][0] = GUICtrlCreateCheckbox("Checkbox", $aCtrl[36][2] * $g_iDPI_ratio1, $aCtrl[36][3] * $g_iDPI_ratio1, $aCtrl[36][4] * $g_iDPI_ratio1, $aCtrl[36][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region CHECKBOX')
    GUICtrlSetState(-1, $GUI_CHECKED)
    GUICtrlSetFont(-1, $aCtrl[36][1] * $g_iDPI_ratio1)
    #EndRegion CHECKBOX

    #Region TREEVIEW ONE
    $aCtrl[37][2] = 210
    $aCtrl[37][3] = 290
    $aCtrl[37][4] = 80
    $aCtrl[37][5] = 80
    $aCtrl[37][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[37][0] = GUICtrlCreateTreeView($aCtrl[37][2] * $g_iDPI_ratio1, $aCtrl[37][3] * $g_iDPI_ratio1, $aCtrl[37][4] * $g_iDPI_ratio1, $aCtrl[37][5] * $g_iDPI_ratio1)
    GUICtrlSetTip(-1, '#Region TREEVIEW ONE')
    GUICtrlSetFont(-1, $aCtrl[37][1] * $g_iDPI_ratio1)
    $aCtrl[38][0] = GUICtrlCreateTreeViewItem("TreeView", $aCtrl[37][0])
    GUICtrlCreateTreeViewItem("Item1", $aCtrl[38][0])
    GUICtrlCreateTreeViewItem("Item2", $aCtrl[38][0])
    GUICtrlCreateTreeViewItem("Foo", -1)
    GUICtrlSetState($aCtrl[38][0], $GUI_EXPAND)
    #EndRegion TREEVIEW ONE

    #Region TREEVIEW TWO
    $aCtrl[39][2] = 295
    $aCtrl[39][3] = 290
    $aCtrl[39][4] = 103
    $aCtrl[39][5] = 80
    $aCtrl[39][1] = 8.5 * $g_iDPI_ratio2
    $aCtrl[39][0] = GUICtrlCreateTreeView($aCtrl[39][2] * $g_iDPI_ratio1, $aCtrl[39][3] * $g_iDPI_ratio1, $aCtrl[39][4] * $g_iDPI_ratio1, $aCtrl[39][5] * $g_iDPI_ratio1, $TVS_CHECKBOXES)
    GUICtrlSetTip(-1, '#Region TREEVIEW TWO')
    GUICtrlSetFont(-1, $aCtrl[39][1] * $g_iDPI_ratio1)
    GUICtrlCreateTreeViewItem("TreeView", $aCtrl[39][0])
    GUICtrlCreateTreeViewItem("With", $aCtrl[39][0])
    GUICtrlCreateTreeViewItem("$TVS_CHECKBOXES", $aCtrl[39][0])
    GUICtrlSetState(-1, $GUI_CHECKED)
    GUICtrlCreateTreeViewItem("Style", $aCtrl[39][0])
    #EndRegion TREEVIEW TWO

    #Region GUI MESSAGE LOOP
    GUISetState(@SW_SHOW)

    If @OSBuild > 9599 Then GUIRegisterMsg($WM_DPICHANGED, "WM_DPICHANGED") ;requires Win 8.1+ / Server 2012 R2+
    GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
    GUIRegisterMsg($WM_SIZE, "WM_SIZE")

    Local $hGUI_child, $hImage, $hGDIBitmap, $hGfx, $hPath, $hFamily, $hFormat, $tLayout, $hPen, $hBrush, $hB, $aGUIGetMsg
    _GDIPlus_Startup()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                _GDIPlus_PathDispose($hPath)
                _GDIPlus_PenDispose($hPen)
                _GDIPlus_BrushDispose($hBrush)
                _GDIPlus_FontFamilyDispose($hFamily)
                _GDIPlus_StringFormatDispose($hFormat)
                _GDIPlus_ImageDispose ($hImage)
                _GDIPlus_GraphicsDispose($hGfx)
                _GDIPlus_Shutdown()
                GUIRegisterMsg($WM_DPICHANGED, "")
                GUIRegisterMsg(WM_GETMINMAXINFO, "")
                GUIRegisterMsg(WM_SIZE, "")
                GUIDelete()
                Exit
            Case $aCtrl[35][0]
                If $hImage Then $hImage = _GDIPlus_ImageDispose($hImage)
                $hImage = _GDIPlus_BitmapCreateFromScan0($iw * $g_iDPI_ratio1, $ih * $g_iDPI_ratio1)
                If $hGfx Then _GDIPlus_GraphicsDispose($hGfx)
                $hGfx = _GDIPlus_ImageGetGraphicsContext($hImage)
                _GDIPlus_GraphicsSetTextRenderingHint($hGfx, $GDIP_TEXTRENDERINGHINTANTIALIAS)
                _GDIPlus_GraphicsSetSmoothingMode($hGfx, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
                _GDIPlus_GraphicsClear($hGfx, 0xFFF0F0F0)
                If $hPath Then _GDIPlus_PathDispose($hPath)
                $hPath = _GDIPlus_PathCreate()
                If $hFamily Then _GDIPlus_FontFamilyDispose($hFamily)
                $hFamily = _GDIPlus_FontFamilyCreate("Arial")
                If $hFormat Then _GDIPlus_StringFormatDispose($hFormat)
                $hFormat = _GDIPlus_StringFormatCreate()
                _GDIPlus_StringFormatSetAlign($hFormat, 1)
                _GDIPlus_StringFormatSetLineAlign($hFormat, 1)
                $tLayout = _GDIPlus_RectFCreate(0, 0, $iw * $g_iDPI_ratio1, $ih * $g_iDPI_ratio1)
                _GDIPlus_PathAddString($hPath, "Hello World!", $tLayout, $hFamily, 0, 50 * $g_iDPI_ratio1, $hFormat)
                If $hPen Then _GDIPlus_PenDispose($hPen)
                $hPen = _GDIPlus_PenCreate(0xFF000000, 8)
                _GDIPlus_PenSetLineJoin($hPen, 2)
                _GDIPlus_GraphicsDrawPath($hGfx, $hPath, $hPen)
                If $hBrush Then _GDIPlus_BrushDispose($hBrush)
                $hBrush = _GDIPlus_BrushCreateSolid(0xFF00FF00)
                _GDIPlus_GraphicsFillPath($hGfx, $hPath, $hBrush)
                If $hGDIBitmap Then _WinAPI_DeleteObject($hGDIBitmap)
                $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
                Local $aGUI_Pos = WinGetPos($ahWnd[0][0])
                $ahWnd[1][0] = GUICreate("GDI+ Child Window", $iw * $g_iDPI_ratio1, $ih * $g_iDPI_ratio1, $aGUI_Pos[0] - ($aGUI_Pos[2] - $iw * $g_iDPI_ratio1) / 2, $aGUI_Pos[1] + $ih * $g_iDPI_ratio1 / 2, $WS_SIZEBOX, -1, $ahWnd[0][0])
                $aCtrl[40][2] = 0
                $aCtrl[40][3] = 0
                $aCtrl[40][4] = $iw
                $aCtrl[40][5] = $ih
                $aCtrl[40][0] = GUICtrlCreatePic("", $aCtrl[40][2], $aCtrl[40][3], $aCtrl[40][4] * $g_iDPI_ratio1, $aCtrl[40][5] * $g_iDPI_ratio1)
                _WinAPI_DeleteObject(GUICtrlSendMsg($aCtrl[40][0], $STM_SETIMAGE, $IMAGE_BITMAP, $hGDIBitmap))
                GUISetState(@SW_SHOW, $ahWnd[1][0])
                While 1
                    $aGUIGetMsg = GUIGetMsg(1)
                        Switch $aGUIGetMsg[1]
                            Case $ahWnd[1][0]
                                Switch $aGUIGetMsg[0]
                                    Case $GUI_EVENT_CLOSE
                                        GUIDelete($ahWnd[1][0])
                                        ExitLoop
                                EndSwitch
                        EndSwitch
                WEnd
        EndSwitch
    WEnd
    #EndRegion GUI MESSAGE LOOP

EndFunc   ;==>_Example

Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam, $lParam
    Switch $hWnd
        Case $ahWnd[1][0]
            Local $aSize = ControlGetPos($ahWnd[1][0], "", $aCtrl[40][0])
            $aCtrl[40][2] = $aSize[0]
            $aCtrl[40][3] = $aSize[1]
            $aCtrl[40][4] = _WinAPI_LoWord($lParam)
            $aCtrl[40][5] = _WinAPI_HiWord($lParam)
            GUICtrlSetPos($aCtrl[40][0], $aCtrl[40][2], $aCtrl[40][3], $aCtrl[40][4], $aCtrl[40][5])
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

Func WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam)
    If $hWnd = $ahWnd[1][0] Then
        Local $minmaxinfo = DllStructCreate("long ptReservedX;long ptReservedY;long ptMaxSizeX; long ptMaxSizeY;long ptMaxPositionX;long ptMaxPositionY;long ptMinTrackSizeX;long ptMinTrackSizeY;long ptMaxTrackSizeX;long ptMaxTrackSizeY  ", $lParam)
        $minmaxinfo.ptMinTrackSizeX = $iw / 2
        $minmaxinfo.ptMinTrackSizeY = $ih / 2
        $minmaxinfo.ptMaxTrackSizeX = $iw * 3
        $minmaxinfo.ptMaxTrackSizeY = $ih * 3
    EndIf
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_GETMINMAXINFO

Func WM_DPICHANGED($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg
    Local $iDPI = _WinAPI_LoWord($wParam)
    ConsoleWrite("DPI change triggered! DPI: " & $iDPI & @CRLF)
    $g_iDPI_ratio1 = $iDPI / 96
    $g_iDPI_ratio2 = $g_iDPI_ratio1 ^ -1
    Local $tRECT = DllStructCreate($tagRECT, $lParam)
    Local $iX = $tRECT.left, $iY = $tRECT.top, $iW = $tRECT.right - $iX, $iH = $tRECT.bottom - $iY, $i
    Switch $hWnd
        Case $ahWnd[0][0]
            _WinAPI_SetWindowPos($ahWnd[0][0], 0, $iX, $iY, $iW, $iH, BitOR($SWP_NOZORDER, $SWP_NOACTIVATE))
            For $i = 0 To 39
                If $aCtrl[$i][1] Then GUICtrlSetFont($aCtrl[$i][0], $aCtrl[$i][1] * $g_iDPI_ratio1)
                If $aCtrl[$i][4] Then GUICtrlSetPos($aCtrl[$i][0], $aCtrl[$i][2] * $g_iDPI_ratio1, $aCtrl[$i][3] * $g_iDPI_ratio1, $aCtrl[$i][4] * $g_iDPI_ratio1, $aCtrl[$i][5] * $g_iDPI_ratio1)
            Next
            _WinAPI_UpdateWindow($ahWnd[0][0])
        Case $ahWnd[1][0]
            $i = 40
            _WinAPI_SetWindowPos($ahWnd[1][0], 0, $iX, $iY, $iW, $iH, BitOR($SWP_NOZORDER, $SWP_NOACTIVATE))
            GUICtrlSetPos($aCtrl[$i][0], $aCtrl[$i][2], $aCtrl[$i][3], $aCtrl[$i][4], $aCtrl[$i][5])
            _WinAPI_UpdateWindow($ahWnd[1][0])
    EndSwitch
    Return 1
EndFunc   ;==>WM_DPICHANGED

 

THX.

Edited by UEZ
UDF 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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...