Recommend a simple pallet class

Source: Internet
Author: User

Some netizens developed their own pallet class, to achieve a slightly cumbersome. Here I recommend a simple and very effective pallet class (which I learned in a book).

1. Copy TrayIcon.cpp and TrayIcon.cpp to your project directory and add it to your project.

2, add #include "TrayIcon.h" in DemoDlg.h

3, add member variable Ctrayicon M_ctrayicon through Class Cdemodlg to guide class;

4, the establishment of menu resources, so that its ID: idr_demo, Design menu:

To add an event handler to Demo1 and exit:

void CDemoDlg::OnFileDemo1()
{
  ShowWindow(SW_SHOW);
  m_TrayIcon.RemoveIcon();
}
  
void CDemoDlg::OnFileExit()
{
  m_TrayIcon.RemoveIcon();
  OnCancel();
}

5. Customize the message #define Wm_icon_notify wm_user+10 in DemoDlg.cpp and declare the message handler function at the declaration message:

BEGIN_MESSAGE_MAP(CDemoDlg, CDialog)
  ......
  ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification)
  ……
END_MESSAGE_MAP()

To add a member function to the class Cdemodlg:

LRESULT OnTrayNotification(WPARAM wParam,LPARAM lParam);

Implementation section:

LRESULT CDemoDlg::OnTrayNotification(WPARAM wParam,LPARAM lParam)
{
  return m_TrayIcon.OnTrayNotification(wParam,lParam);
}

6, add the "Start" button in the dialog box, and double-click the "Start" button to edit the handler:

void CDemoDlg::OnBnClickedButton1()
{
  m_TrayIcon.Create(this,WM_ICON_NOTIFY,"鼠标指向时显示",m_hIcon,IDR_DEMO); //构造
  ShowWindow(SW_HIDE); //隐藏窗口
}

7, you can flexibly use other class member functions. such as: SetIcon change the icon, you can use the timer message to achieve the tray icon animation effect.

8, delete tray icon: M_trayicon.removeicon ();

This article supporting source code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.