Click here to Skip to main content
15,923,219 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRatio color bar for an MFC-based application Pin
marc ochsenmeier27-Oct-10 9:42
marc ochsenmeier27-Oct-10 9:42 
AnswerRe: Ratio color bar for an MFC-based application Pin
Code-o-mat27-Oct-10 11:31
Code-o-mat27-Oct-10 11:31 
GeneralRe: Ratio color bar for an MFC-based application Pin
«_Superman_»27-Oct-10 12:16
professional«_Superman_»27-Oct-10 12:16 
GeneralRe: Ratio color bar for an MFC-based application Pin
marc ochsenmeier27-Oct-10 19:39
marc ochsenmeier27-Oct-10 19:39 
GeneralRe: Ratio color bar for an MFC-based application Pin
marc ochsenmeier27-Oct-10 20:10
marc ochsenmeier27-Oct-10 20:10 
GeneralRe: Ratio color bar for an MFC-based application Pin
Code-o-mat27-Oct-10 21:52
Code-o-mat27-Oct-10 21:52 
GeneralRe: Ratio color bar for an MFC-based application [modified] Pin
marc ochsenmeier27-Oct-10 19:38
marc ochsenmeier27-Oct-10 19:38 
QuestionCImage and transparency Pin
Craig Longman27-Oct-10 7:39
Craig Longman27-Oct-10 7:39 
I have a button that I want an image in, a basic colour swatch. I liked the idea of having a partially transparent shadow around it, so in GIMP, I created a 32 bit BMP with the desired alpha shadow, and a white, totally non-transparent square in the middle. The intention was to fill the white area in with the colour that the user chooses. Sounds simple enough. So, the basic code is such:

HDC hDC;
HANDLE hOldBmp;
HBRUSH hBrush;
LOGBRUSH zLogBrush;

HBITMAP hColourShadowBmp_ = ::LoadBitmap( hInst, MAKEINTRESOURCE(IDB_COLOUR_SHADOW) );

zLogBrush.lbStyle = BS_SOLID;
zLogBrush.lbColor = RGB( m_Props.uiRed, m_Props.uiGreen, m_Props.uiBlue );
zLogBrush.lbHatch = NULL;

hBrush = ::CreateBrushIndirect( &zLogBrush );

CImage zFinalImage;
CImage zSwatchImage;

zFinalImage.Attach( hColourShadowBmp_ );
zSwatchImage.Create( 20, 20, 24 );

hDC = zSwatchImage.GetDC();
::SelectObject( hDC, hBrush );
::Rectangle( hDC, 0, 0, 20, 20 );
zSwatchImage.ReleaseDC();

hDC = zFinalImage.GetDC();
zSwatchImage.AlphaBlend( hDC, 2, 2, 255 );
zFinalImage.ReleaseDC();

hOldBmp = (HANDLE)
    ::SendMessage( ::GetDlgItem( m_hWnd, IDC_COLOUR ),
                   BM_SETIMAGE,
                   (WPARAM)IMAGE_BITMAP,
                   (LPARAM)zFinalImage.Detach() );

::DeleteObject( hBrush );


All I end up with is the source shadow image, with a lovely fully transparent square where the swatch should be. I know the swatch painting is working, as I can send that image and get the colour square I expect.

Yet nothing I do seems to be able to make the colours get transferred. Crazily enough, the alpha is, if I set the alpha in the AlphaBlend() call to 0, I get the original shadow image unchanged. So I know that it is modifying the alpha channel properly at least. The source is opaque, so no amount of pre-multiplying will help.

FWIW, I also tried making the zSwatchImage a 32 bit with alpha, but it made no difference.

The only solution I can see now is jumping into the bits for the shadow image and changing the RGB values to what I want.

But surely I'm doing something wrong? It's hard to believe that a simply blend like this fails.

Thanks,

CraigL
AnswerRe: CImage and transparency Pin
Code-o-mat27-Oct-10 7:47
Code-o-mat27-Oct-10 7:47 
GeneralRe: CImage and transparency Pin
Craig Longman27-Oct-10 8:13
Craig Longman27-Oct-10 8:13 
GeneralRe: CImage and transparency Pin
Craig Longman27-Oct-10 8:27
Craig Longman27-Oct-10 8:27 
GeneralRe: CImage and transparency Pin
Code-o-mat27-Oct-10 8:52
Code-o-mat27-Oct-10 8:52 
AnswerRe: CImage and transparency Pin
Alain Rist27-Oct-10 8:30
Alain Rist27-Oct-10 8:30 
GeneralRe: CImage and transparency Pin
transoft27-Oct-10 17:23
transoft27-Oct-10 17:23 
GeneralRe: CImage and transparency Pin
Moak31-Oct-10 12:50
Moak31-Oct-10 12:50 
QuestionCToolTipCtrl: Restrict Tooltip within the dialog Pin
chandu00427-Oct-10 4:57
chandu00427-Oct-10 4:57 
AnswerRe: CToolTipCtrl: Restrict Tooltip within the dialog Pin
msr_codeproject27-Oct-10 19:48
msr_codeproject27-Oct-10 19:48 
Questioncontrolling wave output volume Pin
Danzy8327-Oct-10 1:52
Danzy8327-Oct-10 1:52 
AnswerRe: controlling wave output volume Pin
David Crow27-Oct-10 3:03
David Crow27-Oct-10 3:03 
AnswerRe: controlling wave output volume Pin
Chris Meech27-Oct-10 3:25
Chris Meech27-Oct-10 3:25 
GeneralRe: controlling wave output volume Pin
Danzy8327-Oct-10 3:44
Danzy8327-Oct-10 3:44 
AnswerRe: controlling wave output volume Pin
Sauro Viti27-Oct-10 3:53
professionalSauro Viti27-Oct-10 3:53 
GeneralRe: controlling wave output volume Pin
Danzy8327-Oct-10 3:58
Danzy8327-Oct-10 3:58 
GeneralRe: controlling wave output volume Pin
Code-o-mat27-Oct-10 4:25
Code-o-mat27-Oct-10 4:25 
QuestionHow can i use tab inside edit control Pin
learningvisualc27-Oct-10 0:33
learningvisualc27-Oct-10 0:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.