Hello, thank you for reading.
i've written a bunch of code that allows me to have a moveable/resizeable window that is quick and smooth and without loosing display quality/having to change the display mode.
the window is painted using dbpro 2d commands. the display mode is set to the desktop width/height.
for the first test, i was using WinAPI transparency. my problem with this is that i can only define a rectangular region, so i can only have one "main" window and every other window must be inside of the main window. i don't want that.
next i've tested out the winskin plugin made by Scilynt. the idea is to create a screenshot, clear the skin, move the window on top of the screenshot and then get the new window position, width and height to create a new skin. the problem is, dbpro saves the image as a 32bit bitmap. the plugin somehow can't handle that.
i made an attempt to write my own save image function that writes a 24bit bitmap.
but a bitmap is flipped vertically. using the image kit plugin made by Sven B i flipped the image and then made a memblock from the flipped image, but the output gets screwed up...
here is my code: (feel free to use in your own projects, but i do not comment my code...)
Rem Project: screenshot_test
Rem Created: Thursday, July 28, 2016
rem start
#constant APP_NAME "Dark Basic Pro Project" // you may need to change this
loadDlls()
set display mode desktop width(), desktop height(), 32
set window position 0,0
set window layout 0,0,0
type cursorType
x as integer
y as integer
endtype
type mouseType
c as cursorType
endtype
type winType
x as integer
y as integer
width as integer
height as integer
titleBarHeight as integer
title as string
bgColor as dword
endtype
dim mouse(0) as mouseType
global window as winType
window.x=50
window.y=50
window.width=640
window.height=480
window.titleBarHeight=20
window.title="Resize Test"
window.bgColor=0xffa0a0a0
setWindowTransparentRegion(window.x,window.y,window.x+window.width,window.y+window.height)
box window.x, window.y, window.x+window.width, window.y+window.height, window.bgColor, window.bgColor, window.bgColor, window.bgColor
box window.x+2,window.y+2,window.x+window.width-2,window.y+window.titleBarHeight-2,0xff839ebc,0xff839ebc,0xff839ebc,0xff839ebc
do
getCursorData()
mmx=mousemovey()
mmy=mousemovey()
if (mouse(0).c.x>=window.x and mouse(0).c.x<=window.x+window.width and mouse(0).c.y>=window.y and mouse(0).c.y<=window.y+window.width) or resize>0
if mouseclick()=1
if mmx<>0 or mmy<>0
if resize=0
mx=mousex()-window.x
my=mousey()-window.y
resize=1
endif
window.x=mouse(0).c.x-mx
window.y=mouse(0).c.y-my
endif
endif
if mouseclick()=2
if resize=0 then resize=1
window.width=mouse(0).c.x-window.x
window.height=mouse(0).c.y-window.y
if window.width<640 then window.width=640
if window.height<480 then window.height=480
endif
if mouseclick()>0 and resize=1
//makeScreenshot()
//setWindowTransparentRegion(0,0,screen width(),screen height())
resize=2
endif
if mouseclick()>0 and resize=2
cls
//showScreenshot()
box window.x, window.y, window.x+window.width, window.y+window.height, window.bgColor, window.bgColor, window.bgColor, window.bgColor
box window.x+2,window.y+2,window.x+window.width-2,window.y+window.titleBarHeight-2,0xff839ebc,0xff839ebc,0xff839ebc,0xff839ebc
//showBorder(window.x,window.y,window.x+window.width,window.y+window.height)
setWindowTransparentRegion(window.x,window.y,window.x+window.width,window.y+window.height)
endif
if mouseclick()=0 and resize>0
//setWindowTransparentRegion(window.x,window.y,window.x+window.width,window.y+window.height)
//clearScreenshot()
resize=0
endif
endif
loop
end
function getCursorData()
call dll 2,"GetCursorPos",mouse(0).c
endfunction
function loadDlls()
Load Dll "gdi32.dll",1
Load Dll "user32.dll",2
endfunction
function getWindowHandle()
Hwnd=Call Dll(2,"FindWindowA",0,APP_NAME)
endfunction Hwnd
function setWindowTransparentRegion(x1,y1,x2,y2)
hwnd=getWindowHandle()
hrgn=Call Dll (1,"CreateRectRgn",x1,y1,x2,y2)
a=Call Dll (2,"SetWindowRgn",hwnd,hrgn,1)
endfunction
remstart
commented out so the code works without plugins. winapi is fast enought so i don't need to make a screenshot
function makeScreenshot()
minimize window
CaptureDesktop "saved.bmp"
restore window
load image "saved.bmp",1,1
delete file "saved.bmp"
endfunction
function showScreenshot()
paste image 1,0,0
endfunction
function clearScreenshot()
if image exist(1) then delete image 1
endfunction
remend
function showBorder(x1,y1,x2,y2)
rem start
line x1,y1,x2,y1
line x1,y2,x2,y2
line x1,y1,x1,y2
line x2,y1,x2,y2
rem end
//box x1,y1,x2,y2,0xff000000,0xff000000,0xff000000,0xff000000
endfunction
remstart
wait key
hrng=Call Dll (1,"CreateRectRgn",x,y,x+width,y+height)
a=Call Dll (2,"SetWindowRgn",hwnd,hrng,1)
wait key
resizeRgn=Call Dll (1,"CreateRectRgn",0,0,desktop width(),desktop height())
a=Call Dll (2,"SetWindowRgn",hwnd,resizeRgn,1)
wait key
hrng=Call Dll (1,"CreateRectRgn",WinElements(0).x-1,WinElements(0).y-1,WinElements(0).x+WinElements(0).width+1,WinElements(0).y+WinElements(0).height+1)
a=Call Dll (2,"SetWindowRgn",hwnd,hrng,1)
remend
Rem ***** Included Source File *****
remstart
set display mode desktop width(), desktop height(), 32
set window skin "skin.bmp",255,0,255
wait key
remend
rem start
#constant C_SW screen width()
#constant C_SH screen height()
box 0,0,C_SW,C_SH,0xffff00ff,0xffff00ff,0xffff00ff,0xffff00ff
box 0,0,40,40,0xff000000,0xff000000,0xff000000,0xff000000
get image 1,0,0,C_SW,C_SH,3
saveBMP("s.bmp",1)
set window skin "s.bmp",255,0,255
make memblock from image 1,1
print "size: ";get memblock size(1);" --- should be: ";3*4+(C_SW*C_SH)*4
print "width: ";memblock dword(1,0)
print "height: ";memblock dword(1,4)
print "depth: ";memblock dword(1,8)
wait key
for i=3*4 to get memblock size(1)-1 step 4
cls
paste image 1,0,0
x=mod(((1+i-3*4)/4)-1,C_SW)
y=(((1+i-3*4)/4)-1) / C_SW
dot x,y,0xffffffff
a$=hex$(memblock byte(1,i))
if len(a$)<2 then a$="0"+a$
b$=b$+a$+" "
a$=hex$(memblock byte(1,i+1))
if len(a$)<2 then a$="0"+a$
b$=b$+a$+" "
a$=hex$(memblock byte(1,i+2))
if len(a$)<2 then a$="0"+a$
b$=b$+a$+" "
a$=hex$(memblock byte(1,i+3))
if len(a$)<2 then a$="0"+a$
b$=b$+a$+" "
print b$
b$=""
repeat
in$=inkey$()
sleep 10
until in$<>""
if in$="x" then end
in$=""
next i
end
function mod(num,modulus)
value=num-((num/modulus)*modulus)
endfunction value
function saveBMP(filename$,imageNr)
repeat
inc memNr
until memblock exist(memNr)=0
repeat
inc fileNr
until file open(fileNr)=0
ik flip image vertically imageNr
make memblock from image memNr,imageNr
//ik flip image vertically imageNr
if file exist(filename$) then delete file filename$
open to write fileNr,filename$
headerSize=54
// BITMAPFILEHEADER
write word fileNr,19778
write long fileNr,headerSize+(image width(imageNr)*image height(imageNr))*3 // size
write word fileNr,0
write word fileNr,0
write long fileNr,headerSize
// BITMAPINFOHEADER
write long fileNr,40
write long fileNr,image width(imageNr)
write long fileNr,image height(imageNr)
write word fileNr,1
write word fileNr,24
write long fileNr,0
write long fileNr,(image width(imageNr)*image height(imageNr))*3
write long fileNr,0
write long fileNr,0
write long fileNr,0
write long fileNr,0
// RGB array
for i=3*4 to get memblock size(memNr)-4 step 4
write byte fileNr,memblock byte(memNr,i+2)
write byte fileNr,memblock byte(memNr,i+1)
write byte fileNr,memblock byte(memNr,i)
next i
close file fileNr
delete memblock memNr
endfunction
rem end