Janet Terra Creating a Nonrectangular Window | Demo 1: Drawing a Nonrectangular Window | Third Part Title
Creating an irregular shaped window is achieved with WinAPI calls to user32.dll and gdi32.dll. The first step is to create a window without a caption. This can be achieved with the stylebits commands _WS_POPUP in the addbits parameter and _WS_CAPTION in the removebits paramater, or simply using the window_popup style. It is also advisable to keep the window in the forefront. Do this by using the stylebits command _WS_EX_TOPMOST in the extended bits parameter. Remember that any GUI window may be closed with Alt-F4.
This first demo draws a circle, a rectangle, and some graphic text. The background is never added to the window. Only the actual drawings, including the graphic text, become part of the window. First, open a captionless window.
Nomainwin'Define the WindowWindowWidth=500WindowHeight=500UpperLeftX=int((DisplayWidth-WindowWidth)/2)UpperLeftY=int((DisplayHeight-WindowHeight)/2)graphicbox#ShapeWindow.gb,0,0,500,500stylebits#ShapeWindow.gb,0, _WS_BORDER,0,0'Keep the Shaped Window in the Forefrontstylebits#ShapeWindow,0,0, _WS_EX_TOPMOST,0open"Shape Window"for window_popup as#ShapeWindow
#ShapeWindow "trapclose [closeShapeWindow]"
Once the window is opened, handles and device controls to both the window and the graphicbox must be obtained.
Now you're ready to draw an image. In this first demo, the image will be drawn using API calls. These are the steps in the [drawShape] gosub.
1: The Destination - Define a region to hold the finished window. Because this region will be built upon, start with all 0's for x, y, width and height.
'Original values for hRgn is meaningless
hRgn = RectRegion(0,0,0,0)'The FunctionFunction RectRegion(ulx, uly, width, height)CallDLL#gdi32,"CreateRectRgn", _
ulx aslong, _
uly aslong, _
width aslong, _
height aslong, _
RectRegion asulongEndFunction
2: The Circle - Define the x, y, width and height values for the circle. Select a red brush, paint the designated ellipse, delete the brush.
The SetBkMode of #gdi32 can be called to achieve a transparent background for text. Text can then become part of the window.
'Set background to TransparentCall SetBkMode hDCgb,1
ReleaseDC is again called to release memory.
'Release memoryCall ReleaseDC hBgb, hDCbg
Graphics text is accomplished with native Liberty BASIC code.
'Format Text#ShapeWindow.gb "font Courier_New 14 Bold"#ShapeWindow.gb "color Black; place 120 150"#ShapeWindow.gb "\Alt-F4 to Close"Wait
Run your program and a shaped window appears. Close the window with Alt-F4 or include a button for closure. The window will stay on top of other windows, but it is possible for the window to lose focus. If this happens, click on the window before pressing Alt-F4.
Creating a Nonrectangular Window
Janet TerraCreating a Nonrectangular Window | Demo 1: Drawing a Nonrectangular Window | Third Part Title
Creating an irregular shaped window is achieved with WinAPI calls to user32.dll and gdi32.dll. The first step is to create a window without a caption. This can be achieved with the stylebits commands _WS_POPUP in the addbits parameter and _WS_CAPTION in the removebits paramater, or simply using the window_popup style. It is also advisable to keep the window in the forefront. Do this by using the stylebits command _WS_EX_TOPMOST in the extended bits parameter. Remember that any GUI window may be closed with Alt-F4.
For more detailed discussion of stylebits, see Stylebits - Windows.
Demo 1: Drawing a Nonrectangular Window
This first demo draws a circle, a rectangle, and some graphic text. The background is never added to the window. Only the actual drawings, including the graphic text, become part of the window. First, open a captionless window.Once the window is opened, handles and device controls to both the window and the graphicbox must be obtained.
Now you're ready to draw an image. In this first demo, the image will be drawn using API calls. These are the steps in the [drawShape] gosub.
1: The Destination - Define a region to hold the finished window. Because this region will be built upon, start with all 0's for x, y, width and height.
2: The Circle - Define the x, y, width and height values for the circle. Select a red brush, paint the designated ellipse, delete the brush.
Use CombineRgn to add this painted region, hRgn1, to the destination region, hRgn.
Now that region hRgn1 is a part of region hRgn, it is no longer needed. Delete that object to free memory.
3: The Rectangle - Define the x, y, width and height values for the rectangle. Select a blue brush, paint the designated rectangle, delete the brush.
Once again, use the API Call CombineRgn to add the pixels of the rectangle hRgn2 to the final destination region hRgn.
The hRgn2 rectangle can now be safely deleted to free up space, as it's been added to the shaped window region hRgn.
4: The newly built region made up of regions hRgn1 and hRgn2 can now be set as the window.
The SetBkMode of #gdi32 can be called to achieve a transparent background for text. Text can then become part of the window.
ReleaseDC is again called to release memory.
Graphics text is accomplished with native Liberty BASIC code.
Run your program and a shaped window appears. Close the window with Alt-F4 or include a button for closure. The window will stay on top of other windows, but it is possible for the window to lose focus. If this happens, click on the window before pressing Alt-F4.
Click ShapedDemo1.bas for the entire program.
Third Part Title
Text here.'code hereCreating a Nonrectangular Window | Demo 1: Drawing a Nonrectangular Window | Third Part Title