JanetTerra
Apr 30, 2006
This is Demo 2 to Accompany [[Drawing a Tiled Background with CreateCompatibleBitmap]] [[code format="vbnet"]] ' Demo2: Transferring the Image with BitBltNomainwin WindowWidthNomainwin WindowWidth = 600WindowHeightWindowHeight = 400GraphicboxGraphicbox #w.g1, 10, 10, 102, 102StatictextStatictext #w.st1a, "Image Source", 8, 120, 110, 32GraphicboxGraphicbox #w.g2, 140, 10, 440, 119StatictextStatictext #w.st2a, "Image transferred from memory using", 138, 140, 200, 16StatictextStatictext #w.st2b, "CallDLL #gdi32, 'BitBlt'", 138, 156, 200, 16 ' Open the WindowOpenOpen "Demo" For Window as #w#w,#w, "Trapclose EndProgram"#w.g2,#w.g2, "Horizscrollbar On 0 600" ' Display Solid BackgroundsCallCall hueBackground "#w.g2", "Darkgreen" ' Get handles and dc of second graphicbox with GetDC ' Place handle numbers in array to make globalhWG1hWG1 = hWnd(#w.g1)hDC1hDC1 = GetDC(hWG1)hWG2hWG2 = hWnd(#w.g2)hDC2hDC2 = GetDC(hWG2) ' Create two compatible memory DC with CreateCompatibleDCdcMem1dcMem1 = CreateCompatibleDC(hDC1) ' Compatible with #w.g1 'memDCMemDC(1)MemDC(1) = dcMem1dcMem2dcMem2 = CreateCompatibleDC(hDC2) ' Compatible with #w.g2MemDC(2)MemDC(2) = dcMem2 ' Get a simple bitmap for appending#w.g1,#w.g1, "Getbmp AppendBitmap 0 0 1200 100" ' Obtain the handle of this simple bitmaphAppendBitmaphAppendBitmap = hBmp("AppendBitmap") ' Create a large bitmap with CreateCompatibleBmp ' Use ScreenDC and not MemoryDChMemBitmaphMemBitmap = CreateCompatibleBitmap(hDC2, 1200, 100) ' Select the appending bitmap into the second memory device contexthAppendBitmaphAppendBitmap = SelectObject(dcMem2, hAppendBitmap) ' Draw the first bitmap and get its handleCallCall SimpleHouse "#w.g1", 0, 0#w.g1,#w.g1, "Getbmp SimpleHouse 0 0 100 100"#w.g1,#w.g1, "Flush"hSimpleHousehSimpleHouse = hBmp("SimpleHouse") ' Draw the second bitmap and get its handleCallCall hueBackground "#w.g1", "Darkblue"CallCall SimpleTrees "#w.g1", 0, 0#w.g1,#w.g1, "Getbmp SimpleTrees 0 0 100 100"#w.g1,#w.g1, "Flush"hSimpleTreeshSimpleTrees = hBmp("SimpleTrees") ' Draw the third bitmap and get its handleCallCall hueBackground "#w.g1", "Darkblue"CallCall SimpleFence "#w.g1", 0, 0#w.g1,#w.g1, "Getbmp SimpleFence 0 0 100 100"#w.g1,#w.g1, "Flush"hSimpleFencehSimpleFence = hBmp("SimpleFence") ' Select the bitmap into the first memory device contexthSimpleHousehSimpleHouse = SelectObject(dcMem1, hSimpleHouse) ' BitBlt the 1st memory device context to the 2nd memory device contextnullnull =BitBlt(dcMem2, 0, 0, 100, 100, dcMem1, 0, 0, _SRCCOPY) ' Select the bitmap into the first memory device contexthSimpleTreeshSimpleTrees = SelectObject(dcMem1, hSimpleTrees) ' BitBlt the 1st memory device bitmap to the 2nd memory device contextnullnull =BitBlt(dcMem2, 100, 0, 100, 100, dcMem1, 0, 0, _SRCCOPY) ' Select the bitmap into the first memory device contexthSimpleFencehSimpleFence = SelectObject(dcMem1, hSimpleFence) ' BitBlt the 1st memory device context to the 2nd memory device contextnullnull =BitBlt(dcMem2, 200, 0, 200, 100, dcMem1, 0, 0, _SRCCOPY) ' Deselect the bitmap from memoryhMemBitmaphMemBitmap = SelectObject(dcMem2, hMemBitmap) ' ReleaseDC on Screen DCnullnull = ReleaseDC(hWG1, hDC1)nullnull = ReleaseDC(hWG2, hDC2) ' DeleteDC on both memory DC'snullnull = DeleteDC(dcMem1)nullnull = DeleteDC(dcMem2) 'Loadbmp from handleLoadbmpLoadbmp "SimpleScene", hMemBitmap#w.g2,#w.g2, "Drawbmp SimpleScene 0 0"#w.g2,#w.g2, "Flush"WaitWait Sub EndProgram handle$UnloadbmpUnloadbmp "SimpleHouse"UnloadbmpUnloadbmp "SimpleTrees"UnloadbmpUnloadbmp "SimpleScene"CloseClose #wEndEnd End Sub Function GetDC(handle)CallDLLCallDLL #user32, "GetDC", _handlehandle As Ulong, _GetDCGetDC as Ulong End Function Function ReleaseDC(handle, hDC)CallDLLCallDLL #user32, "ReleaseDC", _handlehandle As Ulong, _hDChDC As Ulong, _ReleaseDCReleaseDC As Long End Function Function DeleteDC(hDC)CallDLLCallDLL #gdi32, "DeleteDC", _hDChDC as Ulong, _resultresult as Boolean End Function Function CreateCompatibleDC(hDC)CallDLLCallDLL #gdi32, "CreateCompatibleDC", _hDChDC as Ulong, _CreateCompatibleDCCreateCompatibleDC as Ulong End Function Function CreateCompatibleBitmap(hDC, wMem, hMem)CallDLLCallDLL #gdi32, "CreateCompatibleBitmap", _hDChDC as Ulong, _wMemwMem as Long, _hMemhMem as Long, _CreateCompatibleBitmapCreateCompatibleBitmap as Ulong End Function Function SelectObject(hDC, hPic)CallDLLCallDLL #gdi32, "SelectObject", _hDChDC as Ulong, _hPichPic as Ulong, _SelectObjectSelectObject as Ulong End Function Function BitBlt(hdcDest, xDest, yDest, wDest, hDest, hdcSource, xSource, ySource, ROP)CallDLLCallDLL #gdi32, "BitBlt", _hdcDesthdcDest as Ulong, _xDestxDest as Long, _yDestyDest as Long, _wDestwDest as Long, _hDesthDest as Long, _hdcSourcehdcSource as Ulong, _xSourcexSource as Long, _ySourceySource as Long, _ROPROP as Ulong, _resultresult as Boolean End Function Sub hueBackground handle$, hue$#handle$,#handle$, "Down; Fill ";hue$#handle$,#handle$, "Flush; Discard" End Sub Sub SimpleHouse handle$, xLoc, yLocCallCall hueBackground handle$, "Darkblue"#handle$,#handle$, "Color 128 64 0; Backcolor Brown"#handle$,#handle$, "Place ";xLoc + 5;" ";yLoc + 50#handle$,#handle$, "Boxfilled ";xLoc + 95;" ";yLoc + 90ForFor x = xLoc to xLoc + 100#handle$,#handle$, "Line ";xLoc + 50;" ";y + 10;" ";x;" ";y + 50NextNext x#handle$,#handle$, "Backcolor 128 64 0"#handle$,#handle$, "Place ";xLoc + 10;" ";yLoc + 60#handle$,#handle$, "Boxfilled ";xLoc + 30;" ";yLoc + 80#handle$,#handle$, "Place ";xLoc + 65;" ";yLoc + 60#handle$,#handle$, "Boxfilled ";xLoc + 85;" ";yLoc + 80#handle$,#handle$, "Place ";xLoc + 35;" ";yLoc + 70#handle$,#handle$, "Boxfilled ";xLoc + 60;" ";yLoc + 90#handle$,#handle$, "Color 16 16 16; Backcolor 16 16 16"#handle$,#handle$, "Place ";xLoc;" ";yLoc + 90#handle$,#handle$, "Boxfilled ";xLoc + 100;" ";yLoc + 100CallCall SimpleGrass handle$, xLoc, yLoc End Sub Sub SimpleTrees handle$, xLoc, yLoc#handle$,#handle$, "Color 128 64 0; Backcolor Brown"#handle$,#handle$, "Place ";xLoc + 30;" ";yLoc + 60#handle$,#handle$, "Boxfilled ";xLoc + 50;" ";yLoc + 90#handle$,#handle$, "Place ";xLoc + 65;" ";yLoc + 40#handle$,#handle$, "Boxfilled ";xLoc + 75;" ";yLoc + 90#handle$,#handle$, "Color 0 64 0; Backcolor 0 128 64"#handle$,#handle$, "Place ";xLoc + 40;" ";yLoc + 40#handle$,#handle$, "Circlefilled 30"#handle$,#handle$, "Place ";xLoc + 70;" ";yLoc + 50#handle$,#handle$, "Circlefilled 20"CallCall SimpleGrass handle$, xLoc, yLoc End Sub Sub SimpleFence handle$, xLoc, yLoc#handle$,#handle$, "Color 64 64 64; Backcolor 192 192 192"#handle$,#handle$, "Place ";xLoc + 10;" ";yLoc + 60#handle$,#handle$, "Boxfilled ";xLoc + 95;" ";yLoc + 70#handle$,#handle$, "Place ";xLoc + 10;" ";yLoc + 80#handle$,#handle$, "Boxfilled ";xLoc + 95;" ";yLoc + 90#handle$,#handle$, "Place ";xLoc + 10;" ";yLoc + 40#handle$,#handle$, "Boxfilled ";xLoc + 15;" ";yLoc + 90#handle$,#handle$, "Place ";xLoc + 30;" ";yLoc + 40#handle$,#handle$, "Boxfilled ";xLoc + 35;" ";yLoc + 90#handle$,#handle$, "Place ";xLoc + 50;" ";40#handle$,#handle$, "Boxfilled ";xLoc + 55;" ";yLoc + 90#handle$,#handle$, "Place ";xLoc + 70;" ";yLoc + 40#handle$,#handle$, "Boxfilled ";xLoc + 75;" ";yLoc + 90#handle$,#handle$, "Place ";xLoc + 90;" ";yLoc + 40#handle$,#handle$, "Boxfilled ";xLoc + 95;" ";yLoc + 90CallCall SimpleGrass handle$, xLoc, yLoc End Sub Sub SimpleGrass handle$, xLoc, yLocForFor x = xLoc to xLoc + 100greenHuegreenHue = Int(Rnd(1) * 128) + 16#handle$,#handle$, "Color 0 ";greenHue;" 0"yy = Int(Rnd(1) * 10) + 85#handle$,#handle$, "Line ";x;" ";y;" ";x;" 100"NextNext x End Sub [[code]] * Return to [[Drawing a Tiled Background with CreateCompatibleBitmap]]