Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Interface and Graphics > Help Please - Cant Explain What Type lol


Reply
 
Thread Tools Display Modes
  #1  
Old 08-03-2003, 08:04 AM
Dayle Rees Dayle Rees is offline
Newcomer
 
Join Date: Jul 2003
Posts: 5
Question Help Please - Cant Explain What Type lol


Hi guys,

I've got this problem where i need to make a program which shows like on the attatched image.

As you can see it needs to use transparency ( best if i could give a range ) .. it also has to be either a cusom shape... or maybe could be done using a semi transparent image on a transparent form. Ive tried this before i made the form transparent, and loaded a Transparent GIF but all the transparencies in the GIF came out white.

Anyone know a way I can do it?

Thanks.
D.z
Attached Images
File Type: jpg msnidea.jpg (4.0 KB, 24 views)
Reply With Quote
  #2  
Old 08-03-2003, 08:33 AM
GavinO's Avatar
GavinO GavinO is offline
Coder of Fortune

Retired Leader
* Expert *
 
Join Date: Dec 2002
Location: Troy, NY USA
Posts: 3,120
Default

You can do single level transparency with some API, I'd recommend looking at elitevb.com for an example, they have a nice one. The alpha blending that you seem to want is much more difficult .... not really sure where to point you, other than that it is asked for on a regular basis, and that a forum search might get you some answers.
__________________
-- The Gavster
Like to IRC? Try irc.randomirc.com
GavServer
Reply With Quote
  #3  
Old 08-03-2003, 09:16 AM
zak2zak's Avatar
zak2zak zak2zak is offline
Contributor
 
Join Date: Jul 2003
Location: Singapore
Posts: 686
Lightbulb May I suggest

May Be This helps.......
You need to use API as mentioned below:
Code:
  • SetWindowRgn
  • DeleteObject
  • CreateCompatibleDC
  • SelectObject
  • GetObject
  • CreateRectRgn
  • CombineRgn
  • DeleteDC
  • GetPixel
Code:
'In the procedure or events that you want to triger just set as shown below below: DoEvents 'if the picture is large & U want other process to be running Call SetRegion(picSelect, &HFFFFFF) 'here I set the transparent pixel to White 'Or SetRegion picSelect, &HFFFFFF
I have a module attached to this reply which has the full source
And is ready to use. Feel free to try..
Attached Files
File Type: bas modRegion.bas (3.5 KB, 3 views)
__________________
I May Have Interpret It wrongly
Correct me..if I misunderstood U.
Hope This helps........and Enjoy Coding........//


zak2zak
Reply With Quote
  #4  
Old 08-03-2003, 10:32 AM
GavinO's Avatar
GavinO GavinO is offline
Coder of Fortune

Retired Leader
* Expert *
 
Join Date: Dec 2002
Location: Troy, NY USA
Posts: 3,120
Default

