Ribbon problem
Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=6974
Printed Date: 27 August 2025 at 9:29pm Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com
Topic: Ribbon problem
Posted By: terrym
Subject: Ribbon problem
Date Posted: 25 April 2007 at 7:57am
We are having a problem with the following code as we want to generate gallery control items on the fly, however once we add the CreateCompatibleDC( NULL ) section it only shows a black square for each gallery control item
Any help would be much appreciated as this code works fine in OnPaint handlers etc.
--------
m_ImageList.Create( m_nWidth, m_nHeight, ILC_COLOR32 | ILC_MASK, 0, 1 );
HBITMAP hBitmap = (HBITMAP)::LoadImage( NULL, "c:\\1.bmp", IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
if ( hBitmap == NULL ) return;
CBitmap *pBitmap = new CBitmap;
pBitmap->Attach( hBitmap );
CDC *pDC = new CDC;
pDC->CreateCompatibleDC( NULL ); // this line seems to make it fail
pDC->SelectObject( pBitmap );
m_ImageList.Add( pBitmap, m_crMaskColour );
--------
Thanks for any help, much appreciated.
Terry
------------- Thank you, Terry Mancey
email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey
|
Replies:
Posted By: Oleg
Date Posted: 25 April 2007 at 8:02am
Hello,
Instead of converting bitmap to imagelist, you can set bitmap directly -
BOOL SetIcons(CBitmap& bmpIcons, UINT* pCommands, int nCount, CSize szIcon, XTPImageState imageState = xtpImageNormal, BOOL bAlpha = FALSE)
------------- Oleg, Support Team CODEJOCK SOFTWARE SOLUTIONS
|
Posted By: Oleg
Date Posted: 25 April 2007 at 8:04am
ps: You don't need these lines to convert hbitmap to CBitmap:
CBitmap *pBitmap = new CBitmap;
pBitmap->Attach( hBitmap );
CDC *pDC = new CDC;
pDC->CreateCompatibleDC( NULL ); // this line seems to make it fail
pDC->SelectObject( pBitmap );
just need these:
HBITMAP hBitmap = (HBITMAP)::LoadImage( NULL, "c:\\1.bmp", IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
CBitmap bmp;
bmp.Attach(hBitmap);
------------- Oleg, Support Team CODEJOCK SOFTWARE SOLUTIONS
|
Posted By: terrym
Date Posted: 25 April 2007 at 8:06am
Hi
The problem is we need to use the DC because we want to edit the bitmap, eg. Resize or add text before it is added to gallery control
Thanks
Terry
------------- Thank you, Terry Mancey
email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey
|
Posted By: terrym
Date Posted: 25 April 2007 at 8:08am
Hi
We load our images from disk then we resize them or add text etc. to each one, so we may need more images, but first we have to create a compatible DC so we can edit the images or add text.
This is the problem :(
Thanks
Terry
------------- Thank you, Terry Mancey
email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey
|
Posted By: terrym
Date Posted: 25 April 2007 at 8:22am
The problem seems to be that we are passing NULL when we create compatible DC, and even thou we are attaching the bitmap it is not setting up this DC correctly. Any ideas on what else we can pass ?
Any help appreciated, even willing to pay somebody to help us fix this as urgent for a projecct.
------------- Thank you, Terry Mancey
email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey
|
Posted By: Oleg
Date Posted: 25 April 2007 at 8:30am
Hi,
Don't think problem in CreatecompatibleDC line - think ptoblem that you call SelectObject and didn't restore context back.
try
CBitmap* pOldBitmap = pDC->SelectObject( pBitmap );
// Make some work
pDC->SelectObject( pOldBitmap);
delete pDC;
m_ImageList.Add( pBitmap, m_crMaskColour );
delete pBitmap;
------------- Oleg, Support Team CODEJOCK SOFTWARE SOLUTIONS
|
Posted By: terrym
Date Posted: 25 April 2007 at 8:52am
Hi
Ok that works fine until we then create a 2nd DC with a compatible bitmap so we can then stretchblt to other DC to create our item (thumbnail), the code is as follows:
HBITMAP hBitmap = (HBITMAP)::LoadImage( NULL, "c:\\1.bmp", IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
if ( hBitmap == NULL ) return;
CDC *pSourceDC = new CDC;
CDC *pDestinationDC = new CDC;
CBitmap *pSourceBitmap = new CBitmap;
pSourceBitmap->Attach( hBitmap );
pSourceDC->CreateCompatibleDC( NULL );
CBitmap *pOldSourceBitmap = pSourceDC->SelectObject( pSourceBitmap );
pDestinationDC->CreateCompatibleDC( NULL );
CBitmap *pDestinationBitmap = new CBitmap;
pDestinationBitmap->CreateCompatibleBitmap( pSourceDC, 48, 48 );
pDestinationDC->StretchBlt( 0, 0, 48, 48, pSourceDC, 0, 0, 300, 300, SRCCOPY );
pSourceDC->SelectObject( pOldSourceBitmap);
delete pSourceDC;
m_ImageList.Add( pDestinationBitmap, m_crMaskColour );
delete pDestinationDC;
delete pDestinationBitmap;
delete pSourceBitmap;
Thanks for help, it is much appreciated.
------------- Thank you, Terry Mancey
email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey
|
Posted By: Oleg
Date Posted: 25 April 2007 at 1:19pm
Hi,
You didn't select pDestinationBitmap to pDestinationDC...
You don't need to much new/delete create them in heap:
CDC dcSrc;
dcSrc.CreateCompatibleDC(NULL)
etc
------------- Oleg, Support Team CODEJOCK SOFTWARE SOLUTIONS
|
Posted By: terrym
Date Posted: 25 April 2007 at 4:04pm
Hi
The new version is below same applies, we are creating the object using CreateCompatibleBitmap which according to microsoft doesn't need to have it's object selected, however I did try this and still same black square, I have sent the project to you via priority support to show you the problem.
Thanks for the help
Terry
HBITMAP hBitmap = (HBITMAP)::LoadImage( NULL, "c:\\1.bmp", IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
if ( hBitmap == NULL ) return;
CDC *pSourceDC = new CDC;
CDC *pDestinationDC = new CDC;
CBitmap *pSourceBitmap = new CBitmap;
pSourceBitmap ->Attach( hBitmap );
pSourceDC ->CreateCompatibleDC( NULL );
CBitmap *pOldSourceBitmap = pSourceDC->SelectObject( pSourceBitmap );
pDestinationDC ->CreateCompatibleDC( NULL );
CBitmap *pDestinationBitmap = new CBitmap;
pDestinationBitmap ->CreateCompatibleBitmap( pSourceDC, 48, 48 );
CBitmap *pOldDestinationBitmap = pSourceDC->SelectObject( pDestinationBitmap );
pDestinationDC ->StretchBlt( 0, 0, 48, 48, pSourceDC, 0, 0, 300, 300, SRCCOPY );
pSourceDC ->SelectObject( pOldSourceBitmap);
delete pSourceDC;
m_ImageList .Add( pDestinationBitmap, m_crMaskColour );
pDestinationDC ->SelectObject( pOldDestinationBitmap );
delete pDestinationDC;
delete pDestinationBitmap;
delete pSourceBitmap;
------------- Thank you, Terry Mancey
email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey
|
|