Click to See Complete Forum and Search --> : Shade images to look like an active icon


lzl1010
January 4th, 2006, 01:27 AM
This function is I found on http://www.codeguru.com/Cpp/G-M/bitmap/specialeffects/article.php/c1679.
I don't understand this this function ,why the WORD Bits[8] = {0x0055, 0x00aa, 0x0055, 0x00aa,0x0055, 0x00aa, 0x0055, 0x00aa }?and it is not Bits[8] = {other values}.
I apply it to an icon,and it's not correct ,it displays a blue square.

ShadeRect( CDC *pDC, CRect& rect )
{
// Bit pattern for a monochrome brush with every
// other pixel turned off
WORD Bits[8] = { 0x0055, 0x00aa, 0x0055, 0x00aa,
0x0055, 0x00aa, 0x0055, 0x00aa };

CBitmap bmBrush;
CBrush brush;

// Need a monochrome pattern bitmap
bmBrush.CreateBitmap( 8, 8, 1, 1, &Bits );

// Create the pattern brush
brush.CreatePatternBrush( &bmBrush );

CBrush *pOldBrush = pDC->SelectObject( &brush );

// Turn every other pixel to black
COLORREF clrBk = pDC->SetBkColor( RGB(255,255,255) );
COLORREF clrText = pDC->SetTextColor( RGB(0,0,0) );
// 0x00A000C9 is the ROP code to AND the brush with the destination
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),(DWORD)0x00A000C9); //DPa - raster code
//pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),(DWORD)0x00FA0089); //DPa - raster code

pDC->SetBkColor( RGB(0,0,0) );
pDC->SetTextColor( GetSysColor(COLOR_HIGHLIGHT) );
// 0x00FA0089 is the ROP code to OR the brush with the destination
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),(DWORD)0x00FA0089); //DPo - raster code

// Restore the device context
pDC->SelectObject( pOldBrush );
pDC->SetBkColor( clrBk );
pDC->SetTextColor( clrText );
}

lzl1010
January 4th, 2006, 03:13 AM
I draw an icon on view (in SDI) from file,I want to give the icon a shade when it is selected.How to do it ?

Such as when you select an icon in windows xp,the icon appearance is changed to indicate that it is selected. what windows does is that it turns every other pixel in the image to the highlight color which is usually blue.

iritonel
January 4th, 2006, 03:34 AM
Hi lzl1010,
I saw this implemetation when on pressing an Icon, it is replaced with another Icon (darker) and therefore seems selected.

Hope that's helps!
Irit

g_gili
January 4th, 2006, 07:03 AM
You just draw it on the client area and you want to give shade for the icon...?? please specify more details.

lzl1010
January 4th, 2006, 07:10 AM
first ,I draw the icon on the view(SDI) in client area .then,I want to shade the icon when I click it ,how to implement it with raster operation?

golanshahar
January 4th, 2006, 07:13 AM
first ,I draw the icon on the view(SDI) in client area .then,I want to shade the icon when I click it ,how to implement it with raster operation?

did you try using ::SetROP2(..) (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/pantdraw_9gdu.asp) ?

Cheers

Marc G
January 4th, 2006, 07:20 AM
[ merged threads ]

Please do not ask the same question in multiple threads.

Marc G
January 4th, 2006, 07:22 AM
[ moved thread ]

Marc G
January 4th, 2006, 07:25 AM
You can put your icon in an imagelist and use the Draw method on the imagelist which allows you do specify a blending factor, for example ILD_BLEND25.
See MFC CImageList::Draw (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cimagelist.3a3a.draw.asp)

lzl1010
January 5th, 2006, 03:51 AM
You can put your icon in an imagelist and use the Draw method on the imagelist which allows you do specify a blending factor, for example ILD_BLEND25.
See MFC CImageList::Draw (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cimagelist.3a3a.draw.asp)


I has implemented shading an icon when I click it in CImageList ::Draw(...),
I want to implement it in raster operation ,but I don't know how to implement it.

Marc G
January 5th, 2006, 04:43 AM
If it is working with CImageList::Draw, then why do you want to do it with raster operations?

lzl1010
January 5th, 2006, 06:37 AM
If it is working with CImageList::Draw, then why do you want to do it with raster operations?

I' m poor in VC++.I want to learn more knowledge.
I only try to implement it with another method ,and I can't implement it with this method.so I want to know how to implement it with raster operations.

Marc G
January 5th, 2006, 07:40 AM
I apply it to an icon,and it's not correct ,it displays a blue square.
Can you post the code how you are using the shaderect function?

lzl1010
January 5th, 2006, 07:47 AM
Can you post the code how you are using the shaderect function?

I use this function . I found it on http://www.codeguru.com/Cpp/G-M/bit...ticle.php/c1679.
I don't understand this this function ,why the WORD Bits[8] = {0x0055, 0x00aa, 0x0055, 0x00aa,0x0055, 0x00aa, 0x0055, 0x00aa }?and it is not Bits[8] = {other values}. why it is 0x00aa,0x0055.......?
I apply it to an icon,and it's not correct ,it displays a blue square.

Marc G
January 5th, 2006, 07:54 AM
I use this function . I found it on http://www.codeguru.com/Cpp/G-M/bit...ticle.php/c1679.
I don't understand this this function ,why the WORD Bits[8] = {0x0055, 0x00aa, 0x0055, 0x00aa,0x0055, 0x00aa, 0x0055, 0x00aa }?and it is not Bits[8] = {other values}. why it is 0x00aa,0x0055.......?
I apply it to an icon,and it's not correct ,it displays a blue square.
Those values are chosen because you want to have a patterned brush where every other pixel is set.
Just convert the above values to binary:
0x00aa = 10101010
0x0055 = 01010101
Now, you create an 8x8 pixel bitmap for you brush, so the pixels will become:
01010101
10101010
01010101
10101010
01010101
10101010
01010101
10101010
As you can see, every other pixel is set.

lzl1010
January 5th, 2006, 09:40 AM
Those values are chosen because you want to have a patterned brush where every other pixel is set.
Just convert the above values to binary:
0x00aa = 10101010
0x0055 = 01010101
Now, you create an 8x8 pixel bitmap for you brush, so the pixels will become:
01010101
10101010
01010101
10101010
01010101
10101010
01010101
10101010
As you can see, every other pixel is set.

why the bits[8] is not :
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
or
11111111
11111111
11111111
11111111
11111111
11111111
11111111
11111111
or other values?

Marc G
January 5th, 2006, 09:55 AM
Because you want a blue pixel at every other pixel and not at every pixel, that's what the shading does when you select an icon in older versions of Windows: the first pixel remains the icon pixel, the second pixel becomes blue, the third pixel is an icon pixel, the fourth is again blue etc.

lzl1010
January 5th, 2006, 08:59 PM
Because you want a blue pixel at every other pixel and not at every pixel, that's what the shading does when you select an icon in older versions of Windows: the first pixel remains the icon pixel, the second pixel becomes blue, the third pixel is an icon pixel, the fourth is again blue etc.

I don't still understand it.

01010101
10101010
.....

"1" is in connection with blue pixel?
"0" is in connection with icon pixel?
why?