|
This is a small collection of mostly game example source codes. These source codes are made available to help PlayBasic programmers kick start their game programming journey.
Looking for more source code / tutorials & media, then remember to visit the PlayBasic Resource board on our forums.
Found #1 item in WinAPI category
Windows API GetWindowRect GetClientRect
|
By: Kevin Picone Added: October 3rd, 2022
|
Category: All,Windows,WinAPI,Screen
|
GetWindowRect and GetClientRect
GetWindowRect is a function in the Windows API that retrieves the dimensions of the bounding rectangle of a window. It takes a handle to the window as an input parameter and returns the dimensions of the window in a RECT structure, which contains the left, top, right, and bottom coordinates of the rectangle.
GetClientRect is a similar function that retrieves the dimensions of the client area of a window. The client area is the part of the window where the application can draw and is typically smaller than the full window because it excludes the title bar and other non-client elements. Like GetWindowRect, GetClientRect takes a handle to the window as an input parameter and returns the dimensions of the client area in a RECT structure.
Both functions are useful for getting the dimensions of a window or client area, which can be used to position controls within the window or to resize the window to fit its contents. They can be called from any application that has a handle to the window, whether it is the application that created the window or another application.
// 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
|
|
|
Viewing Page [1] of [0]
Want More Source Codes?:
Release Type:
The source code & tutorials found on this site are released as license ware for PlayBasic Users. No Person or Company may redistribute any file (tutorial / source code or media files) from this site, without explicit written permission.
|
|