VC++: Trying to change taskbar icons using notifyIcon1 and imageList1

  • Thread starter Thread starter bahnfire
  • Start date Start date
B

bahnfire

Hi,

I am hoping that I finally have the right group :-)

I am using Visual C++ Express 2008 and am trying to change the taskbar
icon that I am using (notifyIcon1) as some state changes (button
press, etc) in my form/app. I have read that I can use imageList1 and
have the following:

//
// notifyIcon1
//
this->notifyIcon1->Icon = (cli::safe_cast<System::Drawing::Icon^
(resources->GetObject(L"notifyIcon1.Icon")));

this->notifyIcon1->Text = L"Right-click to access";
this->notifyIcon1->Visible = true;

//
// imageList1
//
this->imageList1->ImageStream =
(cli::safe_cast<System::Windows::Forms::ImageListStreamer^
(resources->GetObject(L"imageList1.ImageStream")));

this->imageList1->TransparentColor =
System::Drawing::Color::Transparent;
this->imageList1->Images->SetKeyName(0, L"one.ico");
this->imageList1->Images->SetKeyName(1, L"two.ico");
this->imageList1->Images->SetKeyName(2, L"three.ico");
this->imageList1->Images->SetKeyName(3, L"g=four.ico");
this->imageList1->Images->SetKeyName(4, L"five.ico");

I have read that I am supposed to use the following 'notifyIcon1->Icon
= Icon->FromHandle();', but all of the examples that I have seen are
for VB and VC#.

I would appreciate any help.

Thanks!
 
Hi,

I am hoping that I finally have the right group :-)

I am using Visual C++ Express 2008 and am trying to change the taskbar
icon that I am using (notifyIcon1) as some state changes (button
press, etc) in my form/app. I have read that I can use imageList1 and
have the following:

//
// notifyIcon1
//
this->notifyIcon1->Icon = (cli::safe_cast<System::Drawing::Icon^


this->notifyIcon1->Text = L"Right-click to access";
this->notifyIcon1->Visible = true;

//
// imageList1
//
this->imageList1->ImageStream =
(cli::safe_cast<System::Windows::Forms::ImageListStreamer^


this->imageList1->TransparentColor =
System::Drawing::Color::Transparent;
this->imageList1->Images->SetKeyName(0, L"one.ico");
this->imageList1->Images->SetKeyName(1, L"two.ico");
this->imageList1->Images->SetKeyName(2, L"three.ico");
this->imageList1->Images->SetKeyName(3, L"g=four.ico");
this->imageList1->Images->SetKeyName(4, L"five.ico");

I have read that I am supposed to use the following 'notifyIcon1->Icon
= Icon->FromHandle();', but all of the examples that I have seen are
for VB and VC#.

I would appreciate any help.

Thanks!

Never mind... figured it out. Solution is below (or at least a
solution that I found and was able to implement - do not have source):

1) Add icons to resources (.resx) file. If the form screams if you add
them by hand, make a few extra icons in the form builder and give them
icons. You can also not show them.
2) Add: private: System::Resources::ResourceManager^ Resources;
3) Add to mainform_onload (or somewhere else where it will get run on
start - do not put in auto generated area): this->Resources = gcnew
System::Resources::ResourceManager(L"project name.form
name",System::Reflection::Assembly::GetExecutingAssembly());
4) Add code wherever the icon needs to change: this->notifyIcon1->Icon
= (cli::safe_cast said:
GetObject(L"icon name from resource file")));

NOTE: I was not able to set the initial icon from the auto. generated
form using this. I had to leave it alone or the form would scream and
wasn't able to run outside of the app (would compile and can debug,
but would not run if VC++ was closed). Auto generated code is: this-
notifyIcon1->Icon = (cli::safe_cast<System::Drawing::Icon^
(resources->GetObject(L"icon name from resource file")));

TIPS: 'project name' is your project name; 'form name' is your form
name; 'icon name from resource file' is the name of the icon from the
resx file.

Cheers!
Paul
 
I am having a problem with Images.
I have a bundle of images to be used as icons. I want to change these images
on Mouse Hover.
How can I include these images with the application and change image on
mouse hover.
I tried to use this:
private: System::Void ImgSettings_MouseHover(System::Object^ sender,
System::EventArgs^ e) {
Image^ newImage = Image::FromFile("Images\\SettingSel.png");
ImgSettings->Image= newImage; }

This would run fine on the development machine. But on an user system, i get
an exception, which is obvious. My problem is how to provide these images
with the application.

TIA
 
Back
Top