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, ...
随机推荐
- 在J2EE的Web应用中,编译后的class文件存放的目录为(选择1项)
在J2EE的Web应用中,编译后的class文件存放的目录为(选择1项) A. classes目录 B. images目录 C. jar目录 D. 任意位置 解答:A
- php如何判断两个时间的时间差
$time1=2011-11-11 11:11:11$time2=2016-12-10 16:58:13 代码: if(abs(strtotime($time2)-strtotime($time1)) ...
- 在MFC中改变控件的TAB顺序
在MFC界面中,控件的TAB顺序如果乱了,不合理,可能会使界面出现意料之外的显示. 例如,在用Spin Control来对Edit Control内的值进行增减时,如果Edit Control.Spi ...
- 漫游Kafka设计篇之Producer和Consumer(4)
Kafka Producer 消息发送 producer直接将数据发送到broker的leader(主节点),不需要在多个节点进行分发.为了帮助producer做到这点,所有的Kafka节点都可以及时 ...
- Mac终端运行java程序
1.编辑源文件HelloWorld.java 2.编译源文件 javac HelloWorld.java 生成HelloWorld.class文件 3.执行java字节码 注意,一定要到源目录下,并且 ...
- python3----datetime模块分析
datetime模块用于是date和time模块的合集,datetime有两个常量,MAXYEAR和MINYEAR,分别是9999和1. datetime模块定义了5个类,分别是 1.datetime ...
- 深入了解Java之虚拟机内存
在讨论JVM内存区域分析之前,先来看一下Java程序详细运行的过程: -我们今天就来分析一下Java程序运行过程的-Runtime-Data-Area(运行时数据)-这一块" class=& ...
- 下载Qt安装包
http://download.qt.io/archive/qt/ 找到下载页面,选择View All Downloads,找你需要的版本
- C语言函数的概念
在<我们对函数进行了简单的解释,函数(Function)是一段可以重复使用的代码,这是从整体上对函数的认识. C语言本身带了很多库函数,并分门别类地放在了不同的头文件中,使用时只要引入对应的头文 ...
- git练习
git commit 提交记录 git branch <branch_name> 建立名为branch_name的分支 git checkout <name>:git comm ...