// Win32 Dialog.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
#define TRAYICONID 1// ID number for the Notify Icon
#define SWM_TRAYMSG WM_APP// the message ID sent to our window
#define SWM_SHOW WM_APP + 1// show the window
#define SWM_HIDE WM_APP + 2// hide the window
#define SWM_EXIT WM_APP + 3// close the window
// Global Variables:
HINSTANCE hInst; // current instance
NOTIFYICONDATA niData; // notify icon data
// Forward declarations of functions included in this code module:
BOOL InitInstance(HINSTANCE, int);
BOOL OnInitDialog(HWND hWnd);
void ShowContextMenu(HWND hWnd);
ULONGLONG GetDllVersion(LPCTSTR lpszDllName);
INT_PTR CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow)) return FALSE;
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_STEALTHDIALOG);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)||
!IsDialogMessage(msg.hwnd,&msg) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
// Initialize the window and tray icon
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
// prepare for XP style controls
InitCommonControls();
// store instance handle and create dialog
hInst = hInstance;
HWND hWnd = CreateDialog( hInstance, MAKEINTRESOURCE(IDD_DLG_DIALOG),
NULL, (DLGPROC)DlgProc );
if (!hWnd) return FALSE;
// Fill the NOTIFYICONDATA structure and call Shell_NotifyIcon
// zero the structure - note: Some Windows funtions require this but
// I can't be bothered which ones do and
// which ones don't.
ZeroMemory(&niData,sizeof(NOTIFYICONDATA));
// get Shell32 version number and set the size of the structure
// note: the MSDN documentation about this is a little
// dubious and I'm not at all sure if the method
// bellow is correct
ULONGLONG ullVersion = GetDllVersion(_T("Shell32.dll"));
if(ullVersion >= MAKEDLLVERULL(5, 0,0,0))
niData.cbSize = sizeof(NOTIFYICONDATA);
else niData.cbSize = NOTIFYICONDATA_V2_SIZE;
// the ID number can be anything you choose
niData.uID = TRAYICONID;
// state which structure members are valid
niData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
// load the icon
niData.hIcon = (HICON)LoadImage(hInstance,MAKEINTRESOURCE(IDI_STEALTHDLG),
IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),
LR_DEFAULTCOLOR);
// the window to send messages to and the message to send
// note: the message value should be in the
// range of WM_APP through 0xBFFF
niData.hWnd = hWnd;
niData.uCallbackMessage = SWM_TRAYMSG;
// tooltip message
lstrcpyn(niData.szTip, _T("Time flies like an arrow but\n fruit flies like a banana!"), sizeof(niData.szTip)/sizeof(TCHAR));
Shell_NotifyIcon(NIM_ADD,&niData);
// free icon handle
if(niData.hIcon && DestroyIcon(niData.hIcon))
niData.hIcon = NULL;
// call ShowWindow here to make the dialog initially visible
return TRUE;
}
BOOL OnInitDialog(HWND hWnd)
{
HMENU hMenu = GetSystemMenu(hWnd,FALSE);
if (hMenu)
{
AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
AppendMenu(hMenu, MF_STRING, IDM_ABOUT, _T("About"));
}
HICON hIcon = (HICON)LoadImage(hInst,
MAKEINTRESOURCE(IDI_STEALTHDLG),
IMAGE_ICON, 0,0, LR_SHARED|LR_DEFAULTSIZE);
SendMessage(hWnd,WM_SETICON,ICON_BIG,(LPARAM)hIcon);
SendMessage(hWnd,WM_SETICON,ICON_SMALL,(LPARAM)hIcon);
return TRUE;
}
// Name says it all
void ShowContextMenu(HWND hWnd)
{
POINT pt;
GetCursorPos(&pt);
HMENU hMenu = CreatePopupMenu();
if(hMenu)
{
if( IsWindowVisible(hWnd) )
InsertMenu(hMenu, -1, MF_BYPOSITION, SWM_HIDE, _T("Hide"));
else
InsertMenu(hMenu, -1, MF_BYPOSITION, SWM_SHOW, _T("Show"));
InsertMenu(hMenu, -1, MF_BYPOSITION, SWM_EXIT, _T("Exit"));
// note: must set window to the foreground or the
// menu won't disappear when it should
SetForegroundWindow(hWnd);
TrackPopupMenu(hMenu, TPM_BOTTOMALIGN,
pt.x, pt.y, 0, hWnd, NULL );
DestroyMenu(hMenu);
}
}
// Get dll version number
ULONGLONG GetDllVersion(LPCTSTR lpszDllName)
{
ULONGLONG ullVersion = 0;
HINSTANCE hinstDll;
hinstDll = LoadLibrary(lpszDllName);
if(hinstDll)
{
DLLGETVERSIONPROC pDllGetVersion;
pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hinstDll, "DllGetVersion");
if(pDllGetVersion)
{
DLLVERSIONINFO dvi;
HRESULT hr;
ZeroMemory(&dvi, sizeof(dvi));
dvi.cbSize = sizeof(dvi);
hr = (*pDllGetVersion)(&dvi);
if(SUCCEEDED(hr))
ullVersion = MAKEDLLVERULL(dvi.dwMajorVersion, dvi.dwMinorVersion,0,0);
}
FreeLibrary(hinstDll);
}
return ullVersion;
}
// Message handler for the app
INT_PTR CALLBACK DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
switch (message)
{
case SWM_TRAYMSG:
switch(lParam)
{
case WM_LBUTTONDBLCLK:
ShowWindow(hWnd, SW_RESTORE);
break;
case WM_RBUTTONDOWN:
case WM_CONTEXTMENU:
ShowContextMenu(hWnd);
}
break;
case WM_SYSCOMMAND:
if((wParam & 0xFFF0) == SC_MINIMIZE)
{
ShowWindow(hWnd, SW_HIDE);
return 1;
}
else if(wParam == IDM_ABOUT)
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case SWM_SHOW:
ShowWindow(hWnd, SW_RESTORE);
break;
case SWM_HIDE:
case IDOK:
ShowWindow(hWnd, SW_HIDE);
break;
case SWM_EXIT:
DestroyWindow(hWnd);
break;
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
}
return 1;
case WM_INITDIALOG:
return OnInitDialog(hWnd);
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
niData.uFlags = 0;
Shell_NotifyIcon(NIM_DELETE,&niData);
PostQuitMessage(0);
break;
}
return 0;
}
// Message handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
没有合适的资源?快使用搜索试试~ 我知道了~
托盘图标-Win32API版本
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共9个文件
cpp:2个
h:2个
rc:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
![star](https://csdnimg.cn/release/downloadcmsfe/public/img/star.98a08eaa.png)
温馨提示
用Win32API Shell_NotifyIcon进行系统托盘图标编程<br>使用基础<br>托盘图标添加,编辑,删除包含如下两个步骤:<br>1.初使化NOTIFYICONDATA类型结构<br>2.调用Shell_NotifyIcon函数
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 9 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
- lh198800002014-09-10可以使用,谢谢。
- dosgo2012-08-09这个不错!可惜我用的是Dev C++!资源编辑不了!
- 新零售系统研发2013-06-03很好的插件
![avatar](https://profile-avatar.csdnimg.cn/8dc1944220a64f82a8d4f32e8c1e5e9e_johnnyrico.jpg!1)
无敌大头鱼
- 粉丝: 1
- 资源: 9
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- 13.字节流&字符流(下篇)
- 基于边缘计算的疲劳驾驶检测系统
- 汽车C柱工装夹具-零件图-机械工程图-机械三维3D建模图打包下载.zip
- 华为MRS产品文档详细参考
- 20N06HLD-VB一款N-Channel沟道TO252的MOSFET晶体管参数介绍与应用说明
- 电子设计论文硬件工程师手册-全电子设计论文硬件工程师手册-全
- 电子设计论文具有抗工频高二的多路高精度数据采集
- MADRL多智能体近端策略优化(MAPPO)算法
- 电子设计论文基于DPA425的开关电源的设计与研制
- 基于LabVIEW 2018开发的注册系统源码,可用于各种非标试验台的注册机制使用 用户可以根据实际自行改公司Logo,机器名
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)