Jump to content

ScreenResolutionOffSet


ptrex
 Share

Recommended Posts

ScreenResolutionOffSet

One of the most frustrating things in AU3, is still that the GUI and the controls don't adjust autmatically.

When run using diffenent Screen Resolutions on different machines.

Well this simple function can help :

Func ScreenResolutionOffSet()
$strComputer = "."

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

$colItems = $objWMIService.ExecQuery ("Select * From Win32_DisplayConfiguration")

For $objItem in $colItems
        $objItem.PelsWidth  
        $objItem.PelsHeight  
Next
    $Width =  $objItem.PelsWidth / $OffSetW
    $Height = $objItem.PelsHeight / $OffSetH
        Return String($Width & "|"  & $Height)
EndFuncoÝ÷ ØLZ^jëh×6#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <Color.au3>
#include <GuiMenu.au3>

;--------------------------------------- Main GUI Init ----------------------------------
; Resolution of the machine where the GUI is created on
Global $OffSetW = 1152
Global $OffSetH = 864

; Resolution OffSet factor
$OffSet = Stringsplit(ScreenResolutionOffSet(),"|")

;----------------------------------------- Main GUI ------------------------------------
$Width = 975 * $OffSet[1]
$Height = 770 * $OffSet[2]

$Gui = GuiCreate("Demo ScreenResolutionOffSet " , $Width, $Height,(@DesktopWidth-$Width)/2, (@DesktopHeight-$Height-35)/2 , _ 
$WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)


