Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 602
  • Last Modified:

Tile Map in visual basic

I am confused with an answer I recieved I am trying to just get an example of a Window Moded VB map that I can scroll around and it still be decent.  I tried example below but cant get it to draw right it ends up drawing part of the form and willl not let me scroll to left and will not draw into map picture box only the back buffer one.

Three PictureBoxes.

The Picture Boxes are all set to scalemode vbPixel.
The Backbuffer and Source are set to AutoRedraw.
====================================
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByBal 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 Sub RefreshMap()
  'picSrc = Invisible Picture Box containing whole map
  'picBack = Invisible Picture Box for back buffer and work.
  'picDest = Picture Box for displaying to user.

  Dim picSrc As PictureBox
  Dim picBack As PictureBox
  Dim picDest As PictureBox

  Dim StartX As Long
  Dim StartY As Long

  Set picSrc = MainForm.pbSource
  Set picBack = MainForm.pbBack
  Set picDest = MainForm.pbMap

  StartX = -MainForm.HScrollMap.Value
  StartY = -MainForm.VScrollMap.Value

  BitBlt picBack.hDC, 0, 0, _
       picBack.ScaleWidth, picDest.ScaleHeight, _
       picSrc.hDC, StartX, StartY, vbSrcCopy

  'Do other things to picBack here like draw
  'on map text messages, sprites, etc.

  BitBlt picDest.hDC, 0, 0, _
       picDest.ScaleHeight, picDest.ScaleWidth, _
       picDest.hDC, 0, 0, vbSrcCopy

End Sub
======================================

 
0
Hook333
Asked:
Hook333
  • 2
1 Solution
 
HermeticCommented:
You have to set Min and Max of the scrollbars and refresh the picture boxes. like this:
(btw - The last bitblt has the width and height switched. and the second hDC should be of picBack.)

Private Sub Form_Load()
    HScrollMap.Min = 0
    VScrollMap.Min = 0
    HScrollMap.Max = pbSrc.ScaleWidth
    VScrollMap.Max = pbSrc.ScaleHeight
    HScrollMap.SmallChange = 5
    VScrollMap.SmallChange = 5
    HScrollMap.LargeChange = 50
    VScrollMap.LargeChange = 50
End Sub

Private Sub HScrollMap_Change()
    RefreshMap
    pbBack.Refresh
    pbMap.Refresh
End Sub

Private Sub HScrollMap_Scroll()
    RefreshMap
    pbBack.Refresh
    pbMap.Refresh
End Sub

Private Sub VScrollMap_Change()
    RefreshMap
    pbBack.Refresh
    pbMap.Refresh
End Sub

Private Sub VScrollMap_Scroll()
    RefreshMap
    pbBack.Refresh
    pbMap.Refresh
End Sub
0
 
HermeticCommented:
Just to be clear, the last BitBlt should be:

BitBlt picDest.hDC, 0, 0, _
      picDest.ScaleWidth, picDest.ScaleHeight, _
      picBack.hDC, 0, 0, vbSrcCopy


For the Scroll mins and maxs in my example, you either have to make them negative, or remove the minus sign in the RefreshMap function

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now