首页 | 互联网 | IT动态 | IT培训 | Cisco | Windows | Linux | Java | .Net | Oracle | 软件测试 | C/C++ | 嵌入式开发 | 存储世界 | 服务器
网络设备 | IDC | 安全 | 求职招聘 | 数字网校 | 网页设计 | 平面设计 | 技术专题 | 电子书下载 | 教学视频 | 源码下载 | 搜索 | 博客 | 论坛
中国IT实验室Dotnet频道
中国IT教育
Google
首页 ASP.NET  C#  XML/WebService ADO.NET VC.NET VB.NET .NET 资讯动态 专题 RSS订阅 讨论 下载
您现在的位置: 中国IT实验室 >> Dotnet >> VC.NET >> 正文

利用Visual C++实现系统托盘程序


///////////////////////////////// MainFrm.h : interface of the CMainFrame class
#if !defined(AFX_MAINFRM_H__9ED70A69_C975_4F20_9D4E_B2877E3575D0__INCLUDED_)
#define AFX_MAINFRM_H__9ED70A69_C975_4F20_9D4E_B2877E3575D0__INCLUDED_
#if _MSC_VER >1000
#pragma once
#endif // _MSC_VER >1000

#include "trayicon.h"
class CMainFrame : public CFrameWnd
{
 public:
  CMainFrame();
 protected:
  DECLARE_DYNAMIC(CMainFrame)
  // Attributes
 public:
  // Overrides
  // ClassWizard generated virtual function overrides
  //{{AFX_VIRTUAL(CMainFrame)
  //}}AFX_VIRTUAL
  // Implementation
 public:
  virtual ~CMainFrame();
  #ifdef _DEBUG
   virtual void AssertValid() const;
   virtual void Dump(CDumpContext& dc) const;
  #endif
 protected: // control bar embedded members
  CStatusBar m_wndStatusBar;
  CTrayIcon m_trayIcon; // my tray icon
  CEdit m_wndEdit; // to display tray notifications
  int m_iWhichIcon; // which HICON to use
  BOOL m_bShutdown; // OK to terminate TRAYTEST
  BOOL m_bShowTrayNotifications; // display info in main window
  // Generated message map functions
 protected:
  //{{AFX_MSG(CMainFrame)
   afx_msg LRESULT OnTrayNotification(WPARAM wp, LPARAM lp);
   afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
   afx_msg void OnToggleIcon();
   afx_msg void OnViewClear();
   afx_msg void OnViewNotifications();
   afx_msg void OnUpdateViewClear(CCmdUI* pCmdUI);
   afx_msg void OnUpdateViewNotifications(CCmdUI* pCmdUI);
   afx_msg void OnClose();
   afx_msg void OnAppOpen();
   afx_msg void OnAppSuspend();
   // NOTE - the ClassWizard will add and remove member functions here.
   // DO NOT EDIT what you see in these blocks of generated code!
  //}}AFX_MSG
 DECLARE_MESSAGE_MAP()
};  


 

///////////////////////////////////////////////CMainFrm.cpp
#include "stdafx.h"
#include "TrayTest.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

LRESULT CTrayIcon::OnTrayNotification(WPARAM wID, LPARAM lEvent)
{
 if (wID!=m_nid.uID    (lEvent!=WM_RBUTTONUP && lEvent!=WM_LBUTTONDBLCLK))
  return 0;
 CMenu menu;//装载上下文菜单;
 if (!menu.LoadMenu(m_nid.uID))
  return 0;
 CMenu* pSubMenu = menu.GetSubMenu(0);
 if (!pSubMenu)
  return 0;
 if (lEvent==WM_RBUTTONUP) {//设置第一个菜单项为默认菜单项目
  ::SetMenuDefaultItem(pSubMenu->m_hMenu, 0, TRUE);
  //将当前菜单作为上下文菜单;
  CPoint mouse;
  GetCursorPos(&mouse);
  ::SetForegroundWindow(m_nid.hWnd);
  ::TrackPopupMenu(pSubMenu->m_hMenu, 0, mouse.x, mouse.y, 0,m_nid.hWnd, NULL);
 } else // double click: execute first menu item
  ::SendMessage(m_nid.hWnd, WM_COMMAND, pSubMenu->GetMenuItemID(0), 0);
 return 1;
}  

上一页  [1] [2] [3] [4] [5] 下一页

【责编:Peng】

中国IT教育

相关产品和培训
文章评论
 友情推荐链接
 认证培训
 专题推荐

 ·WEB程序开发--ASP.NET和PHP、JSP究竟学哪个?
 ·五步带你入门XML
 ·关于Java框架技术专题
 ·XML全攻略技术专题
 ·JAVA开源技术介绍专题
 ·Java嵌入式开发之J2ME技术专题
 ·超前体验 Oracle 11g的5个新特性…
 ·揭密使用VB.NET的五个实用技巧
 ·Oracle和SQL Server常用函数对比专题…
 ·展现C#世界 C#程序设计专题…
 今日更新
 社区讨论
 博客论点
 频道精选
 Dotnet频道相关导航