Is there any way I can make only ONE color on my form transparent? I want to make the form invisible but keep any image data I may have on there (like from using .print or .line).
There is a method to create a rounded form, for example. This is made with a masked picture that tells which part of the form is visible and which is not. Would this help?
Emiliano F. Martín
If a post has helped you then pleaseRate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Have a look at this. This example has the masked already loaded in the form.
Emiliano F. Martín
If a post has helped you then pleaseRate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Mc Brain if what you posted does this then sorry, it didn't sound like it
Not quite. I posted a simpler sample. An here is an even simpler way.
Emiliano F. Martín
If a post has helped you then pleaseRate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Nove, true transparency is only supported on Windows 2000 and higher.
You can still do funny shaped forms in Win 98 but no translucency effects.
The code I posted works on W98. However, it is neither true transparency, nor translucent. Maybe it's not what you need.
Emiliano F. Martín
If a post has helped you then pleaseRate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Mc Brain when I run the 2nd project you posted I see white dots to the right of the black text. I have some other regioning code which doesn't do that.
Code:
Public Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Public Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Public Function RegionFromImage(fRgnForm As Form, picBackground As PictureBox, ByVal lBackColor As Long) As Long
Dim hRegion As Long
Dim lpicHeight As Long
Dim lpicWidth As Long
Dim lRow As Long
Dim lCol As Long
Dim lStart As Long
Dim hTempRegion As Long
Dim lResult As Long
hRegion = CreateRectRgn(0, 0, 0, 0)
With picBackground
lpicHeight = .Height / Screen.TwipsPerPixelY
lpicWidth = .Width / Screen.TwipsPerPixelX
For lRow = 0 To lpicHeight - 1
lCol = 0
Do While lCol < lpicWidth
Do While (lCol < lpicWidth) And _
(GetPixel(.hDC, lCol, lRow) = lBackColor)
lCol = lCol + 1
Loop
If lCol < lpicWidth Then
lStart = lCol
Do While (lCol < lpicWidth) And _
(GetPixel(.hDC, lCol, lRow) <> lBackColor)
lCol = lCol + 1
Loop
If lCol > lpicWidth Then lCol = lpicWidth
hTempRegion = CreateRectRgn(lStart, lRow, lCol, lRow + 1)
lResult = CombineRgn(hRegion, hRegion, hTempRegion, RGN_OR)
Call DeleteObject(hTempRegion)
End If
Loop
Next
End With
RegionFromImage = hRegion
SetWindowRgn fRgnForm.hwnd, hRegion, True
End Function
Basically just call RegionFromImage from the Form_Initialize sub. Unlike your example it does need a picture box with an image in it. Also you need to pass the background (transparent) colour.
Nove if you are printing text/lines to the form, to use this code just print them to a picture box instead, and pass the background colour of the picture box to the funciton.
Mc Brain when I run the 2nd project you posted I see white dots to the right of the black text. I have some other regioning code which doesn't do that.
Code:
Public Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Public Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Public Function RegionFromImage(fRgnForm As Form, picBackground As PictureBox, ByVal lBackColor As Long) As Long
Dim hRegion As Long
Dim lpicHeight As Long
Dim lpicWidth As Long
Dim lRow As Long
Dim lCol As Long
Dim lStart As Long
Dim hTempRegion As Long
Dim lResult As Long
hRegion = CreateRectRgn(0, 0, 0, 0)
With picBackground
lpicHeight = .Height / Screen.TwipsPerPixelY
lpicWidth = .Width / Screen.TwipsPerPixelX
For lRow = 0 To lpicHeight - 1
lCol = 0
Do While lCol < lpicWidth
Do While (lCol < lpicWidth) And _
(GetPixel(.hDC, lCol, lRow) = lBackColor)
lCol = lCol + 1
Loop
If lCol < lpicWidth Then
lStart = lCol
Do While (lCol < lpicWidth) And _
(GetPixel(.hDC, lCol, lRow) <> lBackColor)
lCol = lCol + 1
Loop
If lCol > lpicWidth Then lCol = lpicWidth
hTempRegion = CreateRectRgn(lStart, lRow, lCol, lRow + 1)
lResult = CombineRgn(hRegion, hRegion, hTempRegion, RGN_OR)
Call DeleteObject(hTempRegion)
End If
Loop
Next
End With
RegionFromImage = hRegion
SetWindowRgn fRgnForm.hwnd, hRegion, True
End Function
Basically just call RegionFromImage from the Form_Initialize sub. Unlike your example it does need a picture box with an image in it. Also you need to pass the background (transparent) colour.
Nove if you are printing text/lines to the form, to use this code just print them to a picture box instead, and pass the background colour of the picture box to the funciton.
I think you see those dots because the image is aliased. The image should get an anti-aliased. That's an example I downloaded some time ago.
Emiliano F. Martín
If a post has helped you then pleaseRate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Here's a sample with penagate's code. However... it seems to be a little slow (with large images). Unfortunately... it won't make it as transparent as almost all men would want. (You'll understand when you see the sample).
Emiliano F. Martín
If a post has helped you then pleaseRate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Some pixels of the image should be turned into "transparent" (and see the light blue form's backcolor. Bear in mind, that the model's top is not perfectly white but has a lot of shades.
Emiliano F. Martín
If a post has helped you then pleaseRate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
I replaced the picture with just a white background, I couldn't really see any difference with the picture there. Works though, now maybe I can implement the two...
Hey, I need to make the form transparent in color, but actually tangible, as in I can see what's underneath it but when i click on that area I click on the form, not the junk underneath. Possible?
Hey, I need to make the form transparent in color, but actually tangible, as in I can see what's underneath it but when i click on that area I click on the form, not the junk underneath. Possible?
No. That's a translucent form. And can only be achieve with W2K Up (I don't know if it can be done in NT either).
Emiliano F. Martín
If a post has helped you then pleaseRate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
McBrain that is a terrible example
nice picture though
And yeah, maybe this whole transparency/translucency thing need clarifying. Translucency (semi-opacity) and full transparency can both be achieved by alpha blending. Full transparency can also be achieved by regioning which is what the examples in this thread are doing. Basically it just consists of telling Windows where to cut the edges of the form out. Alpha blending on the other hand makes either the whole form or pixels of a certain colour on the form, semi-opaque (a bit like Mc Brain's picture )
The API needed for alpha-blending is only available in Win 2K+. The APIs used for regioning however are available in Win 95+.
McBrain that is a terrible example
nice picture though
Sorry. He was saying he wanted to do it a picture, and I thought it should be with a photo.... and don't have much photos for an example.
Emiliano F. Martín
If a post has helped you then pleaseRate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
When you cant control what image is going to be used so you can make sure its anti-aliased you can always seperate the colors down to their RGB components and check them to see if the difference between them all is minute, sounds like a lot of checking but its not too bad and helps a lot on some images.
Since regions is the subject here and is spawned from the very same beginnings as my project, i have a question...
After deciding the 'BlueScreening' method wasnt quite what i needed I ended up drawing my images manually (just semi-complex shapes) by creating regions, and using FillRgn and FrameRgn. Worked good, however I did it on a UserControl. Inside that usercontrol i have another nested usercontrol which plays animations. my problem? when i play the animation in the nested control, my entire control with the painted region is invalidated and disappears leaving only the nested animation control showing. Its not clipping...so...what am i missing?
If i lock the window update, then the animation isnt seen, so i need to lock everything but the animation...