Go back to group page
Go to next unread message | Full plain text message | Fixed font - Proportional font

Subject: Re: Button Icon question
Author: Sean Cameron
Date: 13 Oct 2010
Ref: 1
It's quite straight forward to convert the icon to grayscale, regardless of whether or not it has an Alpha channel. The Windows API is a disappointment in this area, which is why you are seeing the rather poor looking disabled icons in Clarion. It looks like they are using DrawSate with DST_ICON | DSS_DISABLED. Doing this in C++ is very straight forward, and the code can be ported to Clarion without too much difficulty (it's just calling Windows GDI functions) COLORREF defaultGrayPalette[256]; BOOL bGrayPaletteSet = FALSE; HICON CreateGrayscaleIcon( HICON hIcon, COLORREF* pPalette ) { if (hIcon == NULL) { return NULL; } HDC hdc = ::GetDC(NULL); HICON hGrayIcon = NULL; ICONINFO icInfo = { 0 }; ICONINFO icGrayInfo = { 0 }; LPDWORD lpBits = NULL; LPBYTE lpBitsPtr = NULL; SIZE sz; DWORD c1 = 0; BITMAPINFO bmpInfo = { 0 }; bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); if (::GetIconInfo(hIcon, &icInfo)) { if (::GetDIBits(hdc, icInfo.hbmColor, 0, 0, NULL, &bmpInfo, DIB_RGB_COLORS) != 0) { bmpInfo.bmiHeader.biCompression = BI_RGB; sz.cx = bmpInfo.bmiHeader.biWidth; sz.cy = bmpInfo.bmiHeader.biHeight; c1 = sz.cx * sz.cy; lpBits = (LPDWORD)::GlobalAlloc(GMEM_FIXED, (c1) * 4); if (lpBits && ::GetDIBits(hdc, icInfo.hbmColor, 0, sz.cy, lpBits, &bmpInfo, DIB_RGB_COLORS) != 0) { lpBitsPtr = (LPBYTE)lpBits; UINT off = 0; for (UINT i = 0; i < c1; i++) { off = (UINT)( 255 - (( lpBitsPtr[0] + lpBitsPtr[1] + lpBitsPtr[2] ) / 3) ); if (lpBitsPtr[3] != 0 || off != 255) { if (off == 0) { off = 1; } lpBits[i] = pPalette[off] | ( lpBitsPtr[3] << 24 ); } lpBitsPtr += 4; } icGrayInfo.hbmColor = ::CreateCompatibleBitmap(hdc, sz.cx, sz.cy); if (icGrayInfo.hbmColor != NULL) { ::SetDIBits(hdc, icGrayInfo.hbmColor, 0, sz.cy, lpBits, &bmpInfo, DIB_RGB_COLORS); icGrayInfo.hbmMask = icInfo.hbmMask; icGrayInfo.fIcon = TRUE; hGrayIcon = ::CreateIconIndirect(&icGrayInfo); ::DeleteObject(icGrayInfo.hbmColor); } ::GlobalFree(lpBits); lpBits = NULL; } } ::DeleteObject(icInfo.hbmColor); ::DeleteObject(icInfo.hbmMask); } ::ReleaseDC(NULL,hdc); return hGrayIcon; } HICON CreateGrayscaleIcon( HICON hIcon ) { if (hIcon == NULL) { return NULL; } if (!bGrayPaletteSet) { for(int i = 0; i < 256; i++) { defaultGrayPalette[i] = RGB(255-i, 255-i, 255-i); } bGrayPaletteSet = TRUE; } return CreateGrayscaleIcon(hIcon, defaultGrayPalette); }
Regards, Sean Cameron CapeSoft www.capesoft.com Work Smarter, Not Harder! "Phil Carroll" <support@ultratree.com> wrote in message news:A921.1286833256.27970@discuss.softvelocity.com...
> Clarion 7.2 build 7600. > > In an app built with a Vista manifest, Win 7 compatibility, a button with > a high quality truecolor vista-format icon looks great in Win 7 when > enabled. When disabled, the icon looks like cr*p. (Half the icon > basically disappears like it was chopped with a hatchet. This occurs with > every icon I have tried.) > > I have in the .ico file, in addition to the 32-bit versions, high quality > 256-color grayscale versions in all sizes. But, they are ignored by the > IDE/RTL. > > What is the standard Clarion way to provide grayed icons for use with > disabled objects? The most obvious way that springs to mind is to insert > code that uses PROP:Icon to swap icons when enabling/disabling a button. > Is there a more general way I am overlooking? > > It would be a great Clarion language addition if a developer could specify > both enabled and disabled versions of an icon on all controls that can be > disabled that also support icons. > > -- > Phil Carroll > http://www.enablingsimplicity.com
Mark all as read
Button Icon question
11 Oct 2010Phil Carroll
11 Oct 2010|- Lee White (Lod…
11 Oct 2010|  \ Phil Carroll
11 Oct 2010|     \ Lee White (Lod…
11 Oct 2010|        |- Jeff Slarve
12 Oct 2010|        |- Phil Carroll
12 Oct 2010|        |  |- Jeff Slarve
12 Oct 2010|        |  |  \ Jeff Slarve
12 Oct 2010|        |  \ Lee White (Lod…
12 Oct 2010|        |     |- Larry Sand
12 Oct 2010|        |     \ Phil Carroll
12 Oct 2010|        |        \ Lee White (Lod…
12 Oct 2010|        |           \ Phil Carroll
12 Oct 2010|        |              |- Lee White (Lod…
12 Oct 2010|        |              |  \ Phil Carroll
12 Oct 2010|        |              \ Mike Hanson [B…
13 Oct 2010|        |                 \ Phil Carroll
14 Oct 2010|        |                    \ Mike Hanson [B…
14 Oct 2010|        |                       \ Phil Carroll
15 Oct 2010|        |                          \ Mike Hanson [B…
12 Oct 2010|        \ Charles Edmonds
12 Oct 2010|- JP Gutsatz (DM…
12 Oct 2010|- Mike Hanson [B…
12 Oct 2010|  \ Jeff Slarve
12 Oct 2010|     \ Lee White (Lod…
12 Oct 2010|        \ Jeff Slarve
13 Oct 2010\ Sean Cameron
13 Oct 2010   |- Jeff Slarve
13 Oct 2010   \ Phil Carroll
14 Oct 2010      |- Mike Hanson [B…
14 Oct 2010      |- Lee White (Lod…
15 Oct 2010      |  \ Phil Carroll
14 Oct 2010      \ Sean Cameron
14 Oct 2010         |- David
14 Oct 2010         \ Phil Carroll