|
-
Feb 19th, 2001, 11:23 AM
#1
Thread Starter
Lively Member
-
Feb 19th, 2001, 11:49 AM
#2
Dont set the picture property to the image propery. That makes the images permenent. All drawing methods go to the image, not the picture. Hope that helps
-
Feb 19th, 2001, 11:56 AM
#3
Retired VBF Adm1nistrator
Why not blit all of your pictures ?
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 19th, 2001, 12:10 PM
#4
Thread Starter
Lively Member
Okay...
if I draw the city, place the tanks, and then set the autoredraw to true, but don't set the form's picture property, this image will not clear when I change screens. But, in order to draw the shell's path and the result of its explosion, I need to set autoredraw to false. If I set it to true after all the drawing, the drawing stays for the time being but will clear if I change windows and then come back again. Same deal if I leave it off after drawing the shell's path etc. I'm getting rather confused.
On Error Resume Screaming...

-
Feb 19th, 2001, 12:12 PM
#5
Thread Starter
Lively Member
Originally posted by plenderj
Why not blit all of your pictures ?
- jamie
because there is nowhere to blit them from. everything is done with line methods, circle methods, and setpixelV. I wanted to avoid having to use pictureboxes and package images with the app. I'm trying to keep size down.
On Error Resume Screaming...

-
Feb 19th, 2001, 12:16 PM
#6
Retired VBF Adm1nistrator
Well blitting really is the quickest way of doing things.
You dont actually need to use source pictureboxes, as in this example from my game :
Code:
Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Public 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
Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Public Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Public Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Function GenerateDC(FileName As String) As Long
DC = CreateCompatibleDC(0)
If DC < 1 Then
GenerateDC = 0
End
Exit Function
End If
hBitmap = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
If hBitmap = 0 Then
DeleteDC DC
GenerateDC = 0
MsgBox FileName & "," & Dir(FileName)
Err.Raise vbObjectError + 2
Exit Function
End If
SelectObject DC, hBitmap
GenerateDC = DC
DeleteObject hBitmap
End Function
'THEN TO GENERATE THE DEVICE CONTEXTS ::
dc_ship(0) = GenerateDC(App.Path & "\images\ship_0.bmp")
For i = 1 To 35
dc_ship(i) = GenerateDC(App.Path & "\images\ship_" & i & "0.bmp")
Next i
dc_obj_0 = GenerateDC(App.Path & "\images\ship_0.bmp")
dc_blip_ship = GenerateDC(App.Path & "\images\radar_ship.bmp")
dc_blip_station = GenerateDC(App.Path & "\images\radar_station.bmp")
dc_fire_lasers = GenerateDC(App.Path & "\images\laser_1_0_.bmp")
dc_explode_craft_1 = GenerateDC(App.Path & "\images\explode_1.bmp")
dc_explode_craft_2 = GenerateDC(App.Path & "\images\explode_2.bmp")
'THEN IN-GAME, TO DO THE BLITTING :
BitBlt Me.hdc, .cords.x, .cords.y, 81, 81, dc_ship(.angle / 10), 0, 0, vbSrcInvert
Its real easy to muck around.
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 19th, 2001, 05:59 PM
#7
Thread Starter
Lively Member
Howsabout this...
Is it possible for me to usecreatecompatibleDC to copy my form's DC, then do all my drawing to that and then blit from my invisible DC to my form's DC? I tried doing something like that before, but nothing happened - no drawings, no errors, nothing.
On Error Resume Screaming...

