Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login

POZE MRRRR'S FORUM (VIEW ONLY)

Nu sunteti logat.
Nou pe simpatie:
Tanya321 la Simpatie.ro
Femeie
19 ani
Giurgiu
cauta Barbat
27 - 63 ani
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides / [VBS] Resize HTA Window On Load Depending on Screen Resolution Moderat de TRaP, TonyTzu
Autor
Mesaj Pagini: 1
TRaP
Moderator

Inregistrat: acum 7 ani
Postari: 836
On a different resolution screen, a HTA that fits perfectly on my laptop would not fit very well, text would be covered by margins.

This goes right after the <head></head> tags:


<script LANGUAGE="VBScript">
Sub Window_onLoad
If Window.Screen.availWidth < 1800 Then
    window.resizeTo 720,640
End If
   
If Window.Screen.availWidth > 1800 Then
    window.resizeTo 820,700
End If
End Sub
</script>


pus acum 2 ani
   
TRaP
Moderator

Inregistrat: acum 7 ani
Postari: 836
Adding the "Sub" around the resize options doesn't really work well sometimes.

Simpler code like below, added before the <HTA> tag is recommended


<script language="VBScript">
    resizeTo 950,810     ' W, H
    moveTo 100,25         ' from left, from top
</script>


Source:


pus acum 3 luni
   
TRaP
Moderator

Inregistrat: acum 7 ani
Postari: 836
Updated, since on this laptop I have a different resolution larger than 1080p and scaling larger than 100%, I need updated code.

The code below reads resolution of primary monitor and reads DPI from the registry then decides proper resolution.
The "problem" seems to actually be the scaling and not the resolution.


<!-- RESIZE SHOULD ALWAYS BE BEFORE THE HTA:APPLICATION TAGS, BECAUSE THAT SETS THE DEFAULT SIZE -->
<script language="VBScript">

Set shell = CreateObject("WScript.Shell")
Set wmi = GetObject("winmgmts:\\.\root\cimv2")
Set monitors = wmi.ExecQuery("Select * from Win32_DesktopMonitor Where Availability = 3")

' Get screen resolution from WMI
For Each monitor In monitors
  width = monitor.ScreenWidth
  height = monitor.ScreenHeight
  Exit For ' Primary monitor only
Next

' Try to read DPI setting from registry
On Error Resume Next
dpi = shell.RegRead("HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\AppliedDPI")
If Err.Number <> 0 Then
    dpi = 96 ' default DPI
    Err.Clear
End If
On Error GoTo 0

' Convert DPI to scale percent
Select Case dpi
    Case 96: scalePercent = "100%"
    Case 120: scalePercent = "125%"
    Case 144: scalePercent = "150%"
    Case 168: scalePercent = "175%"
    Case 192: scalePercent = "200%"
    Case Else: scalePercent = "Unknown (" & dpi & ")"
End Select

'MsgBox "Resolution: " & width & "x" & height & vbCrLf & "Scaling: " & scalePercent

If width > 1920 and dpi = 120 Then
    resizeTo 1200,1000     ' W x H
    moveTo 100,25         ' from left, from top

Else
    resizeTo 1300,1200     ' W x H
    moveTo 100,25         ' from left, from top
End If

</script>
<!-- RESIZE SHOULD ALWAYS BE BEFORE THE HTA:APPLICATION TAGS, BECAUSE THAT SETS THE DEFAULT SIZE -->



Source: ChatGPT


pus acum 2 luni
   
TRaP
Moderator

Inregistrat: acum 7 ani
Postari: 836
In another case, I simplified the macro above greatly by finding the proper resolution based percentage scaling for both monitors I have.

The same works fine for both 2048x1280, at a scale of 125%, and 1920x1080 at a scale of 100%.

<!-- RESIZE SHOULD ALWAYS BE BEFORE THE HTA:APPLICATION TAGS, BECAUSE THAT SETS THE DEFAULT SIZE -->
<script language="VBScript">
    screenW = window.screen.availWidth
    screenH = window.screen.availHeight

    targetW = Int(screenW * 0.325)     ' 32,5% width
    targetH = Int(screenH * 0.72)     ' 72% height

    window.resizeTo targetW, targetH
</script>
<!-- RESIZE SHOULD ALWAYS BE BEFORE THE HTA:APPLICATION TAGS, BECAUSE THAT SETS THE DEFAULT SIZE -->


Additionally, I created a Subroutine with the exact above contents and named it ResizeHTA(), then added a button on top of my HTA window so the user can click it to resize the window - as it cannot happen automatically on moving the HTA window to a new monitor, so I am entrusting the end user to click the button to resize the HTA window.


Sub ResizeHTA()
    Dim screenW, screenH, targetW, targetH
    screenW = window.screen.availWidth
    screenH = window.screen.availHeight

    targetW = Int(screenW * 0.325)     ' 32,5% width
    targetH = Int(screenH * 0.72)     ' 72% height

    window.resizeTo targetW, targetH
    'window.moveTo (screenW - targetW) \ 2, (screenH - targetH) \ 2
End Sub

Redim button:

<input type="button" onclick="ResizeHTA()" value="Resize
window" style="background-color: PaleTurquoise; width: 100px; height: 50px;" >


pus acum 3 saptamani
   
Mrrrr
AdMiN

Inregistrat: acum 18 ani
Postari: 2260
Tried the codes above on a new PC with 2 monitors, both 1080p and the width was larger than on the 1080p monitor at work, and the height a bit smaller.

Changed the approach once more and this seems to work fine on any computer.

TBA


_______________________________________


pus acum 3 saptamani
   
Pagini: 1  

Mergi la