Loading ...
Sorry, an error occurred while loading the content.

47156RE: StrecchtBlt

Expand Messages
  • rod_bird001
    Nov 13, 2013
    • 0 Attachment

      You may need to double buffer but try this text overlay and see if it works for you. The scrolling needs the star field duplicated top and bottom to give a seamless scroll.

       

       NOMAINWIN

          'I need to know the exact size of the drawing area
          'because getbmp can only get what is visible.
          'I need 500x700 to be visible. This is simply a
          'complication of the getbmp code if you load a 500x700 bmp
          'it will work anyway but if I getbmp from a 500x700 window
          'I will lose the edges and bottom due to Windows title bar
          'and side bars

          WindowWidth = 200
          WindowHeight = 200
          open "Ajusting..." for graphics_nf_nsb as #1
          #1, "home ; down ; posxy w h"
          w=200-2*w : h = 200-2*h
          close #1
          WindowWidth  = 500+w
          WindowHeight = 700+h
          UpperLeftX   = (DisplayWidth-WindowWidth)/2
          UpperLeftY   = (DisplayHeight-WindowHeight)/2
          graphicbox #runner.gb, 0,0,502,702
          open "Space Destroyer" for graphics_nf_nsb  as #runner
          #runner "trapclose [quit]"
          #runner.gb "font comic sans 20"
          global energy
          global deadboong1
          global deadboong2

          global score
          global start
          varx = 235
          vary = 420
          energy = 4
          score = 0

          bx = 0
          by = 0
          start = 1

          ' open the dll file used for TransparentBlt
          open "msimg32.dll" for dll as #m


          #runner.gb "down ; fill black"
          #runner.gb "color white"
          'paint some stars in the TOP half of the window
          for d = 1 to 350
              #runner.gb "size ";int(rnd(0)*4)
              #runner.gb "set ";int(rnd(0)*500);" ";int(rnd(0)*350)
          next d
          'now copy that to the BOTTOM half
          #runner.gb "getbmp bmp 0 0 500 350"
          #runner.gb "drawbmp bmp 0 350"
          #runner.gb "getbmp bmp 0 0 500 700"

          'that sets us up to be able to scroll a 350 deep box
          'down the 700 deep image. At the boundary you are
          'blitting 350 below but as the images are identical
          'the scroll round is seemles.

          times = times + 1

           'sDC is our screen buffer, (DC handle to the graphicsbox)
          sDC=GetDC(hwnd(#runner.gb))

          'as this is the main drawing screen we set transparent text drawing
          'on. Any Text drawing will have a transparent background.
          call SetBkMode,sDC,1

          'mDC is a copy of the screen in memory
          mDC=CreateCompatibleDC(sDC)


          'select our 500x700 bmp graphic resource into the memory dc
          hBitmap=hbmp("bmp")

          oldBmp=SelectObject(mDC,hBitmap)

          ' draw initial ship
          timer 50,  [movement]

          [movement]
          ' move the background

          y = y - 1
          if y<0 then y=350


          'first blit the star field double height to fill the screen
          call StretchBlt sDC,0,0,500,700,mDC,0,y,500,350

          'now overlay the text, there are three new functions added to
          'allow this. You might also separate the graphicboxes but you
          'can't overlay them easily.
          'You may notice this text flicker, if it flickers too much you
          'will need to double buffer, this is covered in the lesson file

          'set the txt color and draw it
          call SetTextColor,sDC,(255*256*256)+(0*256)+(0)'blue
          call TextOutA,sDC,10,40,"Energy = ";str$(energy)

          'set the second  txt color and draw it
          call SetTextColor,sDC,(0*256*256)+(255*256)+(0)'green
          call TextOutA,sDC,360,40,"Score = ";str$(score)

          wait

      Function GetDC(hWnd)
          CallDLL #user32, "GetDC",_
              hWnd As ulong,_  'window or control handle
              GetDC As ulong   'returns device context
          End Function

      Sub ReleaseDC hWnd, hDC
          CallDLL#user32,"ReleaseDC",_
              hWnd As ulong,_  'window or control handle
              hDC As ulong,_   'handle of DC to delete
              result As Long
          End Sub

      Function CreateCompatibleDC(hDC)
          CallDLL #gdi32,"CreateCompatibleDC",_
              hDC As ulong,_               'window DC
              CreateCompatibleDC As ulong  'memory DC
          End Function

      Sub DeleteDC hDC
          CallDLL #gdi32, "DeleteDC",_
          hDC As ulong,_   'memory DC to delete
          r As Boolean
          End Sub

      Sub StretchBlt hDCdest,x,y,w,h,hDCsrc,x2,y2,w2,h2
          CallDLL #gdi32, "SetStretchBltMode",_
              hDCdest As ulong,_       'device context
              _COLORONCOLOR As Long,_ 'color reduction mode
              RESULT As Long
          CallDLL #gdi32, "StretchBlt",_
              hDCdest As ulong,_   'destination
              x As Long,_         'destination x pos
              y As Long,_         'destination y pos
              w As Long,_         'destination width desired
              h As Long,_         'destination height desired
              hDCsrc As ulong,_    'source
              x2 As Long,_        'x location to start from source
              y2 As Long,_        'y location to start from source
              w2 As Long,_        'width desired from source
              h2 As Long,_        'height desired from source
              _SRCCOPY As long,_ 'dwRasterOperation
              RESULT As Boolean
          End Sub

      Sub TransparentBlt hDCdest,x,y,w,h,hDCsrc,x2,y2,w2,h2,crTransparent
          calldll #m, "TransparentBlt",_
              hDCdest As uLong,_  'destination
              x As Long,_         'destination x pos
              y As Long,_         'destination y pos
              w As Long,_         'destination width desired
              h As Long,_         'destination height desired
              hDCsrc As uLong,_    'source
              x2 As Long,_        'x location to start from source
              y2 As Long,_        'y location to start from source
              w2 As Long,_        'width desired from source
              h2 As Long,_        'height desired from source
              crTransparent as ulong,_ 'color to make transparent 0=Black
              result as boolean
          end sub


      Function SelectObject(hDC,hObject)
          CallDLL #gdi32,"SelectObject",_
              hDC As ulong,_        'memory device context
              hObject As long,_    'handle of object
              SelectObject As long 'returns previously selected object
          End Function

       

      Sub SetBkMode hDC, flag
          '1=transparent
          '2=opaque
          CallDLL #gdi32, "SetBkMode",hDC As ulong,_
          flag As long, RESULT As long
          End Sub

      Sub TextOutA hDc,X,Y,text$
          lengthtext=len(text$)
          calldll #gdi32, "TextOutA", _
          hDc as ulong,_      'device context of window or graphicbox
          X as long,_         'x origin of text
          Y as long,_         'y origin of text
          text$ as ptr,_      'text string to display
          lengthtext as long,_'length of text string
          result as long      'nonzero if successful
          End Sub

      sub SetTextColor hDc,crColor
          calldll #gdi32, "SetTextColor", _
          hDc as ulong,_      'device context of window or control
          crColor as long,_   'long integer color value
          result as long      'returns previous text color, if successful
          End Sub

       

       

      wait
      [whatabout]


      notice "Space Destroyer" + chr$(13)  + chr$(13); "     By m f r   2013"


      wait
      [quit]
      timer 0
      call ReleaseDC hwnd(#runner), gDC
      call DeleteDC mDC
      close #runner
      close #m
      end  ' end program

       

       



      ---In libertybasic@yahoogroups.com, <mrossi8888@...> wrote:

      Rod, I have this code I cannot figure out what is wrong with it.  If you could look at it I would appreciate it.

      Marc

      PS>  This is just the code that does not work.  I have more that works but didn't include it so you don't have to load the BMP's.

      Marc

       

      ' code start

      NOMAINWIN

      Menu #runner,"&Program", "&About", [whatabout]
      Menu #runner, "&Exit", "&Quit", [quit]
      ' LOADBMP,"big",  "big.bmp"
      dim alienboong(3,3)  ' alien ships are made in this array
      WindowWidth = 500
      WindowHeight = 700
      UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
      UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
      graphicbox #runner.score, 0, 0, 100, 30
      graphicbox #runner.totalnum, 400, 0, 100, 30
      open "Space Destroyer" for graphics_nf_nsb  as #runner
      print #runner, "trapclose [quit]"
      global energy
      global deadboong1
      global deadboong2

      global score
      global start
      varx = 235
      vary = 420
      energy = 4
      score = 0

      bx = 0
      by = 0
      start = 1

      ' open the dll file used for TransparentBlt
      open "msimg32.dll" for dll as #m


      print #runner, "down ; fill black"
      print #runner, "color white"
      for d = 1 to 700
      print #runner, "set ";int(rnd(0)*500);" ";int(rnd(0)*600)
      next d
      print #runner, "getbmp bmp 0 30 500 700"

              print #runner, "drawbmp bmp 30 350"

              unloadbmp "bmp"
               print #runner, "getbmp bmp 0 30 500 350"
      'loadbmp "total","total.bmp"

      print #runner.score, "place 10 20 ;\Energy=";energy
      print #runner.totalnum, "place 10 20 ;\Score=";score
      times = times + 1

           'sDC is our screen buffer, (DC handle to the graphicsbox)
           sDC=GetDC(hwnd(#runner))

           'mDC is a copy of the screen in memory
           mDC=CreateCompatibleDC(sDC)

          ' select our bmp graphic resource into the memory dc
          hBitmap=hbmp("bmp")

          oldBmp=SelectObject(mDC,hBitmap)

      ' draw initial ship
      timer 50,  [movement]

      [movement]
      ' move the background

      y = y - 1
      if y=abs(-700) then y=30

      call StretchBlt sDC,0,30,500,700,mDC,0,y,500,350  'destination x pos 'destination y pos destination width desired 'destination height desired
                                                'source 'x location to start from source 'y location to start from source 'width desired from source 'height desired from source 'dwRasterOperation
      wait

      Function GetDC(hWnd)
          CallDLL #user32, "GetDC",_
              hWnd As ulong,_  'window or control handle
              GetDC As ulong   'returns device context
          End Function

      Sub ReleaseDC hWnd, hDC
          CallDLL#user32,"ReleaseDC",_
              hWnd As ulong,_  'window or control handle
              hDC As ulong,_   'handle of DC to delete
              result As Long
          End Sub

      Function CreateCompatibleDC(hDC)
          CallDLL #gdi32,"CreateCompatibleDC",_
              hDC As ulong,_               'window DC
              CreateCompatibleDC As ulong  'memory DC
          End Function

      Sub DeleteDC hDC
          CallDLL #gdi32, "DeleteDC",_
          hDC As ulong,_   'memory DC to delete
          r As Boolean
          End Sub

      Sub StretchBlt hDCdest,x,y,w,h,hDCsrc,x2,y2,w2,h2
          CallDLL #gdi32, "SetStretchBltMode",_
              hDCdest As ulong,_       'device context
              _COLORONCOLOR As Long,_ 'color reduction mode
              RESULT As Long
          CallDLL #gdi32, "StretchBlt",_
              hDCdest As ulong,_   'destination
              x As Long,_         'destination x pos
              y As Long,_         'destination y pos
              w As Long,_         'destination width desired
              h As Long,_         'destination height desired
              hDCsrc As ulong,_    'source
              x2 As Long,_        'x location to start from source
              y2 As Long,_        'y location to start from source
              w2 As Long,_        'width desired from source
              h2 As Long,_        'height desired from source
              _SRCCOPY As long,_ 'dwRasterOperation
              RESULT As Boolean
          End Sub

      Sub TransparentBlt hDCdest,x,y,w,h,hDCsrc,x2,y2,w2,h2,crTransparent
          calldll #m, "TransparentBlt",_
              hDCdest As uLong,_  'destination
              x As Long,_         'destination x pos
              y As Long,_         'destination y pos
              w As Long,_         'destination width desired
              h As Long,_         'destination height desired
              hDCsrc As uLong,_    'source
              x2 As Long,_        'x location to start from source
              y2 As Long,_        'y location to start from source
              w2 As Long,_        'width desired from source
              h2 As Long,_        'height desired from source
              crTransparent as ulong,_ 'color to make transparent 0=Black
              result as boolean
          end sub


      Function SelectObject(hDC,hObject)
          CallDLL #gdi32,"SelectObject",_
              hDC As ulong,_        'memory device context
              hObject As long,_    'handle of object
              SelectObject As long 'returns previously selected object
          End Function

       

       

       

      wait
      [whatabout]


      notice "Space Destroyer" + chr$(13)  + chr$(13); "     By m f r   2013"


      wait
      [quit]
      unloadbmp "total"
      call ReleaseDC hwnd(#runner), gDC
      call DeleteDC mDC
      close #runner
      close #m
      end  ' end program

       

      ' code end

    • Show all 3 messages in this topic