![]() |
Ribbon problem |
Post Reply ![]() |
Author | |
terrym ![]() Senior Member ![]() Joined: 13 April 2007 Status: Offline Points: 836 |
![]() ![]() ![]() ![]() ![]() 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 |
|
![]() |
|
Oleg ![]() Senior Member ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
Oleg ![]() Senior Member ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
terrym ![]() Senior Member ![]() Joined: 13 April 2007 Status: Offline Points: 836 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
terrym ![]() Senior Member ![]() Joined: 13 April 2007 Status: Offline Points: 836 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
terrym ![]() Senior Member ![]() Joined: 13 April 2007 Status: Offline Points: 836 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
Oleg ![]() Senior Member ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
terrym ![]() Senior Member ![]() Joined: 13 April 2007 Status: Offline Points: 836 |
![]() ![]() ![]() ![]() ![]() |
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:
Thanks for help, it is much appreciated. |
|
Thank you,
Terry Mancey email terry@tmancey.ltd.uk | linkedin www.tmancey.ltd.uk | twitter @tmancey |
|
![]() |
|
Oleg ![]() Senior Member ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
terrym ![]() Senior Member ![]() Joined: 13 April 2007 Status: Offline Points: 836 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |