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的更多相关文章

  1. [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 ...

  2. 在WINDOWS中安装使用GSL(MinGW64+Sublime Text3 & Visual Studio)

    本文介绍在Windows下安装使用GSL库,涉及GSL两个版本(官方最新版及GSL1.8 VC版).msys shell.GCC.G++等内容,最终实现对GSL安装及示例基于MinGW64在Subli ...

  3. [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 ...

  4. 安装InfoPath 2013后 SharePoint 2010 出现 “找不到 Microsoft.Office.InfoPath, Version=14.0.0....” 的错误的解决方案

    1. 症状 您的SharePoint 2010的服务器是不是最近一直出现这个错误呢? Could not load file or assembly 'Microsoft.Office.InfoPat ...

  5. 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 ...

  6. WPF datagrid 动态增加列

    DataGrid动态增加列 <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.m ...

  7. 关于DLL搜索路径顺序的一个问题

    DLL的动态链接有两种方法.一种是加载时动态链接(Load_time dynamic linking).Windows搜索要装入的DLL时,按以下顺序:应用程序所在目录→当前目录→Windows SY ...

  8. 【转载】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 ...

  9. [LeetCode] All questions numbers conclusion 所有题目题号

    Note: 后面数字n表明刷的第n + 1遍, 如果题目有**, 表明有待总结 Conclusion questions: [LeetCode] questions conclustion_BFS, ...

随机推荐

  1. MyBatis是支持普通 SQL查询

    MyBatis是支持普通 SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis 消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索.MyBatis 使用简单的 XML或注解用于配置 ...

  2. 【BZOJ】1679: [Usaco2005 Jan]Moo Volume 牛的呼声(数学)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1679 水题没啥好说的..自己用笔画画就懂了 将点排序,然后每一次的点到后边点的声音距离和==(n-i ...

  3. Codeforces Round #265 (Div. 2)

    http://codeforces.com/contest/465 rating+7,,简直... 感人肺腑...............蒟蒻就是蒟蒻......... 被虐瞎 a:inc ARG 题 ...

  4. 小结:trie

    复杂度: 查找O(n),维护O(n),空间O(sum(len[i])) 概要: 就是每个节点对应一个字母,然后儿子有26个,查找和维护时进入对应儿子即可. 应用:在字符串匹配中多模匹配做基础结构:可以 ...

  5. uc 调试

    UC浏览器开发者版 目录[隐藏] 1 关于RI 2 准备工作 3 调试方式 相关下载 1 关于RI 目前,在手机上使用浏览器访问网页,无法便捷地进行网页语言调试.手机屏幕相对较小且操作不便,直接在手机 ...

  6. 三、Gradle初级教程——Gradle除了签名打包还能配置jar包

    1.gradle概念 构建工具,Groovy,Java. 2.gradle配置jar包,和libs文件夹导入jar包的区别 到此,还是这种方法导入JAR包比较方便.每次更新JAR包,只需要修改版本号就 ...

  7. php实现简单的权限管理

    今天主要来实现一个权限管理系统,它主要是为了给不同的用户设定不同的权限,从而实现不同权限的用户登录之后使用的功能不一样,首先先看下数据库 总共有5张表,qx_user,qx_rules和qx_jues ...

  8. 【BZOJ4818】[Sdoi2017]序列计数 DP+矩阵乘法

    [BZOJ4818][Sdoi2017]序列计数 Description Alice想要得到一个长度为n的序列,序列中的数都是不超过m的正整数,而且这n个数的和是p的倍数.Alice还希望 ,这n个数 ...

  9. angular 2+ innerHTML属性中内联样式丢失

    通过属性绑定的innerHTML,把字符串里面的html解析 解析是没问题的,但一些内联样式会丢失掉 为了不丢掉样式,需要自定义一个管道来解决这个问题 html.pipe.ts import {Pip ...

  10. 160601、Websocet服务端实现

    今天是六一儿童节,祝愿小朋友们节日快乐!大朋友们事事顺心! Websocet服务端实现 WebSocketConfig.Java ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...