JanetTerra
Jul 6, 2011
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
' Use Flood Fill for changing background color'This demo is slightly modified toButtonfacebe
'compatible with Windows 7
'Load a bitmap
loadbmp "pic", "boy.bmp"
'Open a small window for coloringnomainwinWindowWidth = 100WindowHeight = 150UpperLeftX = int((DisplayWidth-WindowWidth)/2)UpperLeftY = int((DisplayHeight-WindowHeight)/2)open "Untitled" for graphics as #g'Get the DC of the windowhg = GetDC(hWnd(#g))'Fill with buttonface and change color to buttonface#g "down; fill buttonface; drawbmp pic; flush"#g "color buttonface; backcolor buttonface"'Find the background color of the picorigColor = pixelColor(hg, 1, 1)'Change the background color to buttonfacecall FloodFill hg, origColor, 1, 1'Unload the old pic from memoryunloadbmp "pic"'Place the new pic in memory#g "getbmp pic 0 0 54 100"'Get the handle of this pichPic = hBmp("pic")'Close this windowclose #g'=========================================
'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
title2$ = "Alt - F4 to Close"statictext #RoundWindow.st2, title2$, 90, 250, 200, 20stylebits #RoundWindow.st2, _ES_CENTER, 0, 0, 0button #RoundWindow.trap, "Exit", [closeRoundWindow], UL, 160, 280, 60, 30
open "No Title" for window as #RoundWindow
#RoundWindow "trapclose [closeRoundWindow]"
#RoundWindow.st2, "!font#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"
call DelObject hBwclose #RoundWindow
endsub DelObject hObjectcalldll #gdi32, "DeleteObject",_hObject as ulong,_null as longend subfunction GetDC(hW)calldll #user32, "GetDC", _hW as ulong, _GetDC as ulongend function
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
sub SelObject hDC, hBrushcalldll #gdi32, "SelectObject", _hDC as ulong, _hBrush as ulong, _null as longend subfunction 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,_
returnSWR as long
end sub
function pixelColor(hDC, x, y)calldll #gdi32, "GetPixel", _hDC as ulong, _x as long, _y as long, _pixelColor as longend functionfunction hue$(hueColor)hueBlue = Int(hueColor/256^2)hueColor = hueColor - hueBlue*256^2hueGreen = Int(hueColor/256)hueRed = hueColor - hueGreen*256hue$ = hueRed;" ";hueGreen;" ";hueBlueend functionsub FloodFill hDC, origColor, x, ycalldll #gdi32, "ExtFloodFill", _hDC as uLong, _x as Long, _y as Long, _origColor as Long, _1 as Long, _result As Longend subsub 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