In addition to what he had, instead of pure white, you want to blend the white with the color behind it, which involves finding that color (don't ask me!) and doing a proportional blend. I think that the blend is something like: break out each channel of each color, multiply it by the percentage that that color is in the final pixel, add the channels, and recompose the color. Lengthy process; it would help to find an API function to do it.
__________________
-- The Gavster
Like to IRC? Try irc.randomirc.com
GavServer
Reply With Quote
  #5  
Old 08-04-2003, 11:38 AM
Dayle Rees Dayle Rees is offline
Newcomer
 
Join Date: Jul 2003
Posts: 5
Talking hmm

Yeah i get it, li'll give it a go and let u know what i can come up with, thanks.
Reply With Quote
  #6  
Old 08-04-2003, 12:23 PM
Dayle Rees Dayle Rees is offline
Newcomer
 
Join Date: Jul 2003
Posts: 5
Default prob.

On using the mod above i get User Defined type not defined, on declaring BM as bitmap, was i meant to include any references?

Dz
Reply With Quote
  #7  
Old 08-04-2003, 12:26 PM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

You need to define the BITMAP type.
Reply With Quote
  #8  
Old 08-04-2003, 02:03 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
Default

Quote:
Originally Posted by Dayle Rees
Hi guys,

I've got this problem where i need to make a program which shows like on the attatched image.

As you can see it needs to use transparency ( best if i could give a range ) .. it also has to be either a cusom shape... or maybe could be done using a semi transparent image on a transparent form. Ive tried this before i made the form transparent, and loaded a Transparent GIF but all the transparencies in the GIF came out white.

Anyone know a way I can do it?

Thanks.
D.z




Here's an example of a way to emulate what you want, but may not be what you're looking for.
Doesn't use any API though.


For those who don't want to download, Just add a command button and put a picturebox on the form, stretch it horizontally a bit, and paste this code in the declarations area.

Code:
Private Sub Command1_Click() Dim colr As Long Dim rc As Single, gc As Single, bc As Single Dim rb As Long, gb As Long, bb As Long Dim b As Single, r As Single, g As Single With Picture1 .BorderStyle = 0 'none colr = Me.Point(15, 15) bb = (colr And &HFF0000) \ &H10000 gb = (colr And &HFF00&) \ &H100 rb = colr And &HFF rc = (&HFF - rb) / .ScaleWidth gc = (&HFF - gb) / .ScaleWidth bc = (&HFF - bb) / .ScaleWidth colr = &HFFFFFF r = 255: g = 255: b = 255 For i = 0 To .ScaleWidth Picture1.Line (i, 0)-(i, .ScaleHeight), colr r = r - rc: g = g - gc: b = b - bc colr = Int(b) * &H10000 + Int(g) * &H100 + Int(r) Next .CurrentX = 5: .CurrentY = 5 Picture1.Print "This is a simulation of shading" End With End Sub
Attached Files
File Type: zip colorbak.zip (1.4 KB, 2 views)

Last edited by passel; 08-04-2003 at 03:06 PM.
Reply With Quote
  #9  
Old 08-05-2003, 06:06 AM
zak2zak's Avatar
zak2zak zak2zak is offline
Contributor
 
Join Date: Jul 2003
Location: Singapore
Posts: 686
Lightbulb Sorry For The Earlier Post Miss The Type

May Be This Helps..
Code:
'Just Add In the mod Declarations Private Type BITMAP bmType As Long bmWidth As Long bmHeight As Long bmWidthBytes As Long bmPlanes As Integer bmBitsPixel As Integer bmBits As Long End Type
__________________
I May Have Interpret It wrongly
Correct me..if I misunderstood U.
Hope This helps........and Enjoy Coding........//


zak2zak
Reply With Quote
  #10  
Old 08-05-2003, 08:22 AM
crow crow is offline
Newcomer
 
Join Date: Jun 2003
Posts: 4
Default

Private Const RGN_XOR = 3 'Creates the union of two combined regions except for any overlapping areas.
Private Const RGN_DIFF = 4 'Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function OffsetRgn Lib "gdi32" (ByVal hRgn As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function SetWindowRgn Lib "USER32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Const SM_CYCAPTION = 4 'Height of windows caption
Const SM_CXBORDER = 5 'Width of no-sizable borders
Const SM_CYBORDER = 6 'Height of non-sizable borders
Const SM_CXDLGFRAME = 7 'Width of dialog box borders
Const SM_CYDLGFRAME = 8 'Height of dialog box borders
Private Declare Function GetSystemMetrics Lib "USER32" (ByVal nIndex As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private oldRgn As Long
Private Dragging As Boolean
Private dragX As Long
Private dragY As Long
Private A As Boolean, b As Boolean
Private J As Byte

Dim x As Long 'Used to loop thru the pixels
Dim y As Long 'Used to loop thru the pixels
Dim wid As Long 'Width of picture - Used to loop thru the pixels
Dim hgt As Long 'Height of picture - Used to loop thru the pixels
Dim ttlHeight As Long 'Height of the form's titlebar & top border in pixels
Dim xBorder As Long 'Width of the form's side borders in pixels

Dim rgnPic As Long 'Region of the picture
Dim rgnPixel As Long 'Region of a pixel - used to subtract out tiny areas
Dim colPixel As Long 'Color of a pixel in the picture
Dim picDC As Long 'Temporary device context used to get pixel color info
Dim oldBmp As Long '1x1 bitmap created when picDC is created.
Dim transColor As Long

'Calculate the size of the picture which we will fit the form to
wid = Me.ScaleX(Me.Picture.Width, vbHimetric, vbPixels)
hgt = Me.ScaleX(Me.Picture.Height, vbHimetric, vbPixels)

'Create a region the same size as our picture dimensions
rgnPic = CreateRectRgn(0, 0, wid, hgt)

'Select our picture into a temporary device context so we can
' read the color information.
picDC = CreateCompatibleDC(Me.hdc)
oldBmp = SelectObject(picDC, Me.Picture.handle)
transColor = GetPixel(picDC, 0, 0)
'Loop thru all pixels in the picture
For y = 0 To hgt
For x = 0 To wid
' check the color of each pixel
colPixel = GetPixel(picDC, x, y)
If colPixel = transColor Then
'If the color is our mask color (Pure red in this case) then
' create a tiny region for it and remove it from the picture
rgnPixel = CreateRectRgn(x, y, x + 1, y + 1)
CombineRgn rgnPic, rgnPic, rgnPixel, RGN_XOR
'Clean up our graphics resource
DeleteObject rgnPixel
End If
Next x
Next y

'Clean up our temporary picture resources
SelectObject picDC, oldBmp
DeleteDC picDC
DeleteObject oldBmp

'Calculate how much we need to offset the region so it lays directly ontop
' of the form's picture (client x,y instead of form x,y)
ttlHeight = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYDLGFRAME)
xBorder = GetSystemMetrics(SM_CXDLGFRAME)

'Offset our region by the calculated amount
OffsetRgn rgnPic, xBorder, ttlHeight

'Fit the window to our new region
' If its the first time, store the original handle.
' If its more than the first time, just delete the previous custom handle.
If oldRgn = 0 Then
oldRgn = SetWindowRgn(Me.hwnd, rgnPic, True)
Else
DeleteObject SetWindowRgn(Me.hwnd, rgnPic, True)
End If
end sub


------------------------------------
this comes i think from psc aint sure, it works tho.. ( i got an old p200 on which it works 2 * * * * ). But it is slow cuz it goes thu the whole form, better if you know what regions 2 cut out and just do those, but since i use it for a slpashscreen with a very complicated picture i use it like this


*EDIT* this does no do shading, it's either transparant or not
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Public Type declarations and object.notation planet-boss General 5 12-19-2002 12:33 PM
type within type User2571 General 3 12-11-2002 06:56 PM
need help - passing user defined type to sub thekillerbean General 13 12-05-2002 09:46 AM
Help Me...GURU Luckyboy General 10 10-22-2001 08:08 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->