Jump to content

Interoperability Between GDI and GDI+


adamski
 Share

Recommended Posts

EDIT:

I have solved this now - 30 minutes after asking the question and I've been trying to figure it out on and off for a day!

I will post code when finished: CODE POSTED

================================

I am so close to getting the result I want but have a problem with using GDI+ buffers with GDI BitBlt.

I can get the two to work together if I draw the GDI+ buffers to the screen and then use it with GDI, but have been unable to figure out how to just use the GDI+ buffers so I don't have to draw intermediate steps to the screen and can just display the BitBlt result.

How can I access the GDI+ buffers from GDI so I don't have to draw them?

(I have been using GDI+ throughout my program before I ran into this)

Thanks

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <GDIplus.au3>

; Build your GUI here
Opt("GUIOnEventMode",1)

; Box Size
Global Const $RectWidth = 300
Global Const $RectHeight = 200

Global Const $GUIWidth=20+$RectWidth
Global Const $GUIHeight=20+$RectHeight
GLobal $GUITitle="GDI+"

$hwnd=GUICreate($GUITitle,$GUIWidth,$GUIHeight)
GUISetOnEvent($GUI_EVENT_CLOSE,"close")

$GDILabel=GUICtrlCreateLabel("",10,10,$RectWidth,$RectHeight)
GUISetState()

; Load your GDI+ resources here:
_GDIPlus_Startup()
$graphics=_GDIPlus_GraphicsCreateFromHWND(ControlGetHandle($hwnd,"",$GDILabel))
$bitmap=_GDIPlus_BitmapCreateFromGraphics($GUIWidth,$GUIHeight,$graphics)
$backbuffer=_GDIPlus_ImageGetGraphicsContext($bitmap)

; Load your GDI resources here:
$graphicsGDI = _WinAPI_GetDC(ControlGetHandle($hwnd,"",$GDILabel))
$backbufferGDI     = _WinAPI_CreateCompatibleDC($graphicsGDI); Create Memory Buffer DC to copy GDI+ to
$backbufferGDIRaster = _WinAPI_CreateCompatibleDC($graphicsGDI); Create Memory Buffer DC for Raster
$bitmapGDIRaster = _WinAPI_CreateCompatibleBitmap($graphicsGDI, $RectWidth, $RectHeight); Raster Bitmap from DC
_WinAPI_SelectObject($backbufferGDIRaster, $bitmapGDIRaster); Put Raster Bitmap on Raster Buffer

; Brushes
$hBrushGreen = _GDIPlus_BrushCreateSolid(0xFF008000)
$hBrushBlue = _GDIPlus_BrushCreateSolid(0xFF000080)
$Red = 0; For Red Brush

Do
; Shades of Red
    $Red += 0.01
    $CurrentRedColour = "0xFF" & Hex(((Sin(1 * $Red / 1) + 1) / 2) * 256, 2) & "0000"
    $hBrushChangeRed = _GDIPlus_BrushCreateSolid($CurrentRedColour)
    
; Draw the GDI Raster Box
    _GDIPlus_GraphicsClear($backbuffer)
    _GDIPlus_GraphicsFillRect($backbuffer, 0, 0, $RectWidth, $RectHeight, $hBrushChangeRed); Draw GDI+ here
    $BitmapGDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bitmap); Copy GDI+ Bitmap to GDI Bitmap
    _WinAPI_SelectObject($backbufferGDIRaster, $BitmapGDI); Put GDI Bitmap on backbufferGDIRaster

    _GDIPlus_GraphicsClear($backbuffer)
    _GDIPlus_GraphicsFillRect($backbuffer, 0, 0, $RectWidth, $RectHeight, $hBrushGreen)
    $BitmapGDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bitmap)
    _WinAPI_SelectObject($backbufferGDI, $BitmapGDI); Put GDI Bitmap on backbufferGDI ready to combine with backbufferGDIRaster
    _WinAPI_BitBlt($backbufferGDIRaster, 0, 0, $RectWidth,  $RectHeight, $backbufferGDI, 0, 0, $SRCPAINT); OR operator combine
    
    _GDIPlus_GraphicsClear($backbuffer)
    _GDIPlus_GraphicsFillRect($backbuffer, 0, 0, $RectWidth, $RectHeight, $hBrushBlue)
    $BitmapGDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bitmap)
    _WinAPI_SelectObject($backbufferGDI, $BitmapGDI)
    _WinAPI_BitBlt($backbufferGDIRaster, 0, 0, $RectWidth,  $RectHeight, $backbufferGDI, 0, 0, $SRCPAINT); OR operator combine

; Draw backbufferGDIRaster to screen
    _WinAPI_BitBlt($graphicsGDI, 0, 0, $RectWidth,  $RectHeight, $backbufferGDIRaster, 0, 0, $SRCCOPY)

Until False

Func close()
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)

    _WinAPI_DeleteDC($backbufferGDI)
    _WinAPI_DeleteObject($BitmapGDI)
    _WinAPI_DeleteDC($backbufferGDIRaster)
    _WinAPI_DeleteObject($bitmapGDIRaster)
    
    _WinAPI_ReleaseDC(0, $graphicsGDI)
    
    _GDIPlus_Shutdown()
    Exit
EndFunc
Edited by adamski
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...