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, ...
随机推荐
- gsoap 学习 1-自己定义接口生成头文件
接口头文件的格式在向导中没有看到明确的说明性的内容,但通过看开发包中示例程序中头文件定义和通过wsdl生成的头文件的内容,可以发现,头文件中都会出现以下几行信息 //gsoap ns service ...
- 【BZOJ】1625: [Usaco2007 Dec]宝石手镯(01背包)
http://www.lydsy.com/JudgeOnline/problem.php?id=1625 太水了. #include <cstdio> #include <cstri ...
- css字体属性相关。
出处:CSS 参考手册 http://www.w3school.com.cn/cssref/index.asp text-decoration 属性 说明:这个属性允许对文本设置某种效果,如加下 ...
- loadruner11 socket脚本-10053错误
背景: socket 10053异常:软件主动放弃一个连接,原因是超时或协议错误.如果LR客户端报10053异常,说明LR在执行套接字操作时,发生通信超时.网络中断或其它异常,主动将Socket连接断 ...
- AWS系列-添加购买的https证书
1.1 自行购买证书 1.2 上传证书 打开EC2的负载均衡 选择相应的ALB 添加侦听器 选择https 端口443 选择目标组 证书类型 上传证书到IAM 证书名称填写申请证书时候的那个域名 私有 ...
- HDU 2159 FATE(二维全然背包)
中文题目就不用解释了 就是裸的二维全然背包 d[i][j]表示消耗i忍耐杀j个怪最多可获得的经验 然后就用全然背包来做了 二维背包背包只是是多了一重循环 <span style=&quo ...
- iOS开发之--打印一堆奇怪东西的解决方案
Xcode8总是打印一堆奇怪的东西.虽然不影响开发,但是看着很不爽.解决的方法就是在Scheme里面添加(name):OS_ACTIVITY_MODE (value):disable 然后再在突出的框 ...
- 四 Android Studio打包EgretApp (热更新)
官网教程: http://developer.egret.com/cn/github/egret-docs/Native/native/hotUpdate/index.html 和Eclipse一样, ...
- java中计算时间差
Calendar cale = null; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" ...
- LeetCode 笔记系列四 Remove Nth Node From End of List
题目:Given a linked list, remove the nth node from the end of list and return its head.For example, Gi ...