• Subject: Re: Icons disapear from a CommanBar
  • Author: Minor, Thomas
  • Date: 29 May
  • References: 1 2
Hi Eric.
> Are they using Outlook 2000? You cannot load custom icons in add-ins for
> that version, such as those loaded from a file or a resource file. You
> need to use the CopyFace and PasteFace methods with built-in icons only.

That's right. I did not go into the detail here.

Outlook 2K connects to an Excahnge server.

We use the following code to put the icons on the toolbar:

void CAddin::InsertButtonFace(
_CommandBarButton *pCommandBarButton, UINT lIcon)
{
if (0 != lIcon)
{
if (OUTLOOK_XP <= m_wOutlookVersion)
{
InsertButtonFacePicture(pCommandBarButton, lIcon);
}
else
{
// version less than OUTLOOK_XP -> Outlook 2000
InsertButtonFaceClipboard(pCommandBarButton, lIcon);
}
}
}

Our Addin runs in different Outlook versions and m_wOutlookVersion keeps the
actual Outlook version after initialization.
Since we obviously act differnet on Outlook 2000 there might be a problem in
my function.

void CAddin::InsertButtonFaceClipboard(
_CommandBarButton *pCommandBarButton, UINT lIcon)
{
CopyIcon2Clipboard(lIcon);
try
{
pCommandBarButton->PasteFace();
}
catch (COleDispatchException *e)
{
if (e->m_scError == CdoE_CALL_FAILED)
{
e->Delete();
}
else
{
e->m_strDescription));
throw e;
}
}
// cleanup
OpenClipboard(NULL);
EmptyClipboard();
CloseClipboard();
}

Finally the copy2clipboard function.


#define ICON_SIZE_X 16
#define ICON_SIZE_Y 16

void CAddin::CopyIcon2Clipboard(UINT lIcon)
{
HICON hIcon;
ICONINFO iconInfo;
HDC hdc, hdcMem, hdcMemSrc;
HBITMAP hBitmap;
STGMEDIUM stgMedium;
COleDataSource *pClipboard;

hIcon = theApp.CRL_GetIcon(lIcon, CRL_ENABLED | CRL_SIZE_SMALL);

if (NULL == hIcon)
{
return;
}
VERIFY(GetIconInfo(hIcon, &iconInfo));

ASSERT(iconInfo.fIcon);
ASSERT(iconInfo.hbmColor);

// create transparency
hdc = ::GetDC(NULL);
ASSERT(hdc);
hBitmap = CreateCompatibleBitmap(hdc, ICON_SIZE_X, ICON_SIZE_Y);
VERIFY(DeleteDC(hdc));
hdc = NULL;
hdcMem = CreateCompatibleDC(NULL);
SelectObject(hdcMem, hBitmap);

// color with menu bg color
SelectObject(hdcMem, GetSysColorBrush(iColorMenu));
VERIFY(Rectangle(hdcMem, -1, -1, ICON_SIZE_X + 1, ICON_SIZE_Y + 1));

// aply mask
hdcMemSrc = CreateCompatibleDC(NULL);
ASSERT(hdcMemSrc);
SelectObject(hdcMemSrc, iconInfo.hbmMask);
VERIFY(BitBlt(hdcMem, 0, 0, ICON_SIZE_X, ICON_SIZE_Y, hdcMemSrc, 0, 0,
SRCAND));
SelectObject(hdcMemSrc, iconInfo.hbmColor);
VERIFY(BitBlt(hdcMem, 0, 0, ICON_SIZE_X, ICON_SIZE_Y, hdcMemSrc, 0, 0,
SRCINVERT));

// cleanup
VERIFY(DeleteDC(hdcMemSrc));
hdcMemSrc = NULL;
VERIFY(DeleteDC(hdcMem));
hdcMem = NULL;

stgMedium.pUnkForRelease = NULL;
stgMedium.hBitmap = hBitmap;
stgMedium.tymed = TYMED_GDI;

try
{
pClipboard = new COleDataSource();
ASSERT_VALID(pClipboard);
if (NULL == pClipboard)
{
DDERR(("kann kein Clipboard kriegen"));
}
else
{
pClipboard->CacheData(CF_BITMAP, &stgMedium);
pClipboard->SetClipboard();
}
}
catch (COleException *e)
{
CString str;

e->GetErrorMessage(str.GetBuffer(1024), 1024, NULL);
str.ReleaseBuffer();
e->Delete();
}
DestroyIcon(hIcon);
}
28 MayIcons disapear from a CommanBar.Minor, Thomas
28 May|- Re: Icons disapear from a CommanBar.<elegaultZZZ@REMOVEZZ...
28 May|  |- Re: Icons disapear from a CommanBar.Ken Slovak - [MVP - O...
29 May|  \ Re: Icons disapear from a CommanBar.Minor, Thomas
28 May|- Re: Icons disapear from a CommanBar.Ken Slovak - [MVP - O...
15 Sep|  \ Re: Icons disapear from a CommanBar.Hichem S
15 Sep|     \ Re: Icons disapear from a CommanBar.Ken Slovak - [MVP - O...
15 Sep|        |- Re: Icons disapear from a CommanBar.Hichem S
16 Oct|        \ Re: Icons disapear from a CommanBar.Minor, Thomas
29 May\ Re: Icons disapear from a CommanBar.Jialiang Ge [MSFT]
29 May   \ Re: Icons disapear from a CommanBar.Jialiang Ge [MSFT]
29 May      \ Re: Icons disapear from a CommanBar.Minor, Thomas
30 May         \ Re: Icons disapear from a CommanBar.Jialiang Ge [MSFT]
02 Jun            \ Re: Icons disapear from a CommanBar.Jialiang Ge [MSFT]
05 Jun               \ Re: Icons disapear from a CommanBar.Minor, Thomas
All times are in (US) Eastern Daylight Time (GMT -4:00)