TGC Codebase Backup



set display mode to change res to window size when window resized by the_winch

14th Sep 2003 5:36
Summary

uses a set display mode to change the display mode to match the window resolution to the window size when the window is resized



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `v0.2 now works much better on minimising and maximising, a maximised window will still
`stretch slightly as you can't set the display mode to the desktop width in a window
sync on : disable escapekey

global pos_x as integer  : `x position of window
global pos_y as integer  : `y position of window
global size_x as integer : `x size of window
global size_y as integer : `y size of window
global old_x as integer
global old_y as integer
global desk_x as integer : `x size of desktop
global desk_y as integer : `y size of desktop

global hwnd
load dll "user32.dll",1
hwnd = call dll (1,"GetDesktopWindow")
make memblock 1,16
call dll 1,"GetWindowRect",hwnd,get memblock ptr(1)
desk_x = memblock word(1,8) - memblock word(1,0)
desk_y = memblock word(1,12) - memblock word(1,4)
hwnd = call dll(1,"GetActiveWindow")
global font as string : `to get around the font changing on set display mode bug
font = text font$()
old_x = screen width()
old_y = screen height()
I as integer

reload_media()

global stop as integer

`Main loop 1928x1208 
while escapekey() = 0
cls 0
text 0,0,"Window position: (" + STR$(pos_x) + "," + STR$(pos_y) + ")"
text 0,15,"Window size: (" + STR$(size_x) + "," + STR$(size_y) + ")"
text 0,30,"Fps : ("+str$(screen fps())+")"
check_display()
sync
Endwhile

function check_display()
call dll 1,"GetClientRect",hwnd,get memblock ptr(1)
pos_x = memblock word(1,0): pos_y = memblock word(1,4)
x2 = memblock word(1,8): y2 = memblock word(1,12)
If pos_y > 3000 Then pos_y = pos_y - 65536
If pos_x > 3000 Then pos_x = pos_x - 65536
size_x = x2 - pos_x: size_y = y2 - pos_y
if size_x = desk_x then dec size_x
if spacekey() then msgbox str$(old_x)+" "+str$(size_x)+" "+str$(old_y)+" "+str$(size_y),0,""
if size_x <> old_x or size_y <> old_y
  if size_x > 0
    if size_x => desk_x then size_x = desk_x - 1
    set display mode size_x,size_y,screen depth()
    set text font font
    old_x = screen width() : old_y = screen height()
    reload_media() : `set display mode loses all loaded media so you need to load it again.
  endif
endif
endfunction

function reload_media()
create bitmap 1,100,100
box 0,0,50,50 : box 50,50,100,100
get image 1,0,0,100,100,1
delete bitmap 1
for i = 1 to 12
  sprite i,i*50,i*50,1
next i
endfunction

`Cleanup code
for i = 0 to 12
if sprite exist(i) then delete sprite i
if image exist(i) then delete image i
if bitmap exist(i) then delete bitmap i
if dll exist(i) then delete dll 1
if memblock exist(i) then delete memblock i
next i