没有合适的资源?快使用搜索试试~ 我知道了~
vc++托盘类专题:第5部分(说明)
需积分: 4 3 下载量 32 浏览量
2009-11-01
10:42:00
上传
评论
收藏 26KB TXT 举报
温馨提示
试读
24页
我自已要用托盘,可又觉得手工太麻烦! 锁性找了很多vc的托盘类! 生成托盘很方便的!
资源推荐
资源详情
资源评论
Let's go step-by-step.
1. Build a tray application
Here we are building a dialog-based application, which has a modeless dialog. So, create a new dialog-based MFC application (I've used Visual Studio 2005) with dialog class name CTrayMeDlg and application class name CTrayMeApp. Add a pointer variable *m_pApplicationDialog of CTrayMeDlg class in the application...
Collapse
class CTrayMeApp: public CWinApp
{
/* class code goes here */
private:
CTrayMeDlg * m_pApplicationDialog;
};
...and replace the traditional DoModal code with the following in the InitInstance() of the application class, as shown below.
Collapse
BOOL CTrayMeApp::InitInstance()
{
/* Function's default code goes here */
//Create a invisible modless dialog.
m_pApplicationDialog = new CTrayMeDlg();
m_pApplicationDialog->Create(IDD_TRAYME_DIALOG,NULL);
m_pMainWnd = m_pApplicationDialog;
ShowWindow(m_pMainWnd->GetSafeHwnd(),SW_HIDE);
return TRUE;
/*
CTrayMeDlg dlg;
1. Build a tray application
Here we are building a dialog-based application, which has a modeless dialog. So, create a new dialog-based MFC application (I've used Visual Studio 2005) with dialog class name CTrayMeDlg and application class name CTrayMeApp. Add a pointer variable *m_pApplicationDialog of CTrayMeDlg class in the application...
Collapse
class CTrayMeApp: public CWinApp
{
/* class code goes here */
private:
CTrayMeDlg * m_pApplicationDialog;
};
...and replace the traditional DoModal code with the following in the InitInstance() of the application class, as shown below.
Collapse
BOOL CTrayMeApp::InitInstance()
{
/* Function's default code goes here */
//Create a invisible modless dialog.
m_pApplicationDialog = new CTrayMeDlg();
m_pApplicationDialog->Create(IDD_TRAYME_DIALOG,NULL);
m_pMainWnd = m_pApplicationDialog;
ShowWindow(m_pMainWnd->GetSafeHwnd(),SW_HIDE);
return TRUE;
/*
CTrayMeDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
*/
}
You might have noticed the SW_HIDE parameter of ShowWindow(). We aren't going to show any dialog as we are building a tray application. All the UI we have for the application is just the context menu of the tray icon. Shell_NotifyIcon() is the API to deal with the application's system tray icon. It sends the message to the system tray to add, modify or delete the icon from the taskbar status area. The following code from OnInitDialog() of CTrayMeDlg makes the system add an application notification icon into the taskbar's status area.
Collapse
BOOL CTrayMeDlg::OnInitDialog()
{
/* Function's default code goes here*/
// TODO: Add extra initialization here
//Add a Tray Notification Icon for the application.
NOTIFYICONDATA niData;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
*/
}
You might have noticed the SW_HIDE parameter of ShowWindow(). We aren't going to show any dialog as we are building a tray application. All the UI we have for the application is just the context menu of the tray icon. Shell_NotifyIcon() is the API to deal with the application's system tray icon. It sends the message to the system tray to add, modify or delete the icon from the taskbar status area. The following code from OnInitDialog() of CTrayMeDlg makes the system add an application notification icon into the taskbar's status area.
Collapse
BOOL CTrayMeDlg::OnInitDialog()
{
/* Function's default code goes here*/
// TODO: Add extra initialization here
//Add a Tray Notification Icon for the application.
NOTIFYICONDATA niData;
剩余23页未读,继续阅读
资源评论
feegood
- 粉丝: 6
- 资源: 42
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功