News:

Function Finder  Find all the functions within source code files

Main Menu

GetWindowRect and GetClientRect

Started by kevin, October 03, 2022, 09:36:28 PM

Previous topic - Next topic

kevin


   GetWindowRect and GetClientRect




PlayBASIC Code: [Select]
  //  Scale 
OpenScreen 1600,960,32,1 ; open screen in 'window' mode

ScaleWindowToDeskTop()

loadfont "ariel",1, 45


do
cls

ShowClientArea()


print "Mouse POsition:"
print MouseX()
print MouseY()

Sync
loop spacekey()=true





type tWindow_RECT
X1,Y1
X2,Y2
endtype

linkdll "user32.dll"
SetWindowPos(hwnd,hWndInsertAfter,x,y,cx,cy,wFlags) alias "SetWindowPos" As integer
GetWindowRect(hwnd,RectPointer) alias "GetWindowRect" As integer
GetClientRect(hwnd,RectPointer) alias "GetClientRect" As integer

Endlinkdll



Function ScaleWindowToDeskTop()

// Get the Desk top width/height
dtw=GetDesktopWidth()
dth=GetDesktopHeight()*0.96

// Get the PB screens size
; w=GetScreenWidth()
; h=GetScreenHeight()

// Get the PB screens window Handle
hwnd=GetScreenHandle()

; Stretch the window to the size users display size
SetWindowPos(hwnd,hWndInsertAfter,0,0,dtw,dth,wFlags)

; Resize PB's GFX viewport to screens (the window) new client area
StretchGFXscreen

Endfunction



Function ShowClientArea()

Local Xpos =GetScreenXpos()
Local Ypos =GetScreenYpos()
Local Width =GetScreenWidth()
Local Height=GetScreenHeight()

local Handle=GetSCreenHandle()

dim Rect as TWindow_REct pointer
Rect = new tWindow_RECT


print "SCREEN SIZE:"
print Width
print Height
print ""



local Status= GetWindowREct(Handle, int(RECT))

if Status

print "Window RECT"
print Rect.X1
print Rect.Y1
print Rect.X2
print Rect.Y2
print ""

endif


local Status= GetClientREct(Handle, int(RECT))

if Status
print "Client RECT - area inside of window"
print Rect.X1
print Rect.Y1
print Rect.X2
print Rect.Y2
print ""
endif
free Rect

EndFunction X,Y



stevmjon

cool demo kev

so you're talking to the windows operating system using the winuser.h header?
is this accessed through the user32.dll?
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

kevin


Quoteso you're talking to the windows operating system using the winuser.h header?
is this accessed through the user32.dll?

  Yep..   Those .h files are header files used in the C/C++ world.   They're basically lists of declarations much like the LINKDLL block in the example above.   So the functions name is declared and it's parameters and what internal function it actually calls.  Which could be a different name. 

  The DLL is the compiled blob of code that these functions happen to live within.   These are made as shared libraries within windows so our programs can use the system provided functionality.



stevmjon

so 'user32.dll' is part of windows OS, found in C:\Windows\System32.

so could i open a second screen, and use it like a panel (eg. surface editor panel in my raytracer)?
this will save having the current surface editor 'panel' as only graphics inside the main screen.
could i make buttons too? (rubs hands together with evil laughter, dance windows dance...or explode).

i know playbasic has a gui, but i remember you saying not to use it anymore, as it doesn't run well on newer machines?
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

kevin


Quoteso 'user32.dll' is part of windows OS, found in C:\Windows\System32.

   Yep..  they're all the common part of windows

