Hi,
Not being a great graphics man, I have a problem. I cut out an oval-ish shape from a
spreadsheet, using Vista's Capture tool
I want to place this on an IWB2 screen without the white background, so that I just
see the oval shape. I've tried drawmode transparent, and other things, but all I get
is the oval shape on a rectangular box with a white background. Any ideas?
Brian
See if this example by ZeroDog possibly gives you any ideas
'ZeroDog's Tips 'N Tricks
'Fun With Windows
'Part 3 - Color Masked Windows
'*******************************
'Creating color masked windows is easy to do in just a few steps using the
'SetLayeredWindowAttributes API function and the MODIFYEXSTYLE function.
'Simply create a layered window, apply a masking color, and anything that
'is drawn in the window using the masking color will be completely transparent.
'Keep in mind however, that the color masking of the window applies to the entire
'window, including menus, titlebars, buttons, images, and just about anything that
'is drawn in the window.
'First thing we need to do is define our window variable.
DEF win:WINDOW
'Now declare the API function call (we can IMPORT from user32.dll)
DECLARE IMPORT, SetLayeredWindowAttributes(hWnd:INT, crKey:INT, bAlpha:INT, dwFlags:INT), INT
'hwnd is the handle of the window to blend.
' Ex: win.hwnd
'crKey is the masking color in RGB.
' Ex: RGB(255,0,0)
'bAlpha is used for another purpose so we will leave it null.
' Ex: 0
'dwFlags is the style flag that will be applied. In this case we will be using the color masking flag.
' Ex: LWA_COLORKEY
'Example useage of the function:
'SetLayeredWindowAttributes(win.hwnd, RGB(255,0,0), 0, LWA_COLORKEY)
'Next we set the constant that we will be using with the MODIFYEXSTYLE function.
CONST WS_EX_LAYERED = 0x80000 :'This constant specifies a layered window.
'Set the constant that we will be using with the SetLayeredWindowAttributes function.
Const LWA_COLORKEY = 0x1 :'This constant specifies color masking for the layered window attribute.
'Now we open up our window.
OPENWINDOW win, 0,0,300,300,@CAPTION|@SIZE, 0, "ZDTNT-FWW-2: Color Masked Windows",&winproc
'We now modify the window we opened to be a layered window.
MODIFYEXSTYLE win, WS_EX_LAYERED, 0
'And finally we set the color masking style to the now layered window.
'The color red, RGB(255,0,0), is set as the masking color, so anything that is drawn in red
'in the window will be transparent.
SetLayeredWindowAttributes(win.hwnd, RGB(255,0,0), 0, LWA_COLORKEY)
'Now we will just draw a few items to the window to make the effect easier to see.
SETWINDOWCOLOR win,RGB(0,0,255) :'Set the window color to blue
CIRCLE win, 150,150, 100, RGB(255,0,0),RGB(255,0,0):'Draw a red circle which will be transparent
DRAWMODE win, @TRANSPARENT :'text will be drawn with no backpen color
FRONTPEN win,RGB(255,0,0) :'frontpen set to red so text will be transparent
SETFONT win,"arial",48,700 :'set our font type, size and weight
PRINT win," ZeroDog " :'print some text to the window
MOVE win,0,175 :'move the print cursor to lower on the window
FRONTPEN win,RGB(0,255,0) :'frontpen set to green so text will be solid.
PRINT win," ZeroDog " :'print some text to the window
'Note: when using color masking and printing to the window, you will sometimes notice
'that the font smoothing options set in the display settings may leave little bits of odd
'coloring around fonts that are being masked around due to the antialiasing of the font.
'Turning off font smoothing in your dispay settings will eliminate these extra bits.
'At this point, the program is all set up, so we will set our run variable
'to 1 and process window messages until the run variable is set to 0, when
'the program is closed.
run=1
WAITUNTIL run=0
CLOSEWINDOW win
END
'Main program end.
'This is our window message handler subroutine.
SUB winproc
'--This message is sent when the window is initially created.
IF @MESSAGE = @IDCREATE THEN CENTERWINDOW win
'--This message is sent when the window/program is closed.
IF @MESSAGE = @IDCLOSEWINDOW THEN run=0
RETURN
ENDSUB
'End of window message handler subroutine.
LarryMc
Larry,
Thanks for reminding me about that one, but I can't seem to make it
work with a graphic
I'm just looking at PhotoFiltre, which is supposed to be able to make
edges transparent, but no luck so far!
Brian
Cracked it!
Realised that SHOWIMAGE had options for BitBlt flags. Looked them up, and kept
trying them until I hit on the one that worked, which was:
SHOWIMAGE win,mypic,@IMGBITMAP,10,254,936,443,0x00BB0226
Looks great!
Brian
I am having no luck getting SHOWIMAGE to work with bitblt flags as you show above. What else is needed? May you please provide an example or elaborate?
In other words, how do I display a bitmap with a transparent color using SHOWIMAGE?
basicgames,
Bitmaps (and JPGs) do not support transparent pixels. My bitmap image in that line of code was of some black text surrounded by white, and the BitBlt flag was to mask the white out
If you need transparent pixels in IWB, use a GIF image
Brian
Thank you, Brian.
That makes sense to me, but I'm having trouble figuring out how you got it to mask the white. What does the hex 0x00BB0226 represent? Is that a raster code?
Either way, it looks like I'd best import bitblt as a function. Still, if you get a chance, could you please provide an example of how you masked the white?
I'm not sure about IWB documentation, but in EB there's virtually nothing other than a mention of bitblit flags in SHOWIMAGE. The only other source I could find was this thread.
Never used BitBlt myself, but the best place to find information on how to use the various APIs can be found at Microsoft,
and here is a link to their explanation of BitBlt: https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-bitblt (https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-bitblt) .
A slightly different approach can be found here: https://vbden.tripod.com/articles/invmask.htm (https://vbden.tripod.com/articles/invmask.htm)
Good luck!
Egil
basicgames,
Here's a little example I dashed off this morning before going out for a Christmas lunch this afternoon. I've even included a text file showing all the BitBlt constants and meanings. Hope this helps you somewhat
Just put the IWB program and bitmap image in the same folder, and compile
Brian
Quote from: Brian on December 06, 2024, 05:31:13 AMbasicgames,
Here's a little example I dashed off this morning before going out for a Christmas lunch this afternoon. I've even included a text file showing all the BitBlt constants and meanings. Hope this helps you somewhat
Just put the IWB program and bitmap image in the same folder, and compile
Brian
Perfect demonstration. Just had to modify the waituntil to win = 0 for EB.
The gradient is helpful to understand how the colors change. I also tried replacing the gradient with solid colors and tried all of the constants.
The results are pretty much what I expected, but this way it makes sense.
That text file you made is great because I haven't seen that information compiled anywhere else. If anyone is looking to use bitblt with SHOWIMAGE, this is the thread to look at.
I appreciate you taking the time to share this. Hope you had a good lunch.
Quote from: Egil on December 06, 2024, 03:51:22 AMNever used BitBlt myself, but the best place to find information on how to use the various APIs can be found at Microsoft,
and here is a link to their explanation of BitBlt: https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-bitblt (https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-bitblt) .
A slightly different approach can be found here: https://vbden.tripod.com/articles/invmask.htm (https://vbden.tripod.com/articles/invmask.htm)
Good luck!
Egil
I had seen the microsoft link, but not the tripod one. It seems that after seeing Brian's example, it is clear that importing bltblt is the way to go for more complex graphics. Thanks for sharing.
My intention is to take some of the game engines I am designing in Blitz Basic using directx and port them to EB (which should be easy to port to IWB) without using any directx.
I am developing an Isometric and a 2.5d engine for role playing games and want to remove the directx dependency.
Long story short, I want to make quality games that are compatible between a 386 with Windws 95 all the way to Ryzen with Windows 11. This is due to the recent discovery that EB runs and compiles well on the 386/95 setup. Why? I got one of those new Pocket 386 machines from China and am absolutely tickled by it.
As a side note, I bet IWB would run on a 386 too. That's a mighty impressive range of compatibility. 95 to 11. 386 to Ryzen.