Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

irregular shape? 1

Status
Not open for further replies.

jacelyn

Programmer
Feb 1, 2001
20
0
0
SG
if you wana add a picture box to your form, you add a rectangle shape. Is it possible to add an irregular shape? EG. an apple shape, a durian shape.

Is there a way?
If yes! How to do it?
 
You can, but you have to become intimately familiar with the Windows API. Start with SetWindowRgn().

Chip H.
 
You can do it.
Please, check this code and learn some tips.


'**************************************
'Windows API/Global Declarations for :Ch
' ange Form Shape
'**************************************


Public Declare Function CreateEllipticRgn Lib "gdi32" _
(ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, _
ByVal Y2 As Long) As Long


Public Declare Function SetWindowRgn Lib "user32" _
(ByVal hWnd As Long, ByVal hRgn As Long, _
ByVal bRedraw As Boolean) As Long
'**************************************
' Name: Change Form Shape
' Description:Can Change The Shape of an
' y form
' Inputs:Look Below
'
' Returns:None
'
'Assumes:None
'
'Side Effects:The border can be preatty
' messed up if you don't know what your do
' ing


Private Sub Form_Load()
Show 'The form!
SetWindowRgn hWnd, CreateEllipticRgn(0, 0, 300, 200), True
End Sub

Enjoy it ! :)

Alex Molina

 
okie, basically i have not try the program and i am going to try it later. but where do i save the picture?
what i want?
i need to store lots of hair picture in a folder.
then while trying to run the program, click on the hair buttons and the picture will appear one after the other. but i do not want it to be in rectangular shape, i onli want the shape of that particular hair, as a rect shape will block the view of the eyes.
so, the problem is where do i save the picture?
do i need to open a rectangular picture box then run the program then the rect shape will turn into an irregular shape?
 
okie! as for your program, i have tried.but i do not noe how to key in the public declare function on both createEllipticRgn and the setwindowrgn?
i am still a newbies to vb.

another thing: i wana change the picture box not the form.
sorry for not stating it clearly juz now.
any way to do it?
 
Ok Jacelyn, thank for clearing me.
I think that you have a picture of face on your form, and over you want to show different hair styles. If this is correct, you must to draw the face with the hair style with any paint tool like Paint Shop Pro, to make each picture appear when you click the button. There is not other way.
Sorry!

:)
Alex Molina
 
There actually is a way to put any shape of picture anywhere on a form. There is no way i could go into all the detail you need here. So to find more information on this i would suggest looking up VB and Animation on the net. Also i would suggest that if you don't need to do this program that you wait and get more used to VB first. Having said that here are the basic concepts. First you have to draw a 'mask' for each hairstyle. A mask is a picture the exact same shape as the hairstyle, but wherever there is color in the hairstyle picture would be black in the mask, on a white background. Then make the background of the hairstyle picture black. In other words if you took the black part of the mask and the black part of the hair picture and put them together you would have a perfectly black picture (they should both be the same size). You would also do the same for the eyes, face, etc.. so that in the end you will be able to draw all components of the face transparently on top of each other and come out with a finished face. Put two PictureBoxes on Your form for each hairstyle, face, etc.. One for the picture and one for the mask. Once you have that done you use these pictureboxes to pass to the BitBlt function, which draws a given picture at given coordinates using a given Raster Operation. You first draw the mask using the vbSrcAnd Raster Op (see code below) this draws the mask transparently, so only the black area shows. You then paint the picture on top of that using the vbSrcPaint Raster Op. what you end up with is the original picture of the hair sitting transparently on whatever background is below it.
The example below is extracted from a sample animation program i found a long time ago. on its own it won't do anything, but it illustrates how to use the BitBlt function. You will need to change all the arguments except for Me.hDC (the Device Context Handle of the current form. a device context is a representation of a form or other object in memory.) and the raster Op (vbSrcAnd, vbSrcPaint). X and Y will be the coordinates of the upper-left of the final picture , nWidth and nHeight are the width and height of the piture (your hair picture), hSrcDC is the DC handle of the picture box where the mask or picture you are drawing is stored, xSrc and ySrc are the location of the upper left corner of the hair picture in the picture box(you could have one long picture box for all the hairs and one for all the masks, if you did that the combination of xSrc, ySrc, nWidth, and nHeight would tell the function what area of the picture box the source picture is to be taken from). If this all sounds complicated thats because it kinda is. I hope this at least gets you started.

Code:
'PUT THIS IN A STANDARD MODULE 
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long


'PUT THIS IN A FORM
'Draw The mask
BitBlt Me.hDC, X, Y, SpriteWidth, SpriteHeight, picMask.hDC, (FrameNumber - 1) * SpriteWidth, 0, vbSrcAnd

'Draw the sprite
BitBlt Me.hDC, X, Y, SpriteWidth, SpriteHeight, picSprite.hDC, (FrameNumber - 1) * SpriteWidth, 0, vbSrcPaint
Ruairi

Could your manufacturing facility benefit from real time process monitoring? Would you like your employees to be able to see up to the minute goal and actual production?
For innovative, low cost solutions check out my website.
 
hihi! thanx RUAIRI!
i got some quiry!
how do i get the function" Private Declare Function BitBlt Lib "gdi32" "

you have say about the animations.
how i approached to open the file?
i got stuck in this problem.

i do not know where to start from?
 
help! i do not how to try out the last program. b4 this. does anyone have the complete program. then how to bring out the pic?

i am quite blur bout the program.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top