Icons disapear from a CommanBar

M

Minor, Thomas

Hi all,

I have a problem with an Outllok AddIn.

Our AddIn creates a CommandBar and adds some buttons to it.
Depending on the context of the user actions (ie which message type is
highlighted, is a contact highlighted..) some buttons
are enabled or disabled. This runs flawlessly on most of our customers
enviroments.
We now have one customer where the following problems occur:

On some or most buttons the icons are missing. The button is there and can
be used, but there is no icon.
We have a 'restore Toolbar' option in our settings dialog wich, under the
hood, removes all buttons from
the CommandBar and then adds them again. Interstingly, after each hit on the
restore-button, a different set of
Icons is displayed on the CommandBar until finally, after a non
deterministic count of tries, all icons are displayed.
This ist not quite the way we would like this to function.

The enviroment is Windows Server 2003, Terminal Server Mode, Citrix
Metaframe and Outlook 2000 SR3

Any hints are strongly appreciated...


--Thomas
 
G

Guest

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.

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS 2007
& WSS 3.0 Application Development)
Collaborative Innovations
-> Try Picture Attachments Wizard For Microsoft Outlook <-
Web: http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault
 
K

Ken Slovak - [MVP - Outlook]

You can use any custom icon as long as it's a BMP with 16x16x256 colors in
Outlook 2000 buttons but you must use PasteFace after copying the image to
the clipboard. I regularly use BMPs stored in a resource file or in the file
system for Outlook 2000 button images.
 
K

Ken Slovak - [MVP - Outlook]

Impossible to tell from that. How are you creating the buttons, show some
sample code.

What sort of Explorer or Inspector is this on? Is WordMail involved?

What mode of operation is the user running for Outlook 2000, Internet only
mode or Corporate/workgroup mode?
 
M

Minor, Thomas

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);
}
 
J

Jialiang Ge [MSFT]

Good morning, Thomas. Welcome to office.developer.com.add_ins newsgroup! My
name is Jialiang Ge [MSFT].



I once handled a very similar issue, where a customer said his
CommandBarButton icon cannot be shown only in Outlook 2000. That problem
turned out to be caused by the code:

HBITMAP hSrcBmp = LoadBitmap(AfxGetResourceHandle(),

MAKEINTRESOURCE(IDB_BITMAP1));

The method LoadBitmap has been superseded by the LoadImage function because
it is incompatible with some device context. Thus, the resolution was to
replace the line with:

HBITMAP hSrcBmp = (HBITMAP)::LoadImage(GetModuleHandle(NULL),

MAKEINTRESOURCE(IDB_BITMAP1), IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);



Thomas, because you did not mention how you loaded the bitmap icon or
provided any code snippet for test, I cannot quickly figure out the reason
for this specific issue. But I suggest you read the above-mentioned thread:

http://office-outlook.com/outlook-forum/index.php/m/209360/#msg_209360



And if the thread does not help, would you please show us some code
snippets? I'd be very happy to test it for you.



Regards,

Jialiang Ge ([email protected], remove 'online.')

Microsoft Online Community Support



Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notifications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support

Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support

professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations

that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Minor, Thomas

Heallo Jialiang,

thanks for your extensive posts on my issue.
test it. Based on my experience, Thomas, I feel the problem may lie in
your code line:
hIcon = theApp.CRL_GetIcon(lIcon, CRL_ENABLED | CRL_SIZE_SMALL);
What¡¯s your implementation of CRL_GetIcon?

We use a resource dll for whitelabeling the application which implements
the function like this:

extern "C" HICON CALLBACK CRL_GetIcon(DWORD nID, DWORD dwFlags)
{
// Tell MFC to use our own resources not those of the loading module
// (must be used for every exported function that loads resources).
#ifdef _AFXDLL
AFX_MANAGE_STATE(AfxGetStaticModuleState())
#endif

// Size?
INT cx = CrlGetSize_(dwFlags);

// Enabled or disabled icon?
LPCTSTR pszName = MAKEINTRESOURCE(dwFlags & CRL_DISABLED ? nID +1 : nID);

// Note that LoadImage() does not require a subsequent DestroyIcon() in
Win32.
// Important: If the icon can't be found, return the icon 'empty' to avoid
// program crashes when returning NULL as HICON.
hIcon = (HICON)LoadImage(
AfxGetResourceHandle(),
pszName,
IMAGE_ICON,
cx, cx,
LR_DEFAULTCOLOR);

// LoadImage fails to load 128x128 icons on some Win9X systems, so use the
64x64 as fallback.
if(!hIcon && (cx == 128))
hIcon = (HICON)LoadImage(
AfxGetResourceHandle(),
pszName,
IMAGE_ICON,
64, 64,
LR_DEFAULTCOLOR);
if(!hIcon)
hIcon = (HICON)LoadImage(
AfxGetResourceHandle(),
MAKEINTRESOURCE(IDI_CRL_MISC_UNKNOWN_ID),
IMAGE_ICON,
cx, cx,
LR_DEFAULTCOLOR);

// LoadImage fails to load 128x128 icons on some Win9X systems, so use the
64x64 as fallback.
if(!hIcon && (cx == 128))
hIcon = (HICON)LoadImage(
AfxGetResourceHandle(),
MAKEINTRESOURCE(IDI_CRL_MISC_UNKNOWN_ID),
IMAGE_ICON,
64, 64,
LR_DEFAULTCOLOR);
return hIcon;
}

The main difference in our handling seems to be that we load the icon
as an icon first and convert it to a bitmap afterwards.
We chose this approach to use a generic way to load the icons.
Maybe there is a fault in this conversion...


--Thomas
 
J

Jialiang Ge [MSFT]

Hello Thomas,

In fact, my code was written by referencing the VB code in the KB article
http://support.microsoft.com/kb/288771/en-us. It demonstrates how to create
a transparent picture for Office CommandBar buttons. But because your code
is importing an icon, instead of a bitmap resource, I suggest you read this
KB article:

How To Add a Transparent Icon to a Toolbar Button
http://support.microsoft.com/kb/260850

It provides the workable way to copy icon to bmp for Outlook 2000 system.
Though the sample code is in VB, the calls of API are the same in VC.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
J

Jialiang Ge [MSFT]

Hello Thomas

I'm writing to check whether the icon->bmp conversion method in my last
reply help you or not. If you need my help to translate those VB code
(http://support.microsoft.com/kb/260850) to VC, please let me know.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
M

Minor, Thomas

Hello Jialiang,
thank you for the help.
I'm writing to check whether the icon->bmp conversion method in my last
reply help you or not. If you need my help to translate those VB code
(http://support.microsoft.com/kb/260850) to VC, please let me know.


I got the code but I was interupted by another task.
I'll get back on you asap.


--Thomas Mior
 
H

Hichem S

I have the same problem only when WordMail is involved!
=> a catatrophic failure message is displayed
(I am using Outlook 2003 and opening a new email item.)

Thanks
 
K

Ken Slovak - [MVP - Outlook]

Please don't hijack other threads.

To repeat my answer to the other poster:

Impossible to tell from that.

How are you creating the buttons, and where are the buttons being created?
Show some sample code.
 
H

Hichem S

Sorry,
I posted a new thread with title : "Icons does not appear in a CommandBar :
Catastrophic failure throw"
Thank you.
 
M

Minor, Thomas

Hi Ken,

it seems you did miss the fact that my problem was solved.
It was a timing problem and could be fixed with a ::Sleep().
I think it is related to multi-core, multi-processor issues.

Thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top