Using Tray Icons in OCX controls
Jeff Evans -- evansj@huey.cadvision.com
Monday, April 08, 1996
Visual C++4.0, Win95, VB 4.0
I'm currently working on an OCX control that allows various shell
extensions to be used through Visual Basic 4.0. One part of the
control creates a tray icon, based on an Icon property (type
LPPICTUREDISP), which is set in VB.
I've tried various methods of assigning the Icon to the NOTIFYICONDATA
structure, but when I call Shell_NotifyIcon, the system doesn't create the
new tray icon... If I don't assign anything to the Icon property in
VB, a blank space appears in the tray, and it responds to click
events etc.
One of the ways I've been trying was to create a CPictureHolder
(lpIcon), and then in the SetIcon handler, call
lpIcon.SetPictureDispatch (newValue). I'd then use icondata.hIcon =
lpIcon.GetPictureDispatch() to set the icon, and then call
Shell_NotifyIcon.
I've also tried using the following code with no luck:
NOTIFYICONDATA icondata;
void CShellCtrl::SetIcon(LPPICTUREDISP newValue)
{
icondata.hIcon = (HICON)newValue;
SetModifiedFlag();
}
I would appreciate any information that you might have,
Thanks,
Jeff Evans.
Gareth Jones -- gaj@i2.co.uk
Thursday, April 11, 1996
Jeff Evans wrote:
>>Visual C++4.0, Win95, VB 4.0
>> I'm currently working on an OCX control that allows various shell
>>extensions to be used through Visual Basic 4.0. One part of the
>>control creates a tray icon, based on an Icon property (type
>>LPPICTUREDISP), which is set in VB.
>>One of the ways I've been trying was to create a CPictureHolder
>>(lpIcon), and then in the SetIcon handler, call
>>lpIcon.SetPictureDispatch (newValue). I'd then use icondata.hIcon =
>>lpIcon.GetPictureDispatch() to set the icon, and then call
>>Shell_NotifyIcon.
>>I've also tried using the following code with no luck:
>>
>> NOTIFYICONDATA icondata;
>>
>> void CShellCtrl::SetIcon(LPPICTUREDISP newValue)
>> {
>> icondata.hIcon = (HICON)newValue;
>>
>> SetModifiedFlag();
>> }
Hopefully the following will set you on your way again:
The LPPICTUREDISP newValue you get in your SetIcon handler is a pointer to a COM interface
called IPictureDisp, defined here. CPictureHolder is a wrapper class designed to hang onto one of these
things, so if you do a SetPictureDispatch into your CPictureHolder instance that should work fine.
However, its not usually necessary to use a holder if all you want is the HICON from it.
(If you want to easily draw the icon as part of your control's design-time appearance, using a
CPictureHolder to get an easy Render function is a good idea though).
Here is the definition for IPictureDisp:
dispinterface Picture
{
properties:
OLE_HANDLE Handle;
OLE_HANDLE hPal;
short Type;
OLE_XSIZE_HIMETRIC Width;
OLE_YSIZE_HIMETRIC Height;
};
typedef Picture IPictureDisp;
where the Type values are one of:
#define PICTYPE_UNINITIALIZED -1 // Not valid for OleCreatePicture
#define PICTYPE_NONE 0
#define PICTYPE_BITMAP 1
#define PICTYPE_METAFILE 2
#define PICTYPE_ICON 3
This is a dispatch interface, so the easiest way to talk to it is to use a COleDispatchDriver instance
and call AttachDispatch with the pointer. This will allow you to easily retieve properties from it.
You can retrieve the Type property by using either this method or using the simple GetType member
if you have a CPictureHolder.
If the Type is PICTYPE_ICON (which is needed, the others won't work) then you can retrieve the Handle
member and assume safely that it is an HICON. This can be put into your notify structure for the tray.
Hope this helps,
Gareth
-----------------------------------------------------------------
Gareth Jones Software Consultant visualize2analyse
gaj@i2.co.uk i2 Ltd, Cambridge, UK information2image
Jeff Evans -- evansj@huey.cadvision.com
Saturday, April 13, 1996
> If the Type is PICTYPE_ICON (which is needed, the others won't work)
> then you can retrieve the Handle member and assume safely that it is
> an HICON. This can be put into your notify structure for the tray.
I've been able to retrieve the Handle member, however, it is an
OLE_HANDLE (unsigned integer). I've tried type casting the handle
to an HICON, and it didn't seem to work either.
I've probably missed something in your explination, and I'd
appreciate it if you might know what...
Jeff.
Mike Blaszczak -- mikeblas@msn.com
Wednesday, April 17, 1996
John Elsbree posted this code to the list around the end of February:
HICON GetIcon(CPictureHolder& pictureHolder)
{
HICON hIcon = NULL;
LPPICTUREDISP pDisp = pictureHolder.GetPictureDispatch();
if (pDisp != NULL)
{
LPPICTURE pPic;
if (SUCCEEDED(pDisp->QueryInterface(IID_IPicture, (void**)&pPic)))
{
short sType = PICTYPE_NONE;
pPic->get_Type(&sType);
if (sType == PICTYPE_ICON)
pPic->get_Handle((OLE_HANDLE*)&hIcon);
pPic->Release();
}
pDisp->Release();
}
return hIcon;
}
I think it's what you're looking for.
.B ekiM
TCHAR sz[] = _T("Check twice and save a life: motorcycles are everywhere!");
----------
From: owner-mfc-l@netcom.com on behalf of Jeff Evans
Sent: Saturday, April 13, 1996 16:30
To: mfc-l@netcom.com
Subject: RE: Using Tray Icons in OCX controls
> If the Type is PICTYPE_ICON (which is needed, the others won't work)
> then you can retrieve the Handle member and assume safely that it is
> an HICON. This can be put into your notify structure for the tray.
I've been able to retrieve the Handle member, however, it is an
OLE_HANDLE (unsigned integer). I've tried type casting the handle
to an HICON, and it didn't seem to work either.
I've probably missed something in your explination, and I'd
appreciate it if you might know what...
Jeff.
| Вернуться в корень Архива
|