|
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 #4 items in Screen 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
|
|
|
Retrieve list of PlayBasic screen modes
|
By: Adrian Nelson (AdeN) Added: September 20th, 2007
|
Category: All,Screen
|
Hi, This code (see attached file) will populate an array with the width, height and bits per pixel (bpp) of all the supported PlayBasic screen modes that are available on the PC. You can also specify a minimum width, height and bpp that you want returned, for example: GetScreens(800, 600, 0) - will return a list of all screen modes that are 800 x 600 pixels or larger. GetScreens(0, 0, 32) - will return a list of all screen modes that support 32 bpp I have also attached a small screenshot that shows all of the 32 bpp modes on my laptop - from 320 x 200 all the way up to 1440 x 900 You may be wondering why you should care - surely 800 x 600 fullscreen is available on all PCs? Well quite often it is, however on a widescreen display this gets stretched to fill the screen and all of your carefully created graphics get distorted as a result. So it would be better to try and match the aspect ratio of the possible screen modes to the returned list. Also, you can then allow the user to select the screen size to run the game at knowing that you are only offering them the screen modes that you want them to be able to pick from. I hope that you find this of use in your own games/applications.
|
|
|
Download:
Login to Download
|
|
Screen Styles
|
By: Kevin Picone Added: January 30th, 2007
|
Category: All,Screen,Graphics
|
This codes gives you a way to change the default PlayBasic screen style. (Windowed mode only). You need to be careful when changing the style though, as some settings will make your program none operational! - But ya get that !
|
|
Download:
Login to Download
|
|
Viewing Page [1] of [1]
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.
|
|