4K window not the right size

Everything else that doesn't fall into one of the other PB categories.
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

4K window not the right size

Post by coco2 »

Does anyone know why this window is not half of a 4K screen? If I run this on my 4K screen it makes a window that is bigger than half of the screen

Code: Select all

OpenWindow(0, 0, 0, 3840/2, 2160/2, "Test 4K", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered)
Define event.i    
Repeat
  event = WaitWindowEvent(10)
Until event = #PB_Event_CloseWindow
I'm familiar with DPI aware but that makes no difference to me in this case. My screen is running at 150%.
User avatar
spikey
Enthusiast
Enthusiast
Posts: 769
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: 4K window not the right size

Post by spikey »

coco2 wrote: Sun May 19, 2024 11:59 am My screen is running at 150%.
When scaling isn't 100% you must account for this in your dimensions, because co-ordinates no longer correspond 1:1 with pixels, in your case the ratio is 1:1.5. The Desktop library contains commands to allow for this. Try this:

Code: Select all

ExamineDesktops()
Debug DesktopResolutionX()
Debug DesktopResolutionY()

W = (DesktopWidth(0)/2) / DesktopResolutionX()
H = (DesktopHeight(0)/2) / DesktopResolutionY()

OpenWindow(0, 0, 0, w, h, "Test 4K", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered)
Define event.i    
Repeat
  event = WaitWindowEvent(10)
Until event = #PB_Event_CloseWindow
Last edited by spikey on Sun May 19, 2024 12:33 pm, edited 1 time in total.
User avatar
blueb
Addict
Addict
Posts: 1116
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: 4K window not the right size

Post by blueb »

I have the same setup and it looks correct to me.

Here's what I use (I've blanked out the need to print a PDF sheet.)

Code: Select all

; -----------------------------------------------------------------------------
;           Name: ScreenSize.pb
;    Description:  see below
;         Author: Blueb
;           Date: 2023-03-23
; ---------------------------------------------------------------------------------------
; Needed - Needed a way to determine the optimum screen size for my six different monitors
;   Goal - Print a visual of the final result with desired screen measurements.
; ----------------------------------------------------------------------------------------
;XIncludeFile "PurePdfModule.pbi"

EnableExplicit
;filename
Global file$="ScreenSize.pdf"
Global Width.s, Height.s, ShowText.s
Global PdfHeight, PdfWidth


;- Enumerations
Enumeration Window
  #Window_0
EndEnumeration

Enumeration Gadgets
   #Txt_1
   #Txt_2
   #Txt_3
EndEnumeration

Enumeration Font
  #Font_0
EndEnumeration

;- Load Fonts
LoadFont(#Font_0, "Arial", 16)

;- Declare
Declare Resize_Window_0()
Declare Open_Window_0(X = 0, Y = 0, Width = 800, Height = 1280)

Procedure Resize_Window_0()
  Protected ScaleX.f, ScaleY.f, Width.s, Height.s, ShowText.s
  Static Window_0_WidthIni, Window_0_HeightIni
  If Window_0_WidthIni = 0
    Window_0_WidthIni = WindowWidth(#Window_0) : Window_0_HeightIni = WindowHeight(#Window_0)
  EndIf

  Width.s = Str(WindowWidth(#Window_0))
  Height.s = Str(WindowHeight(#Window_0))
  PdfHeight = WindowHeight(#Window_0)
  PdfWidth = WindowWidth(#Window_0)
  ShowText.s = Width + " X " + Height
  SetGadgetText(#Txt_1, ShowText)
;
EndProcedure

Procedure Open_Window_0(X = 0, Y = 0, Width = 800, Height = 1280)
   Define.s DesiredText.s
  If OpenWindow(#Window_0, X, Y, Width, Height, "Title", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
     SetWindowColor(#Window_0, $AED8EE)
   
    TextGadget(#Txt_1, 300, 10, 200, 40, "Text_1", #PB_Text_Center | #SS_CENTERIMAGE)
      SetGadgetColor(#Txt_1, #PB_Gadget_FrontColor, $FF0000)
      SetGadgetColor(#Txt_1, #PB_Gadget_BackColor, $FFFFFF)
      SetGadgetFont(#Txt_1, FontID(#Font_0))
      
      EditorGadget(#Txt_2, 10, 80, 780, 240, #PB_Editor_ReadOnly|#PB_Editor_WordWrap)
      DesiredText.s = "Many of us program for different monitors, and it gets hard to remember the best sizes for each monitor (I have 6 different setups)... so determining the best visual size for your forms on the actual monitor 'before' commiting to starting your form is a God send. No guessing involved!" + #CRLF$ + " " + #CRLF$
      DesiredText = DesiredText + "Just use the corner Grab handles to re-size screen to suit your actual monitor, then a PDF will be created on exit. You can print it, if you desire."+ #CRLF$ + " " + #CRLF$
      DesiredText = DesiredText + "It's simple, but effective!"
       AddGadgetItem(#Txt_2, 1, DesiredText)
          SetGadgetColor(#Txt_2, #PB_Gadget_FrontColor, $FF0000)
          SetGadgetColor(#Txt_2, #PB_Gadget_BackColor, $FFFFFF)
         SetGadgetFont(#Txt_2, FontID(#Font_0))  
       TextGadget(#Txt_3, 80, 20, 200, 40, "Current Screen Size:", #PB_Text_Right) 
          SetGadgetColor(#Txt_3, #PB_Gadget_FrontColor, $FF0000)
          SetGadgetColor(#Txt_3, #PB_Gadget_BackColor,  $AED8EE)
         SetGadgetFont(#Txt_3, FontID(#Font_0))      
         
         
    BindEvent(#PB_Event_SizeWindow, @Resize_Window_0(), #Window_0)
    PostEvent(#PB_Event_SizeWindow, #Window_0, 0)

    WindowBounds(#Window_0, 100, 100, #PB_Ignore, #PB_Ignore)
 

  EndIf
EndProcedure

CompilerIf (#PB_Compiler_IsMainFile)
;- Main Program
Open_Window_0()

;- Event Loop
Repeat
   Select WaitWindowEvent()

     Case #PB_Event_CloseWindow
;           ;-----[ Make PDF file on Exit]-----
;              If PDF::Create()
;                 PDF::AddPage()
;                 PDF::SetFillColor(255,255,255)    
;                 PDF::RoundRect(10,10,75,75,5,PDF::#STYLE_DRAWANDFILL) 
;                    PDF::SetFont("Arial","",20)
;                    PDF::Text(90,50,Str(PdfHeight) + " Pixels High") ;Height
;                    PDF::Text(25,100,Str(PdfWidth) + " Pixels Wide") ;Width                 
;                 PDF::Save(file$)
;              EndIf 
;              RunProgram(file$)
         ;-----[ End of PDF ]-----     
      Break

      ;-> Event Gadget
    Case #PB_Event_Gadget
       Select EventGadget()

      EndSelect

  EndSelect
ForEver
CompilerEndIf


HTH
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
spikey
Enthusiast
Enthusiast
Posts: 769
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: 4K window not the right size

Post by spikey »

blueb wrote: Sun May 19, 2024 12:33 pm ; my six different monitors
:shock: :D
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: 4K window not the right size

Post by coco2 »

Thanks everyone, I made a silly mistake, I was storing the DesktopResolution as an integer. I changed it to a double and it's fixed :oops:
Post Reply