[SOLVED] OpenWindow() with dimensions greater than screen size

Windows specific forum
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

[SOLVED] OpenWindow() with dimensions greater than screen size

Post by PBJim »

I found with some testing, that if a PureBasic Windows application has been designed with larger monitor size requirements in mind, but is executed on a system with a smaller monitor, say for instance on a 1280 x 1024, it automatically reduces the window size to the monitor's dimensions. This can mean that any gadgets drawn outside that resized area, do not appear.

Is there a way to ensure that a window retains its pre-set size and therefore be moved around to reveal its full extent, instead of being reduced in size? This requirement is for software demonstration purposes, where the user's system has a small monitor 1280 x 1024. Therefore it isn't important to us if the window does not fit entirely into the monitor's dimensions, because we can grab the title bar and move it around, to reveal the section we want to view.

What I remember happening in the past, when monitors were of smaller dimensions, is that Windows O/S only showed a portion of the window on the monitor. That was not PureBasic, but certain applications I recall, in the days of the VGA monitors. Can that behaviour be reproduced?

Code: Select all

win.i = OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, 1920, 1080, "Test", #PB_Window_MinimizeGadget | #PB_Window_SystemMenu)

TextGadget(#PB_Any, 30, 30, 160, 25, "Item ref.")

pcode.i  = StringGadget(#PB_Any, 140, 25, 140, 25, "")
exitbutton.i = ButtonGadget(#PB_Any, 30, 160, 100, 25, "Exit")

SetActiveGadget(pcode.i)

Repeat
  event = WaitWindowEvent()

  Select event
      
    Case #PB_Event_CloseWindow
      Break
      
    Case #PB_Event_Gadget
      
      Select EventGadget()

          ; **
          ; **  Exit button
          ; **
        Case exitbutton.i
          Break
          
      EndSelect
  EndSelect

ForEver

CloseWindow(win.i)

End
Last edited by PBJim on Mon Nov 18, 2024 3:23 pm, edited 1 time in total.
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: OpenWindow() with dimensions greater than screen size

Post by PBJim »

Thought I'd add to this, on seeing jak64's post also about desktop resolution. Below is a simpler description of what I'm looking for.

Our application is designed for a modern wider geometry VDU but I need to give a demo on a user's smaller screen. Is there a way to make the PB window retain its geometry, rather than the automatic resizing that seems to happen? If this is possible, then at least we could 'pan' the window from left to right by moving the title bar, to give the client a reasonable demo. I'm fairly sure I've seen other Windows apps that behave in this way on a small monitor. Thanks for any help if you know the answer.

Image
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: OpenWindow() with dimensions greater than screen size

Post by breeze4me »

The maximum size of a window seems to be set to roughly the size of the virtual screen(GetSystemMetrics_(#SM_CXVIRTUALSCREEN), GetSystemMetrics_(#SM_CYVIRTUALSCREEN)), so you can use the WindowBounds() command to set the size of the window beyond that limit.

Code: Select all

win.i = OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, 1920, 1080, "Test", #PB_Window_MinimizeGadget | #PB_Window_SystemMenu)
WindowBounds(win, 1920, 1080, #PB_Ignore, #PB_Ignore)

TextGadget(#PB_Any, 30, 30, 160, 25, "Item ref.")

pcode.i  = StringGadget(#PB_Any, 140, 25, 140, 25, "")
exitbutton.i = ButtonGadget(#PB_Any, 30, 160, 100, 25, "Exit")

SetActiveGadget(pcode.i)

Repeat
  event = WaitWindowEvent()

  Select event
      
    Case #PB_Event_CloseWindow
      Break
      
    Case #PB_Event_Gadget
      
      Select EventGadget()

          ; **
          ; **  Exit button
          ; **
        Case exitbutton.i
          Break
          
      EndSelect
  EndSelect

ForEver

CloseWindow(win.i)

End
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: OpenWindow() with dimensions greater than screen size

Post by PBJim »

breeze4me wrote: Sun Nov 17, 2024 8:19 am The maximum size of a window seems to be set to roughly the size of the virtual screen(GetSystemMetrics_(#SM_CXVIRTUALSCREEN), GetSystemMetrics_(#SM_CYVIRTUALSCREEN)), so you can use the WindowBounds() command to set the size of the window beyond that limit.

Code: Select all

WindowBounds(win, 1920, 1080, #PB_Ignore, #PB_Ignore)
Many thanks breeze4me, that's exactly what I was hoping for. I remembered I had seen it done before.

Yes, interesting GetSystemMetrics_(#SM_CXVIRTUALSCREEN) and GetSystemMetrics_(#SM_CYVIRTUALSCREEN) return 1920 x 1080 on my own desktop here, which made me realise why I was unable to see part of the lower section of a window on my 1366 x 768 laptop — it's because the window titlebar occupies a few pixels. Anyway, I appreciate your reply, really helpful.
User avatar
mk-soft
Always Here
Always Here
Posts: 6242
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: OpenWindow() with dimensions greater than screen size

Post by mk-soft »

The programme should be written in such a way that it also adapts to smaller monitors.
It is even worse if the programme remembers the window position and size.
Here I have, even with professional programmes, when I drive with the laptop to the construction site, the programme starts it moves to a non-existent monitor.
Tip: ALT key -> Left -> Down -> Move
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
DeanH
Enthusiast
Enthusiast
Posts: 274
Joined: Wed May 07, 2008 4:57 am
Location: Adelaide, South Australia
Contact:

Re: OpenWindow() with dimensions greater than screen size

Post by DeanH »

I have never been able to work out how a program can automatically resize / rescale all the windows and controls to adapt to different screen resolutions and scaling. That ability would be very useful.

Instead, I have set maximum window size to fit the smallest display my customers have.
Just over half have monitors set to 1920 x 1080 at 100% scaling.
A few are larger.
A lot are smaller or use higher scaling.
The next most common smaller size is 1366 x 768 at 100%. These are usually low-cost laptops.
Many laptops have scaling set to 125% or 150% "out of the box". I've even seen higher.
The smallest is 1024 x 768 at 100%. A few still have very old monitors.
I use this code to work out the useful width/height

Code: Select all

ExamineDesktops()
wd=DesktopWidth(0)
width=DesktopUnscaledX(wd)
hd=DesktopHeight(0)
height=DesktopUnscaledY(hd) - 48
;The taskbar height on Windows 11 is 46 pixels. On Windows 10 it is 40.
;I subtract 48 from height to get a useful vertical value.
I have set the maximum window size at 990 width and 690 height.
This just fits the old monitors.
It allows scaling up to 150% with 1920 x 1080.
The window just fits vertically on 1366 x 768 laptops at 100% only.

My system keeps track of the positions of 8 main windows.
Absolutely correct: keeping track of window positions can be a problem with multiple monitors. Leave one turned off or it has been removed and the window doesn't appear.
I haven't solved the "missing monitor" problem either.
I have included a "reset position" function on a dropdown menu that puts all the windows back to the centre of the main monitor.
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: OpenWindow() with dimensions greater than screen size

Post by PBJim »

DeanH wrote: Sun Nov 17, 2024 11:26 pm Just over half have monitors set to 1920 x 1080 at 100% scaling.
Thanks for the post DeanH, I haven't needed to consider screen resolution until now, because our legacy application only required a small amount of space.

A question please — when we talk about scaling here, are we talking about this slider setting below?

Image
Last edited by PBJim on Mon Nov 18, 2024 8:30 pm, edited 1 time in total.
BarryG
Addict
Addict
Posts: 4168
Joined: Thu Apr 18, 2019 8:17 am

Re: OpenWindow() with dimensions greater than screen size

Post by BarryG »

PBJim wrote: Fri Nov 15, 2024 4:39 pmIs there a way to ensure that a window retains its pre-set size and therefore be moved around to reveal its full extent, instead of being reduced in size?
I have this code whose original source I can't find now. May have been mine in conjunction with some other users here, but even a Google search doesn't find it. Anyway, maybe it helps your goal? I'm posting it as-is from my PureBasic code folder.

Code: Select all

; Microsoft Windows will auto-resize a window if it's larger than the
; Desktop height. So, this code forces a window to the height desired.

Global winheight=3072

Procedure RealWindowHeight(hWnd)
  GetWindowRect_(hWnd,@win.RECT)
  ProcedureReturn win\bottom-win\top
EndProcedure

Procedure WinCallBack(hWnd,Msg,wParam,lParam)
  Result=#PB_ProcessPureBasicEvents
  Select Msg
    Case #WM_GETMINMAXINFO
      *minmax.MINMAXINFO=lParam
      ;*minmax\ptMaxTrackSize\x=GetSystemMetrics_(#SM_CXMAXTRACK)+winwidth
      *minmax\ptMaxTrackSize\y=GetSystemMetrics_(#SM_CYMAXTRACK)+winheight
  EndSelect
  ProcedureReturn Result
EndProcedure

CreateImage(0,300,winheight)
StartDrawing(ImageOutput(0))
  Box(0,0,300,2,#Yellow)
  Box(0,winheight-2,300,2,#Yellow)
StopDrawing()

SetWindowCallback(@WinCallBack()) ; MUST go before window creation!

w=OpenWindow(0,0,0,300,winheight,"",#PB_Window_SystemMenu)
ImageGadget(0,0,0,300,3072,ImageID(0))
SetWindowTitle(0,Str(RealWindowHeight(w))+" <- This should be over 3072!")

Repeat
  ev=WaitWindowEvent()
  If ev=#PB_Event_Gadget
    p=1-p
    If p=0
      ResizeWindow(0,0,0,#PB_Ignore,#PB_Ignore)
    Else
      ResizeWindow(0,0,-400,#PB_Ignore,#PB_Ignore)
    EndIf
    While WindowEvent() : Wend
  EndIf
Until ev=#PB_Event_CloseWindow
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: OpenWindow() with dimensions greater than screen size

Post by PBJim »

BarryG wrote: Mon Nov 18, 2024 9:22 am I have this code whose original source I can't find now. May have been mine in conjunction with some other users here, but even a Google search doesn't find it. Anyway, maybe it helps your goal? I'm posting it as-is from my PureBasic code folder.
Thanks Barry, that's certainly worth keeping. I think we're going to be fine now anyway, because the WindowBounds() has done the job, or at least appears to on my own monitor. It's only for software demo on a 1280 x 1024 monitor anyway, so as long as I can move the wide window to reveal its hidden area, it will be fine.

I was planning to take my 25" monitor on the flight with me, but shan't be bothering now that I know about this WindowsBounds :D
Post Reply