Help needed converting a VB6 Project

Drewpeu

Member
Licensed User
Hi Guys,
Any help would be great. :sign0085:

How can I do the following:
PictureBox Arrays:
Bug(0) to Bug(7)

for i = vaderst to vaderfin
bug(i).Left = looperx:Bug(i).Top = loopery
next


Image Arrays:
imaBugSplat(0) to imgBugSplat(7)
Bug(BKI) = imgBugSplat(KI) '<---KILLS BUGS DEAD

I am also having trouble with this line:
Randomize Val(Right(Time$, 2)) / 3.17412

Line's and Shapes's were easy to convert:
pen1.Color = cGold
line(160,150,160,350)

Sub Line(x1,y1,x2,y2)
drawer.DrawLine(pen1.Value,x1,y1,x2,y2)
drawer.Refresh(x1-x2,y1-y2,x1-x2,y1-y2)
End Sub


Can we Use/Create VB6 Class Modules

Is their an equivelent of the following:

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


Thanks in advance,

Andrew.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
VB6 PictureBoxes are Image controls in Basic4ppc.
Create 7 images (at the beginning of your program):
B4X:
    'create 7 image controls
    For i = 0 To 7 
        AddImage("Form1","Image" & i,x,y,width,height)
    Next

Move images:
B4X:
    For i = vaderst To vaderfin
        Control("Image" & i).Left = looperx
        Control("Image" & i).Top = loopery
    Next
You can store the images (not controls) in an ImageList and then assign these images to the image controls when needed:
B4X:
Control("Image" & BKI) = ImageList.Item(KI)

What values do you expect from the Randomize statement?
It is not possible to use VB6 class modules..
Basic4ppc can only interact with .Net modules (c# or VB.Net)
There is no equivalent to BitBlt.
 

Drewpeu

Member
Licensed User
Re Help Needed converting a VB6 Project

Hi Erel,

Thank you for your speedy and helpfull responce.

The code samples you provided work a treat.

The Randomize statement is used to generate randome enemy fire
by setting and resetting the tmrTimer_EnemyFire Subroutine.

Any chance that you or one of your many Library coders could
create a Basic4ppc bitblt dll? :)

Thanks again.

Regards,
Andrew
 

Drewpeu

Member
Licensed User
Hi again Erel,

Please find below as requested!

BitBlt quite simply makes copies of portions of the screen.
This is done by accessing the Windows hDC and other low level mind numbing things.
This is similar to your:


drawer.New1("Form1",true)
rectSrc.New1(0,0,bmp.Width,bmp.Height) 'The source rectangle.
rectDest.New1(120,120,36,32)
drawer.DrawImage1(bmp.Value,rectSrc.Value,rectDest.Value,true)
Form1.DrawString("Try to catch the smiley",12,10,10,200,50,cBlack)


It is a very fast routine, you dont get the flickering as you do in tha above routine
This has been on the go since VB3 and I still use it in VB6:

Declare the functions that are in the GDI32.DLL file so we can use them in VB.NET.

Declare Auto Function BitBlt Lib "GDI32.DLL" ( _
ByVal hdcDest As IntPtr, _
ByVal nXDest As Integer, _
ByVal nYDest As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, _
ByVal nYSrc As Integer, _
ByVal dwRop As Int32) As Boolean

Private Function copyRect(ByVal src As PictureBox, _
ByVal rect As RectangleF) As Bitmap

'Get a Graphics Object from the form

Dim srcPic As Graphics = src.CreateGraphics

'Create a EMPTY bitmap from that graphics

Dim srcBmp As New Bitmap(src.Width, src.Height, srcPic)

'Create a Graphics object in memory from that bitmap

Dim srcMem As Graphics = Graphics.FromImage(srcBmp)

'get the IntPtr's of the graphics

Dim HDC1 As IntPtr = srcPic.GetHdc

'get the IntPtr's of the graphics

Dim HDC2 As IntPtr = srcMem.GetHdc

'get the picture

BitBlt(HDC2, 0, 0, rect.Width, _
rect.Height, HDC1, rect.X, rect.Y, 13369376)

'Clone the bitmap so we can dispose this one

copyRect = srcBmp.Clone()

'Clean Up

srcPic.ReleaseHdc(HDC1)
srcMem.ReleaseHdc(HDC2)
srcPic.Dispose()
srcMem.Dispose()
srcMem.Dispose()
End Function


Then all we need to do is call the function to return the image we want:

Dim bmp = CType(copyRect(src, _
New RectangleF(0, 0, 50, src.Height)), Bitmap)
dest.Image = bmp.CloneShorthand:

-or-
dest.Image = CType(copyRect(src, _
New RectangleF(0, 0, 50, src.Height)), Bitmap).Clone


Regards,
Andrew.
 

agraham

Expert
Licensed User
Longtime User
However if anyone is interested in building such a library it shouldn't be too complicated.
That's what I thought but! .... :( .... there is some hidden twist that I don't presently understand. having obtained the hdcs for a couple of .NET Bitmaps I can BitBlt BLACKNESS and WHITENESS onto the destination bitmap but even thought BtBlt returns true (success) it won't pick up the contents of the source bitmap for SRCCOPY and the other SRC... raster ops. I have no idea why :confused: I'll look again tomorrow - my brain's hurting!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
That's what I thought but! .... :( .... there is some hidden twist that I don't presently understand. having obtained the hdcs for a couple of .NET Bitmaps I can BitBlt BLACKNESS and WHITENESS onto the destination bitmap but even thought BtBlt returns true (success) it won't pick up the contents of the source bitmap for SRCCOPY and the other SRC... raster ops. I have no idea why :confused: I'll look again tomorrow - my brain's hurting!

Oops. There are many simple looking computer problems that end with huge efforts.
How about this one:
Can you write a program that receives some code and checks if this code always stop?
http://en.wikipedia.org/wiki/Halting_problem
 

agraham

Expert
Licensed User
Longtime User
If you have a problem let me know.
Lots of problems interoperating from GDI+ to GDI which explains the odd behaviour I have observed while experimenting. INFO: Interoperability Between GDI and GDI+. The key paragraph is "Using GDI on a GDI+ Graphics Object Backed by a Bitmap"

A concise summary of a highly technical situation.

An hDC from a .NET Graphics for a Bitmap created by Graphics.FromImage(Bitmap) is effectively write-only as the underlying bitmap is not initialised. Therefore you can draw on it but not use it as a source.

An hDC from a .NET Graphics for a Control created by Control.CreatGraphics().GetHdc() is both readable and writeable as a physical bitmap exists on the screen.

Therefore BitBlt can be used for screen capture using the SRCCOPY rasterop to a destination bitmap and for very little else as the combinatorial rasterops do not have a destination to read. For this reason the the BitBlt way of achieving tranparency and animation won't work as it relies on the combinatorial rasterops SRCAND and SRCPAINT :(

GDI gurus may have a way round this but I am afraid that I don't know enough about GDI (and don't want to learn either) so I'll have to give up for now.
 

Drewpeu

Member
Licensed User
agraham said:
GDI gurus may have a way round this but I am afraid that I don't know enough about GDI (and don't want to learn either) so I'll have to give up for now.

That is a shame!
Thanks for trying, I have noticed that this forum is a very helpfull one unlike some others I know! :(
 

taximania

Well-Known Member
Licensed User
Longtime User
How about this one:
Can you write a program that receives some code and checks if this code always stop?

:sign0137: That's some heavy reading.

What came first, the chicken or the egg ? :sign0148:

Do all theories come to a solution, or are some so debetable
an answer is unobtainable :sign0136: ha ha ha
 
Top