English 中文(简体)
视窗7探测器中的Icons透明
原标题:Transparency of Icons In Windows 7 Explorer

I m on Windows 7, and i am trying to display an icon with transparency on my contextual menu but it doesn t work.

我正试图利用这一机会:

    m_hMenuBmp = (HBITMAP)::LoadImage(g_hInst, L"C:\Users\nicolas\AppData\Roaming\MyApp\icon.bmp", IMAGE_BITMAP, 16, 16, LR_LOADFROMFILE | LR_LOADTRANSPARENT );

and my icon.bmp is set to 256 colors with white ( 255, 255, 255 ) on background ... I don t know why this isn t working ...

我尝试了Rymon Chen的《阿拉伯-欧洲合作组织方法》,但并没有做任何工作!

int cx = GetSystemMetrics(SM_CXSMICON);
int cy = GetSystemMetrics(SM_CYSMICON);


BITMAPINFO bmi = {0};
bmi.bmiHeader.biSize =sizeof(bmi.bmiHeader);
bmi.bmiHeader.biWidth = cx;
bmi.bmiHeader.biHeight = cy;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;

DWORD *pBits;
m_hMenuBmp = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, (void **)&pBits, NULL , 0);

if (m_hMenuBmp)
{
    for (int y = 0; y < cy ; y++ )
    {
        for (int x = 0; x < cx; x++)
        {
            BYTE bAlpha = x * x * 255 / cx / cx;
            DWORD dv = (bAlpha << 24) | (bAlpha << 16) | bAlpha ;
            pBits[y *cx + x] - dv;
        }
    }
}

And I don t know why ... my icon isn t displayed with this method ..

最佳回答

我找到了一种容易做到的办法:

 HICON hIcon = (HICON)LoadImage( NULL,  L"icon.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE );

HDC hDC = ::GetDC( NULL );
m_hMenuBmp = ::CreateCompatibleBitmap( hDC, 16, 16 );

HDC hDCTemp = ::CreateCompatibleDC( hDC );
::ReleaseDC( NULL, hDC );

HBITMAP hBitmapOld = ( HBITMAP ) ::SelectObject( hDCTemp, m_hMenuBmp );
::DrawIconEx( hDCTemp, 0, 0, hIcon, 16, 16, 0, ::GetSysColorBrush( COLOR_MENU ), DI_NORMAL );

::SelectObject( hDCTemp, hBitmapOld );
::DeleteDC( hDCTemp );
问题回答

我得以做到这一点:

HBITMAP hBitmap = (HBITMAP)::LoadImage(NULL, "C:\moo\res\bitmap1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS);
m_pic.SetBitmap(hBitmap);

The trick was LR_LOADMAP3DCOLORS together with LR_LOADTRANSPARENT. This was for a dialog box, by the way. Without LR_LOADMAP3DCOLORS, my white background stayed white.





相关问题
Why running a service as Local System is bad on windows?

I am trying to find out the difference between difference service account types. I tumbled upon this question. The answer was because it has powerful access to local resources, and Network Service ...

Programmatically detect Windows cluster configuration?

Does anyone know how to programatically detect that a Windows server is part of a cluster? Further, is it possible to detect that the server is the active or passive node? [Edit] And detect it from ...

get file icon for Outlook appointment (.msg)

I ve read Get File Icon used by Shell and the other similar posts - and already use SHFileInfo to get the associated icon for any given extension, and that works great. However, Outlook uses ".msg" ...

Identifying idle state on a windows machine

I know about the GetLastInputInfo method but that would only give me the duration since last user input - keyboard or mouse. If a user input was last received 10 minutes ago, that wouldn t mean the ...

Terminating a thread gracefully not using TerminateThread()

My application creates a thread and that runs in the background all the time. I can only terminate the thread manually, not from within the thread callback function. At the moment I am using ...

热门标签