A class for dynamic icons in Windows
A class for dynamic icons in Windows
#include <windows.h>
class DynamicIcon {
public:
DynamicIcon();
~DynamicIcon();
HICON Icon();
private:
HDC memDC1_;
HDC memDC2_;
HBITMAP oldBmp_1;
HBITMAP oldBmp_2;
HBITMAP iconBmp_;
HBITMAP iconMaskBmp_;
HBRUSH hCircleBrush;
HBRUSH hTranspBrush;
HBRUSH hOldBrush;
HRGN circle;
HICON icon_;
static int const iconWidth_;
static int const iconHeight_;
};
int const DynamicIcon::iconWidth_ = 16;
int const DynamicIcon::iconHeight_ = 16;
DynamicIcon::DynamicIcon() {
HDC hDC = GetDC (0);
memDC1_ = CreateCompatibleDC (hDC);
memDC2_ = CreateCompatibleDC (hDC);
iconBmp_ = CreateCompatibleBitmap (hDC, iconWidth_, iconHeight_);
iconMaskBmp_ = CreateCompatibleBitmap (hDC, iconWidth_, iconHeight_);
oldBmp_1 = (HBITMAP) SelectObject (memDC1_, (HBITMAP) iconBmp_);
oldBmp_2 = (HBITMAP) SelectObject (memDC2_, (HBITMAP) iconMaskBmp_);
// prepare mask
HBRUSH hBrush = CreateSolidBrush (RGB (255, 255, 255));
hOldBrush = (HBRUSH) SelectObject (memDC2_, hBrush);
PatBlt (memDC2_, 0, 0, iconWidth_, iconHeight_, PATCOPY);
SelectObject (memDC2_, hOldBrush);
DeleteObject (hBrush);
// draw circle on both bitmaps
circle = CreateEllipticRgn (0, 0, iconWidth_, iconHeight_);
hBrush = CreateSolidBrush (RGB (255, 0, 0));
FillRgn (memDC1_, circle, hBrush);
DeleteObject (hBrush);
hBrush = CreateSolidBrush (RGB (0, 0, 0));
FillRgn (memDC2_, circle, hBrush);
DeleteObject (hBrush);
DeleteObject (circle);
SelectObject (memDC1_, (HBITMAP) oldBmp_1);
DeleteDC (memDC1_);
SelectObject (memDC2_, (HBITMAP) oldBmp_2);
DeleteDC (memDC2_);
DeleteDC (hDC);
ICONINFO ii = {TRUE, 0, 0, iconMaskBmp_, iconBmp_};
icon_ = CreateIconIndirect (&ii);
}
DynamicIcon::~DynamicIcon() {
DestroyIcon (icon_);
DeleteObject(iconBmp_);
DeleteObject(iconMaskBmp_);
}
HICON DynamicIcon::Icon() {
return icon_;
}
LRESULT CALLBACK WndProc(
HWND hWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam ) {
switch( msg ) {
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hDC = BeginPaint( hWnd, &ps );
TextOut(hDC, 10, 10, "ADP GmbH", 8 );
EndPaint( hWnd, &ps );
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc( hWnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow) {
DynamicIcon di;
WNDCLASSEX wce;
wce.cbSize = sizeof(wce);
wce.style = CS_VREDRAW | CS_HREDRAW;
wce.lpfnWndProc = (WNDPROC) WndProc;
wce.cbClsExtra = 0;
wce.cbWndExtra = 0;
wce.hInstance = hInstance;
wce.hIcon = <b>di.Icon()</b>;
wce.hCursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW);
wce.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wce.lpszMenuName = 0;
wce.lpszClassName = "ADPWinClass",
wce.hIconSm = 0;
if (!RegisterClassEx(&wce)) return 0;
HWND hWnd = CreateWindowEx(
0, // Ex Styles
"ADPWinClass",
"ADP GmbH",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, // x
CW_USEDEFAULT, // y
CW_USEDEFAULT, // Hoehe
CW_USEDEFAULT, // Breite
NULL, // ElternWindow
NULL, // Menu respektive Child ID
hInstance, //
NULL // Pointer auf Daten zu diesem Window
);
ShowWindow( hWnd, nCmdShow );
MSG msg;
int r;
while ((r = GetMessage(&msg, NULL, 0, 0 )) != 0) {
if (r == -1) {
; // Error!
}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
};
A class for dynamic icons in Windows的更多相关文章
- [LeetCode] 643. Maximum Average Subarray I_Easy tag: Dynamic Programming(Sliding windows)
Given an array consisting of n integers, find the contiguous subarray of given length k that has the ...
- 在WINDOWS中安装使用GSL(MinGW64+Sublime Text3 & Visual Studio)
本文介绍在Windows下安装使用GSL库,涉及GSL两个版本(官方最新版及GSL1.8 VC版).msys shell.GCC.G++等内容,最终实现对GSL安装及示例基于MinGW64在Subli ...
- [Windows Azure] Developing Multi-Tenant Web Applications with Windows Azure AD
Developing Multi-Tenant Web Applications with Windows Azure AD 2 out of 3 rated this helpful - Rate ...
- 安装InfoPath 2013后 SharePoint 2010 出现 “找不到 Microsoft.Office.InfoPath, Version=14.0.0....” 的错误的解决方案
1. 症状 您的SharePoint 2010的服务器是不是最近一直出现这个错误呢? Could not load file or assembly 'Microsoft.Office.InfoPat ...
- Configure the max limit for concurrent TCP connections(转)
To keep the TCP/IP stack from taking all resources on the computer, there are different parameters t ...
- WPF datagrid 动态增加列
DataGrid动态增加列 <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.m ...
- 关于DLL搜索路径顺序的一个问题
DLL的动态链接有两种方法.一种是加载时动态链接(Load_time dynamic linking).Windows搜索要装入的DLL时,按以下顺序:应用程序所在目录→当前目录→Windows SY ...
- 【转载】Configure the max limit for concurrent TCP connections
转载地址:http://smallvoid.com/article/winnt-tcpip-max-limit.html To keep the TCP/IP stack from taking al ...
- [LeetCode] All questions numbers conclusion 所有题目题号
Note: 后面数字n表明刷的第n + 1遍, 如果题目有**, 表明有待总结 Conclusion questions: [LeetCode] questions conclustion_BFS, ...
随机推荐
- CI -- $this->load->library()详解
我第一次加载失败,原来是文件名和类名不同的原因,先总结关于CI加载你自己的类文件注意事项: 1.第三方加载文件应放在application/libraries文件下 2.文件名和类名应该相同,并且首字 ...
- hdu 2141:Can you find it?(数据结构,二分查找)
Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others ...
- MFC存储图片到SQL Server数据库
第一步:建立数据库表,比如:id char,pic image. 第二步:建立MFC单文档应用程序,再添加类CMyRecordset,基类选择CRecordset,导入数据库的刚建立的表. 第三步:在 ...
- Redis分布式锁,基于StringRedisTemplate和基于Lettuce实现setNx
使用redis分布式锁,来确保多个服务对共享数据操作的唯一性一般来说有StringRedisTemplate和RedisTemplate两种redis操作模板. 根据key-value的类型决定使用哪 ...
- Hadoop单机安装配置过程:
1. 首先安装JDK,必须是sun公司的jdk,最好1.6版本以上. 最后java –version 查看成功与否. 注意配置/etc/profile文件,在其后面加上下面几句: export JAV ...
- C#三种字符串拼接方法的效率对比
C#字符串拼接的方法常用的有:StringBuilder.+.string.Format.List<string>.使用情况不同,效率不同. 1.+的方式 string sql = &qu ...
- 【BZOJ4262】Sum 单调栈+线段树
[BZOJ4262]Sum Description Input 第一行一个数 t,表示询问组数. 第一行一个数 t,表示询问组数. 接下来 t 行,每行四个数 l_1, r_1, l_2, r_2. ...
- 【BZOJ3442】学习小组 费用流
[BZOJ3442]学习小组 Description [背景] 坑校准备鼓励学生参加学习小组. [描述] 共有n个学生,m个学习小组,每个学生有一定的喜好,只愿意参加其中的一些学习小组,但是校领导为学 ...
- LeetCode 笔记系列三 3Sum
题目:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all ...
- Ubuntu 16.04 安装 Gnome 桌面环境
个人博客链接:Ubuntu 16.04 安装 Gnome 桌面环境