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, ...
随机推荐
- 绑定QQ登录 PHP OAuth详解(转)
越来越多的网站开始采用 第三方账号登录 如qq 微博 开心网 等诸多流行的社交平台,利用第三方账号登录,可以更好地省去用户的注册时间,并且极大地提高用户体验,吸引更多的潜在用户. 让用户拥有 一个号码 ...
- MathType与Office公式编辑器有什么不同
说到在论文中编辑公式,有经验的人都会知道要用公式编辑器来编辑,没经验的人也会被安利使用公式编辑器.然而在使用公式编辑器时,又有了两种选择,一种是使用Office自带的公式编辑器,一种是MathType ...
- lumen 常用辅助函数
optional 函数接收任意参数并允许你访问对象上的属性或调用其方法.如果给定的对象为空,属性或方法调用返回 null return optional($user->address)-> ...
- 编程之美 set 4 找到符合条件的数
题目 任意给定一个正整数 N, 求一个最小的正整数 M (M > 1), 使得 N*M 的十进制表达式中只有 0 和 1. 解法 1. 枚举0,1能够组成的数字, 可以组成一颗二叉树 然后由 B ...
- myForm.js
根据控件名,重现一些特殊的表单项,生成html var can_submit = true; function myForm($form_id, $id_value, province, city, ...
- 获取jqGrid中选择的行的数据以及 jqGrid获得所有行数据的方法
获取jqGrid中选择的行的数据: 获取选择一行的id,如果你选择多行,那下面的id是最后选择的行的id: 1 var id=$('#gridTable').jqGrid('getGridPara ...
- highcharts配置的效果如下
配置如下: function init(categoryArray,seriesData,month_first_day,month_last_day,currDay){ var chart = Hi ...
- kafka基础概念
kafka介绍 kafka is a distributed, partitiononed,replicated commited logservice. kafka是一个分布式的.易扩展的.安全性高 ...
- angular2+ 自定义pipe管道实例--定义全局管道及使用
首先到项目目录下ng g pipe pipe/myslice 就会在app目录下生成一个pipe文件夹文件夹下有myslice.pipe.ts文件,如果没有也可以自己手动新建 然后需要再app.mod ...
- angular的属性绑定
1. 图片地址属性绑定 html文件 <img [src]="imgUrl"> ts文件 export class ProductComponent implement ...