Don't use the clipboard to paint a toolbar button


P

Phlip

Newsgroupies:

The sample code on this page is user-hostile:

http://www.mindcracker.com/mindcracker/c_cafe/atl/BuildingOffice2KCOMAddInAD.asp

// to set a bitmap to a button, load a 32x32 bitmap
// and copy it to clipboard. Call CommandBarButton's PasteFace()
// to copy the bitmap to the button face. to use
// Outlook's set of predefined bitmap, set button's FaceId to //the
// button whose bitmap you want to use
HBITMAP hBmp =(HBITMAP)::LoadImage(_Module.GetResourceInstance(),
MAKEINTRESOURCE(IDB_BITMAP1),IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS);

// put bitmap into Clipboard
::OpenClipboard(NULL);
::EmptyClipboard();
::SetClipboardData(CF_BITMAP, (HANDLE)hBmp);
::CloseClipboard();
::DeleteObject(hBmp);
// set style before setting bitmap
spCmdButton->PutStyle(Office::msoButtonIconAndCaption);

If the user copies text, launches Word, and pastes, they will insert my
beautiful bitmap, not their text.

However, if I use FaceId, I get one of the built-in icons.

How do I get my own icon without destroying the clipboard contents?

Can one push the clipboard contents onto a stack and then pop it?

And why do CommandBars support a technique that's user hostile?
 
Ad

Advertisements

P

Phlip

Phlip said:
Newsgroupies:

The sample code on this page is user-hostile:

http://www.mindcracker.com/mindcracker/c_cafe/atl/BuildingOffice2KCOMAddInAD.asp

How do I get my own icon without destroying the clipboard contents?

Can one push the clipboard contents onto a stack and then pop it?

Here's as far as I have gotten:

::OpenClipboard( NULL );
UINT format = EnumClipboardFormats(0);
HANDLE data = GetClipboardData(format);
::CloseClipboard();


::OpenClipboard( NULL );
::EmptyClipboard();
::SetClipboardData( CF_BITMAP, ( HANDLE ) hBmp );
::CloseClipboard();
::DeleteObject( hBmp );

// ... addButtons

::OpenClipboard( NULL );
::SetClipboardData( format, data );
::CloseClipboard();

Now the problem is a crash deep inside the second SetClipboardData(). I
figure if the current window owned the clipboard (instead of NULL owning
it), then the odds would improve. But I can't get the current window handle
out of pApp->ActiveWindow.

How to prevent the clipboard from crashing?
And why do CommandBars support a technique that's user hostile?

Because Pictures can't easily marshal, and COM interfaces must assume
remotability.
 
Ad

Advertisements

P

Phlip

Phlip said:
Newsgroupies:

The sample code on this page is user-hostile:

http://www.mindcracker.com/mindcracker/c_cafe/atl/BuildingOffice2KCOMAddInAD.asp

How do I get my own icon without destroying the clipboard contents?

Can one push the clipboard contents onto a stack and then pop it?

Here's as far as I have gotten:

::OpenClipboard( NULL );
UINT format = EnumClipboardFormats(0);
HANDLE data = GetClipboardData(format);
::CloseClipboard();


::OpenClipboard( NULL );
::EmptyClipboard();
::SetClipboardData( CF_BITMAP, ( HANDLE ) hBmp );
::CloseClipboard();
::DeleteObject( hBmp );

// ... addButtons

::OpenClipboard( NULL );
::SetClipboardData( format, data );
::CloseClipboard();

Now the problem is a crash deep inside the second SetClipboardData(). I
figure if the current window owned the clipboard (instead of NULL owning
it), then the odds would improve. But I can't get the current window handle
out of pApp->ActiveWindow.

How to prevent the clipboard from crashing?
And why do CommandBars support a technique that's user hostile?

Because Pictures can't easily marshal, and COM interfaces must assume
remotability.
 

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