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

47493Re: [LIBERTYBASIC] Re:

Expand Messages
  • Marc Rossi
    May 3, 2014
    • 0 Attachment
      Rod.  Here is my code.  Can you see what I am doing wrong?
      Thanks,
      Marc
      nomainwin
      global w
      global h
      global width
      global height
      ' now open our window as a full screen popup window
      WindowWidth  = DisplayWidth - (1 * -1)
      WindowHeight = DisplayHeight - (1 * -1)
        w = WindowWidth - 5
        h = WindowHeight - 5
       menu #gwin, "&File", "&Open", [OP],"&Exit", [quit]
       menu #gwin, "&Mirror","&Mirror Horizontal", [m]
       menu #gwin, "&Properties", "Properties of bitmap", [properties]
       graphicbox #gwin.gbox, 0,0,w - 15,h - 15
       open "Picview" for window_popup as #gwin
       print #gwin.gbox, "trapclose [quit]"
       print #gwin.gbox, "vertscrollbar on"
       print #gwin.gbox, "horizscrollbar on"
       print #gwin.gbox, "down;fill black"
       print #gwin.gbox, "flush"
       ' print #gwin,   "trapclose [quit]"


      wait
      [OP]
      filedialog "Open Graphics File", "*.bmp", gfile$
      if gfile$ = "" then close #gwin: END
      loadbmp "g", gfile$
       bmphandle = hbmp("g")
      'print #prop, "Height of bitmap = ";heightBitmap
      ' create a struct to hold the retrieved info
       STRUCT BITMAP,_
       bmType as long,_
       bmWidth as long,_
       bmHeight as long,_
       bmWidthBytes as long,_
       bmPlanes as word,_
       bmBitsPixel as word,_
       bmBits as long
      nSize = len(BITMAP.struct) ' returns the length of the struct
      p = GetObjectA(bmphandle,nSize,Bitmap,result)
      print #gwin.gbox, "flush"
       type = BITMAP.bmType.struct
       width = BITMAP.bmWidth.struct
       height = BITMAP.bmHeight.struct
       widthBytes = BITMAP.bmWidthBytes.struct
       planes = BITMAP.bmPlanes.struct
       bp = BITMAP.bmBitsPixel.struct

       ' bDC is our screen
      bDC = GetDC(hwnd(#gwin.gbox))
      ' mDC is a copy of the screen in memory
      mDC=CreateCompatibleDC(bDC)
       ' select the loaded bmp into the memory DC
      oldBmp=SelectObject(mDC,bmphandle)
      [mp]
      if used = 2 then goto [m]
      used = 2
      print #gwin.gbox, "down;fill black"
      call StretchBlt,bDC,0,0,width,height,mDC,0,0, width,height    ' hDCdest, xdest, yDest, xWidth,yHeight ,hDCsource,xSrc,ySrrc,result
      print #gwin.gbox, "down;drawbmp 0 0"
      print #gwin.gbox, "flush"
      wait
      [m]
      print #gwin.gbox, "down;fill black"
      turn = 1 * w
      turnminus = turn * -1
      if used = 1 then goto [mp]  ' if it is already reversed then mirror it back to normal
       call StretchBlt,bDC,0,0,width,height,mDC,0 ,0,width,height ' \destination x pos \destination y pos\ destination width desired  \destination height desired hDCsrc As ulong
                                                       ' x location to start from source  y location to start from source\ width desired from source\ height desired from source
        print #gwin.gbox, "FLUSH"
       used = 1
      wait
      [properties]
      WindowWidth = 500
       WindowHeight = 300
      open "Properties" for text as #t
      print #t, "!trapclose [quit2]"
      print #t,"Properties of bitmap"
      print#t, " "
      print #t, "Type of Bitmap:";bp; " bits per pixel"
      print #t, "Width:";width
      print #t, "Height:";height
      print #t, "result= ";result
      ' print #t, "Success,non-zero=yes";r
      wait
      function GetDC(hWnd)
      calldll #user32,"GetDC",_
      hWnd as ulong,_
      GetDC as ulong
      end function

      function GetObjectA(bmphandle,nSize,BITMAP,result)
       calldll #gdi32, "GetObjectA",_
       bmphandle as long,_ ' handle of object queried
       nSize as long,_ ' number of bytes in struct
       BITMAP as struct,_ ' address of struct
       result as long ' retrieves the number of bytes retreived, 0 on error
      end function
      sub PatBlt hDCdest, xdest, yDest, xWidth,yHeight,hDCsource,xSrc,ySrrc
      calldll #gdi32, "PatBlt",_
      hDCdest as ulong,_
      xdest as long,_
      yDest as long,_
      xWidth as long,_
      yHeight as long,_
      hDCsource as ulong,_
      xSrc as long,_
      ySrrc as long,_
      result as ulong
      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 Long
       End Sub
       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 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 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 Long
       End Sub


      wait

      [quit]

      unloadbmp "g"
       call ReleaseDC hwnd(#gwin), gDC
       call DeleteDC mDC
       close #gwin

      END
      wait
      [quit2]
      close #t
      wait

      On Saturday, May 3, 2014 6:31 AM, Marc Rossi <mrossi8888@...> wrote:
       
      Hi, Rod.  I looked at your code and I was only getting the bmp using the memory commands  GetDC etc..
      Do I have to draw the bmp or use getbmp to make it work?
      Thanks,
      Marc
      On Saturday, May 3, 2014 6:05 AM, "rodbird@..." <rodbird@...> wrote:
       
      Flush does make the difference, remove the flush in this code and your error is replicated. So do you have the flush command in the correct place? Is it bypassed or never called?

       WindowWidth = 650
          WindowHeight = 650
          open "temp" for graphics as #1
          #1 "down"
          for x= 0 to 540 step 60
          for y= 0 to 540 step 60
              if toggle then
                  #1 "backcolor red"
                  #1 "place ";x;" ";y;" ; boxfilled ";x+60;" ";y+60
                  toggle=0
              else
                  #1 "backcolor yellow"
                  #1 "place ";x;" ";y;" ; boxfilled ";x+60;" ";y+60
                  toggle=1
              end if
          next
          next
          #1 "getbmp bmp 0 0 600 600"
          close #1

          WindowWidth = 300
          WindowHeight = 300
          graphicbox #1.gb, 0, 0, 200, 200
          open "test" for window as #1
          #1 "trapclose [quit]"
          #1.gb "horizscrollbar on 0 400"
          #1.gb "vertscrollbar on 0 400"
          #1.gb "down ; drawbmp bmp 0 0 ; flush"
          wait

          [quit]
          close #1
          end





    • Show all 7 messages in this topic