;----------------------------------------- ListView ------------------------------------
$ListView1 = GUICtrlCreateListView("Duplicate Files |Date |Size in Kb |MD5 Hash ", 10, 45, 957*$OffSet[1], 478*$OffSet[2],-1, BitOR($LVS_SHOWSELALWAYS,$LVS_REPORT)) 
GUICtrlSendMsg($listview1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_HEADERDRAGDROP, $LVS_EX_HEADERDRAGDROP) ;Drag & Drop 
GUICtrlSendMsg($listview1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlSendMsg($listview1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_TRACKSELECT, $LVS_EX_TRACKSELECT)
GUICtrlSetImage($ListView1, "compstui.dll", -15)
GUICtrlSetResizing ($ListView1,$GUI_DOCKAUTO)
_GUICtrlListView_SetColumnWidth ($ListView1, 0,600) 
_GUICtrlListView_SetColumnWidth ($ListView1, 3,300)
_GUICtrlListView_SetHoverTime ($ListView1,500) ; Set Hoover to x Sec.

$ListView2 = GUICtrlCreateListView("Related Duplicate Files |Date |Size in Kb |MD5 Hash ", 10, 530*$OffSet[2], 957*$OffSet[1], 200*$OffSet[2],-1,$LVS_REPORT)
GUICtrlSendMsg($listview1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_HEADERDRAGDROP, $LVS_EX_HEADERDRAGDROP) ; Drag & Drop 
GUICtrlSendMsg($listview1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlSetImage($ListView2, "compstui.dll", -16)
GUICtrlSetResizing ($ListView2,$GUI_DOCKAUTO)
_GUICtrlListView_SetColumnWidth ($ListView2, 0,600) 
_GUICtrlListView_SetColumnWidth ($ListView2, 3,300)

;------------------------------------ Labels -------------------------------------------
$Progressbar1 = GUICtrlCreateProgress (167*$OffSet[1],732*$OffSet[2],800*$OffSet[1],15*$OffSet[2])
GUICtrlSetColor(-1,32250) ; not working with Windows XP Style

$ProgressLabel = GUICtrlCreateLabel("Processing MD5 Checksum : ",10 ,732*$OffSet[2] ,155*$OffSet[1],15*$OffSet[2])
$PathLabel = GUICtrlCreateLabel("Reading Files : ",10 ,750*$OffSet[2] ,695*$OffSet[1],18*$OffSet[2],$SS_SUNKEN)
$TimeLabel = GUICtrlCreateLabel("Time Elapsed : ",710*$OffSet[1] ,750*$OffSet[2] ,135*$OffSet[1],18*$OffSet[2],$SS_SUNKEN)
$VersionLabel = GUICtrlCreateLabel("MD5 Version - 1.1.0",850*$OffSet[1] ,750*$OffSet[2] ,120*$OffSet[1],18*$OffSet[2],$SS_SUNKEN)

;------------------------------------ Menu ---------------------------------------------
Dim $sPath = @MyDocumentsDir
$sShortPath = StringSplit($sPath,"\")

$nFileMenu1     = GUICtrlCreateMenu(" &Open")
$nFileSelFolder1= GUICtrlCreateMenuItem("Select Folder ...",$nFileMenu1)
GUICtrlSetState(-1,$GUI_DEFBUTTON)
$nFileSelFolder2= GUICtrlCreateMenuItem("Export to File",$nFileMenu1)
$nFileSelFolder0= GUICtrlCreateMenuItem("",$nFileMenu1)
;$nFileSelFolder3 = GUICtrlCreateMenuItem($sShortPath[1]&"\ ...\" & $sShortPath[$sShortPath[0]]  ,$nFileMenu1)

$nFileMenu2     = GUICtrlCreateMenu("&Info")
$nFileSelFolderH= GUICtrlCreateMenuItem("Help" ,$nFileMenu2)
$nFileSelFolderA= GUICtrlCreateMenuItem("About ...",$nFileMenu2)

;------------------------------------ Button -------------------------------------------
$bScan = GuiCtrlCreateButton("Scan ...", 10, 2, 40, 40, BitOr($BS_BOTTOM,$BS_ICON))
GUICtrlSetImage ($bScan, "shell32.dll",-219)

;------------------------------------- Input --------------------------------------------
$Group = GUICtrlCreateGroup("Filters ", 100, 5, 400*$OffSet[1], 30*$OffSet[2])
$sExtention = GUICtrlCreateLabel("File Extention : ",110 ,18 ,80*$OffSet[1],15*$OffSet[2])
$iFileSizeRnd = GUICtrlCreateLabel("File Size in Kb : ",270 ,18 ,70 ,15)
$sFilter = GUICtrlCreateInput ("*", 200,  14, 40*$OffSet[1], 17*$OffSet[2])
GUICtrlSetTip($sFilter,"Extention like PDF, ZIP, EXE, ... ")
$sSize = GUICtrlCreateInput ("0", 350, 14, 60*$OffSet[1], 17*$OffSet[2])
GUICtrlSetTip($sSize,"Input a Size number to filter on ... ")


;-------------------------------------- Group -------------------------------------------
$Group = GUICtrlCreateGroup("Statistics ", 620, 5, 300*$OffSet[1], 30*$OffSet[2])
$ItemsCnt = GUICtrlCreateLabel("Duplicate Items : 0" , 630, 18, 160*$OffSet[1], 15*$OffSet[2])
$FilesCnt = GUICtrlCreateLabel("Number of Files Processed : 0" , 745, 18, 170*$OffSet[1], 15*$OffSet[2])


;-------------------------------------- Init -----------------------------------------
$Size = WinGetClientSize($Gui)

;GUI handling
;------------
GuiSetState()

While 1
    $nMsg = GUIGetMsg()
Switch $nMsg
    Case $GUI_EVENT_CLOSE
        Exit
    Case $nFileSelFolder1
        $MenuPath = FileSelectFolder("Select a Folder to Scan ...", "", "", $sPath)
    
    Case $nFileSelFolderH
        Help()
    Case $nFileSelFolderA
        About()
    EndSwitch
WEnd

Func Help()
    MsgBox(64,"Help info", _
                "IMPORTANT : Read this " & @CRLF )
EndFunc

Func About()
MsgBox(64,"About info", _
                "About me " & @CRLF )
EndFunc

Func ScreenResolutionOffSet()
$strComputer = "."

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

$colItems = $objWMIService.ExecQuery ("Select * From Win32_DisplayConfiguration")

For $objItem in $colItems
        $objItem.PelsWidth  
        $objItem.PelsHeight  
Next
    $Width =  $objItem.PelsWidth / $OffSetW
    $Height = $objItem.PelsHeight / $OffSetH
        Return String($Width & "|"  & $Height)
EndFunc

If some has a better approach let us know.

Enjoy!!

regards

ptrex

Link to comment
Share on other sites

Instead of $offset[1] and $offset[2] why not have

$ScaleX = @DesktopWidth/$OffSetW

$scaleY = @DesktopHeight/$OffsetH

?

It would seem simpler, or am I missing something?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

$ScaleX = @DesktopWidth/$OffSetW

$scaleY = @DesktopHeight/$OffsetH

I used this solution.

There is a scale to resize font??

Edited by Fabry
A lan chat (Multilanguage)LanMuleFile transferTank gameTank 2 an online game[center]L'esperienza è il nome che tutti danno ai propri errori.Experience is the name everyone gives to their mistakes.Oscar Wilde[/center]
Link to comment
Share on other sites

I used this solution.

There is a scale to resize font??

You could try

$fontsize = Floor($baseFontSize * $scaleY)

It might work, I used a similar idea for a rich edit once where I wanted to show it scaled and that worked ok. (I know you can zoom rich edits but I can't remember why I didn't do that.)

I suppose that to set the text size correctly you should have a little function that makes calls to the GetTextMetrics or GetTextExtentPoint32 in gdi32.dll, and adjust the font until it is within a required range.

EDIT: \spelling plus addition below.

@Ptrex

I am probably going bacwards here but maybe the most useful dimensions are the working area. Various people have posted methods for getting this. Here is the first one I found.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Martin, how can you zoom rich edits?

ptrex, this will come in handy like others of yours!

Look up the messages EM_SETZOOM, EM_GETZOOM.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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