Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Ribbon problem
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Ribbon problem

 Post Reply Post Reply
Author
Message
terrym View Drop Down
Senior Member
Senior Member


Joined: 13 April 2007
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote terrym Quote  Post ReplyReply Direct Link To This Post Topic: Ribbon problem
    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
Back to Top
Oleg View Drop Down
Senior Member
Senior Member


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Oleg View Drop Down
Senior Member
Senior Member


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
terrym View Drop Down
Senior Member
Senior Member


Joined: 13 April 2007
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote terrym Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
terrym View Drop Down
Senior Member
Senior Member


Joined: 13 April 2007
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote terrym Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
terrym View Drop Down
Senior Member
Senior Member


Joined: 13 April 2007
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote terrym Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Oleg View Drop Down
Senior Member
Senior Member


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
terrym View Drop Down
Senior Member
Senior Member


Joined: 13 April 2007
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote terrym Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Oleg View Drop Down
Senior Member
Senior Member


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
terrym View Drop Down
Senior Member
Senior Member


Joined: 13 April 2007
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote terrym Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.047 seconds.