Older Version Newer Version

RodBird RodBird Nov 23, 2015

ShapedWindowDemo3.bas

This code accompanies the article Creating a Nonrectangular Window

 'ShapedDemo3.bas - Janet Terra 
'Demo to accompany
'Demo - Creating a Nonrectangular Window
'LBPE July, 2011
'Originally appeared in
'LB Newsletter #132, May, 2005
'This demo is slightly modified to be
'compatible with Windows 7


'Load a bitmap
loadbmp "pic", "boy.bmp"
hPic = hBmp("pic")

'Define the Window
WindowWidth = 400
WindowHeight = 400
UpperLeftX = int((DisplayWidth-WindowWidth)/2)
UpperLeftY = int((DisplayHeight-WindowHeight)/2)

statictext #RoundWindow.st1, "", 90, 106, 200, 120
stylebits #RoundWindow.st1, _SS_BITMAP or _SS_CENTERIMAGE, 0, 0, 0
button #RoundWindow.trap, "Exit", [closeRoundWindow], UL, 160, 280, 60, 30

open "No Title" for window as #RoundWindow
#RoundWindow "trapclose [closeRoundWindow]"
#RoundWindow "font New_Courier 12 Bold"

'Obtain the Handles and Device Controls
hRw = hWnd(#RoundWindow)
hSt = hWnd(#RoundWindow.st1)

'Define the circle
hRgn = EllipticRegion(40, 80, 350, 380)
call SetWindowRgn hRw, hRgn

'Set the image
call setImage hSt, hPic
wait

[closeRoundWindow]
unloadbmp "pic"
close #RoundWindow
end

function RectRegion(ulx, uly, width, height)
calldll #gdi32, "CreateRectRgn", _
ulx as long, _
uly as long, _
width as long, _
height as long, _
RectRegion as ulong
end function

function EllipticRegion(ulx, uly, width, height)
calldll #gdi32, "CreateEllipticRgn", _
ulx as long, _
uly as long, _
width as long, _
height as long, _
EllipticRegion as ulong
end function

sub SetWindowRgn hWnd, hRgn
calldll #user32, "SetWindowRgn",_
hWnd as ulong,_
hRgn as ulong,_
1 as boolean,_ long,_
returnSWR as long
end sub

sub setImage hStatic, hImage
calldll #user32, "SendMessageA",_
hStatic as ulong, _
_STM_SETIMAGE as long, _
_IMAGE_BITMAP as long, _
hImage as ulong, _
result as long
end sub