-
Feb 20th, 2001, 12:18 AM
#8
Addicted Member
hey where are you drawing all of this stuff to? the form? if you're using drawing commands put the drawing commands in the forms Paint event. when you change between forms if should then redraw what was the there before. i've had the same problem before with directx. i was only drawing to the screen when i needed to instead of having a continous loop. when i had a window open everything behind it disapeared until i had drawn to the screen again.
I see said the blind man as he spat into the wind.
It all comes back to me now!
A.D.T.'s VB
-
Feb 20th, 2001, 03:15 AM
#9
Retired VBF Adm1nistrator
DarkJedi, thats what the code above does 
It creates DCs in memory, and then blits from those onto your form.
Its real easy to work with.
Just try messing around with my code.
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 20th, 2001, 03:18 AM
#10
Retired VBF Adm1nistrator
You also need a couple of variables... unless you have the VC++ header files you'd be hard pushed to find these :
Code:
'' Device Contexts used for blitting
Public dc_ship(0 To 35) As Long
Public dc_obj_0 As Long '' Device Context (for blitting)
Public dc_blip_ship As Long '' Device Context for blitting ship radar blips
Public dc_blip_station As Long '' Device Context for blitting station radar blips
Public dc_fire_lasers As Long '' Device Context for blitting lasers
Public dc_station() As Long '' Device Context for blitting space stations
Public dc_explode_craft_1 As Long '' Device Context for blitting craft's explosion #1
Public dc_explode_craft_2 As Long '' Device Context for blitting craft's explosion #2
'' Variables used for GenerateDC Function
Public DC As Long '' Device Context object
Public hBitmap As Long '' Bitmap object
Const IMAGE_BITMAP As Long = 0
Const LR_LOADFROMFILE As Long = &H10
Const LR_CREATEDIBSECTION As Long = &H2000
Const LR_SHARED As Long = &H8000
Thats a copy-n-paste from my game, so some of it isnt needed.
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 20th, 2001, 05:43 AM
#11
Addicted Member
You must set the AutoRedraw to True BEFORE you draw anything on the Form/PictureBox. Then, after you've done drawing, call the Refresh method to display the contents. It's simple as that...
-
Feb 20th, 2001, 05:56 PM
#12
You dont need to call refresh, as the form will be refreshed as soon as the window gets a WM_PAINT message (Idle Time, or when the program hits a DoEvents)
-
Feb 20th, 2001, 11:50 PM
#13
Thread Starter
Lively Member
Originally posted by Arcom
You must set the AutoRedraw to True BEFORE you draw anything on the Form/PictureBox. Then, after you've done drawing, call the Refresh method to display the contents. It's simple as that...
But if I have autoredraw set to true, then the drawing flickers and all that while I'm drawing it. It looks pretty crappy.
Basically, I need to edit what the autoredraw is redrawing. Whatever I do doesn't seem to be working. Either that or I need to know why when I try to draw on a DC I created nothing happens.
On Error Resume Screaming...

-
Feb 21st, 2001, 02:52 AM
#14
Retired VBF Adm1nistrator
DarkJedi,
Check out the thread I've just made :
http://forums.vb-world.net/showthrea...threadid=56233
Ive posted the source code to my game.
You can see how I've done the blitting.
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 21st, 2001, 04:43 PM
#15
Thread Starter
Lively Member
I think I'm getting the hang of this.(?)
So this code works when the autoredraw property is set to true. But only if I have the picture = image lines. This is okay, though. Only problem is: how do I clear out the picture property? Is there a way to do it besides just coloring over all my drawings with gray and then setting picture to image again? Also, what if I want to draw the shell's path? Will I have to set the picture to image every time I draw a pixel? That's what it seems like but that is pretty ridiculous.
Private Sub Command1_Click()
Dim FormDC As Long
Dim BackDC As Long
Dim OldBrush As Long
Dim OldPen As Long
Dim NewBrush As Long
Dim NewPen As Long
Dim Color As Long
NewPen = CreatePen(PS_SOLID, 9, &HFF)
OldPen = SelectObject(Form1.hdc, NewPen)
NewBrush = CreateSolidBrush(&HFF)
OldBrush = SelectObject(Form1.hdc, NewBrush)
Rectangle Form1.hdc, 50, 50, 100, 100
Form1.Picture = Form1.Image
SelectObject Form1.hdc, OldBrush
SelectObject Form1.hdc, OldPen
Rectangle Form1.hdc, 50, 50, 100, 100
Form1.Picture = Form1.Image
DeleteObject NewPen
End Sub
P.S. I still can't get the createcompatibleDC thing to work. Or maybe the DC works, but when I draw to it and try to blit it to my form it doesn't work. If anyone would like to look at my code, I'll put it in a new reply; this one is getting pretty lenghty.
Last edited by DarkJedi9; Feb 21st, 2001 at 04:47 PM.
On Error Resume Screaming...

-
Feb 21st, 2001, 05:24 PM
#16
Fanatic Member
To clear the Picture box of the Picture...
Code:
Picture1.Picture = LoadPicture("")
and to get the offscreen DC to work you need to use the CreateCompatibleBitmap function and select it into the DC first.
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Feb 21st, 2001, 10:03 PM
#17
Thread Starter
Lively Member
Thank You!!!
Thanks so much! This has been p**sing (can I say that?)me off for days. Everybody who replied; thanks for your help. You guys are the best!
On Error Resume Screaming...

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|