CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2002
    Location
    La Plata, Buenos Aires
    Posts
    615

    Unhappy Help! Can't draw GDIplus bitmap from HBITMAP

    My problem is that I want to draw some ownerdrawn controls on a GDI+ graphics surface.

    My approach is:

    1. I've declared a global object as:

    Code:
    extern Gdiplus::Bitmap		*pBmpOdElem;
    2. I setup an empty bitmap with:

    Code:
    void createGdiplusObj(void)
    {
    	pBmpOdElem = new Bitmap(50,50,PixelFormatDontCare);
    }
    3. I try to draw onto the bitmap using the pBmpOdElem pointer:

    Code:
    BOOL OwnDrawProc (WPARAM wparam, LPARAM lparam)
    {
        HBITMAP				hBitmap = 0;
        LPDRAWITEMSTRUCT	lpDrawItem = (LPDRAWITEMSTRUCT)lparam;
        int					x =  lpDrawItem->rcItem.top;
        int					y =  lpDrawItem->rcItem.left;
        Graphics			gr(lpDrawItem->hDC);
        UINT				uiSelect = lpDrawItem->itemState & ODS_SELECTED;
    
    ...
    
    	pBmpOdElem->FromHBITMAP(hBitmap, NULL);
        gr.DrawImage (pBmpOdElem, x, y, pBmpOdElem->GetWidth(), pBmpOdElem->GetHeight()); 
    }
    and nothings happens...

    My previous approach to the problem was creating a Bitmap object in the ownerdrawn procedure and draw it accordingly. This worked but I dont want to create a Bitmap object every time the painting routine gets called... it's not efficient.

    Any help with managing those GDI+ ptrs?

    thank you.

    Hernan

  2. #2
    Join Date
    Dec 2002
    Location
    La Plata, Buenos Aires
    Posts
    615
    don't care...

    I fixed it with the following line

    Code:
        gr.DrawImage (pBmpOdElem->FromHBITMAP(hBitmap,0), x, y, pBmpOdElem->GetWidth(), pBmpOdElem->GetHeight());

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured