Jump to content
Sign in to follow this  

Interoperability Between GDI and GDI+

Recommended Posts



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)


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

; Build your GUI here

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

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



; Load your GDI+ resources here:

; 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

; 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_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_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_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()

    _WinAPI_ReleaseDC(0, $graphicsGDI)
Edited by adamski

Share this post

Link to post
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
Sign in to follow this