Quote
so could i open a second screen, and use it like a panel (eg. surface editor panel in my raytracer)?
this will save having the current surface editor 'panel' as only graphics inside the main screen.
could i make buttons too? (rubs hands together with evil laughter, dance windows dance...or explode).

    You can open a second window (there's an example(s) of that on the forums somewhere) but Windows are message / event based.  These require machine code call backs,  which you can't do from PB.  There might be a way around it, but i'm not too sure off the top of my in good old PB.

    Could possibly have a look at making a library that opens a second window.   


Quote
i know playbasic has a gui, but i remember you saying not to use it anymore, as it doesn't run well on newer machines?

   It's Windows GUI so there's nothing stopping it from functioning on newer editions of windows until they rip out legacy 32bit support.  It works but is problematic.   Hence why i've generally stuck to custom solutions.


kevin

#5
  Resize Screen / Resize Window

  Sometimes if the user resizes the window; we want to resize the PlayBASIC screen to the new client area;  but PB will just scale the existing screen size to the new distorted window.   

  But want if we wanted the manually scaled window to change the PlayBASIC screen ?  Well....  then we have to either use the ScreenLayout command or open a new screen.  This is the approach the code bellow takes; it's not without it's bumps and grinds mind you as we're potentially opening the screen again;  when will destroy the direct draw interface, but we can get something running.   

  The way it works is by monitoring the windows client area (size) each refresh; if it's different; then the user is probably dragging the window. SO we try and wait until the resizing has stopped;  then refresh the screen..  This can be a bit glitchy but works reasonably.  The Screen stretch while it's being dragged; nothing I can do about that.. 

  Have fun !

 
PlayBASIC Code: [Select]
linkdll "user32.dll"
SetWindowPos(hwnd,hWndInsertAfter,x,y,cx,cy,wFlags) alias "SetWindowPos" As integer
GetWindowRect(hwnd,RectPointer) alias "GetWindowRect" As integer
GetClientRect(hwnd,RectPointer) alias "GetClientRect" As integer
Endlinkdll



type tScreen_RECT
X,Y
WIDTH,HEIGHT
endtype


Type tScreen
ReSizeSTATUS
ReSizeLayout as tScreen_RECT
OLDReSizeLayout as tScreen_RECT
EndType

Dim Screen as tScreen
Screen=new tScreen


Function ResizeSYNC()

local Handle=GetSCreenHandle()

local Status= GetClientRect(Handle, int(SCreen.ResizeLayout))

if Status

// COmpute Width and Height of Client area of the PB Screen / Window
SCreen.ResizeLayout.Width -=SCreen.ResizeLayout.X
SCreen.ResizeLayout.Height -=SCreen.ResizeLayout.Y

if SCreen.OLDResizeLayout.Width
// Check if either are different ?
Flag =SCreen.OLDResizeLayout.Width<>SCreen.ResizeLayout.Width
Flag+=SCreen.OLDResizeLayout.Height<>SCreen.ResizeLayout.Height

if Flag
Screen.ReSizeSTATUS++
else
if Screen.ReSizeSTATUS>0
Screen.ReSizeSTATUS=0
Xpos=GetScreenXpos()
Ypos=GetScreenYpos()


// Handle Scaling down, with a Screen Layout

Bigger =GetSCreenWidth()>SCreen.ResizeLayout.Width
Bigger+=GetScreenHeight()>SCreen.ResizeLayout.Height
if Bigger>0
ScreenLayout 0,0,GetScreenWidth(),GetScreenHeight()
else
// if we make the screen bigger; we need to open a new window / screen
OPenScreen SCreen.ResizeLayout.Width,Screen.ResizeLayout.Height,GetScreenDepth(),GetScreenType()
positionScreen Xpos,Ypos
endif

SCreen.ResizeLayout.Width=0
SCreen.ResizeLayout.Height=0

endif
endif
endif
endif

SCreen.OldResizeLayout.Width = SCreen.ResizeLayout.Width
SCreen.OldResizeLayout.Height = SCreen.ResizeLayout.Height

Sync
ENdFunction





loadfont "ariel",1, 30

do
cls

circle 400,300,300,true

print "Resize screen"

print "Screen Size:"
print GetScreenWidth()
print GetScreenHeight()


print "Mouse POsition:"
print MouseX()
print MouseY()


ResizeSYNC()
loop spacekey()=true