#pragma once
#include
HICON myCreateIcon(HWND hwnd, HICON hicon);
VOID setOverLay(HWND hWnd, HICON hIcon, const WCHAR* description);
VOID resetOverLay(HWND hWnd);
void setMyIcon(HWND hwnd);
#include "overlapIcon.h"
#include "apifuns.h"
#include "main.h"
#include
#include
#include "resource.h"
#pragma pack(1)
typedef struct
{
BITMAPINFOHEADER icHeader;
} ICONIMAGE, * LPICONIMAGE;
typedef struct
{
BYTE bWidth;
BYTE bHeight;
BYTE bColorCount;
BYTE bReserved;
WORD wPlanes;
WORD wBitCount;
DWORD dwBytesInRes;
DWORD dwImageOffset;
} ICONDIRENTRY, * LPICONDIRENTRY;
typedef struct
{
WORD idReserved;
WORD idType;
WORD idCount;
ICONDIRENTRY idEntries[1];
} ICONDIR, * LPICONDIR;
#pragma pack()
HICON getAppIcon(HWND hwnd);
int copyScanline(BYTE* dst, BYTE* src, int src_line_size, int dst_line_size, int height);
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
int blendPixel(BYTE* dst, BYTE* src, int src_line_size, int dst_line_size, int src_height, int backgroundWeigh);
#define PIXERL_BLEND_APP_ICON_WEIGH 120
int compressBmp(BYTE* line, int line_size, int bytesperpix, int src_height) {
DWORD* src_ptr = (DWORD*)line;
DWORD* dst_ptr = (DWORD*)(line + bytesperpix);
for (int i = 0; i < src_height; i++)
{
for (int j = 0; j < line_size / bytesperpix / 2; j += 2)
{
src_ptr[j] = (src_ptr[j] + dst_ptr[j]) / 2;
}
dst_ptr += line_size;
src_ptr += line_size;
}
src_ptr = (DWORD*)line;
dst_ptr = (DWORD*)line + line_size;
for (int i = 0; i < src_height / 2; i++)
{
for (int j = 0; j < line_size / sizeof(DWORD) / 2; j++)
{
src_ptr[j] = (src_ptr[j] + dst_ptr[j]) / 2;
}
dst_ptr = dst_ptr + line_size * 2;
src_ptr = src_ptr + line_size * 2;
}
return TRUE;
}
int copyScanline(BYTE* dst, BYTE* src, int src_line_size, int dst_line_size, int src_height) {
BYTE* dst_ptr = dst;
BYTE* src_ptr = src;
for (int i = 0; i < src_height; i++)
{
memcpy(dst_ptr, src_ptr, src_line_size);
dst_ptr += dst_line_size;
src_ptr += src_line_size;
}
return TRUE;
}
int blendScanline(BYTE* dst, BYTE* src, int src_line_size, int dst_line_size, int src_height, int backgroundWeigh) {
BYTE* dst_ptr = dst;
BYTE* src_ptr = src;
for (int i = 0; i < src_height; i++)
{
for (int j = 0; j < src_line_size; j++)
{
BYTE src_byte = src_ptr[j];
BYTE dst_byte = dst_ptr[j];
BYTE v = (src_byte * (255 - backgroundWeigh) + dst_byte * backgroundWeigh) / 255;
dst_ptr[j] = v;
}
dst_ptr += dst_line_size;
src_ptr += src_line_size;
}
return TRUE;
}
int blendPixel(BYTE* dst, BYTE* src, int src_line_size, int dst_line_size, int src_height, int backgroundWeigh) {
if (backgroundWeigh)
{
return blendScanline(dst, src, src_line_size, dst_line_size, src_height, backgroundWeigh);
}
else {
return copyScanline(dst, src, src_line_size, dst_line_size, src_height);
}
return 0;
}
BOOL CALLBACK myEnumWindowsProc(HWND hwnd, LPARAM lParam)
{
int result = 0;
HWND hwnd_owner = GetWindow(hwnd, GW_OWNER);
int isvisible = IsWindowVisible(hwnd);
if (hwnd_owner == 0 && isvisible)
{
wchar_t title[256];
GetWindowTextW(hwnd, title, 256);
wchar_t classname[256];
GetClassName(hwnd, classname, 256);
if (wcscmp(classname, L"Progman") == 0 || wcscmp(classname, L"WorkerW") == 0)
{
return false;
}
WCHAR procsid[MAX_PATH];
WCHAR procimage[MAX_PATH];
ULONG sessionid = 0;
WCHAR procboxname[64] = { 0 };
DWORD dwProcessID = 0;
result = GetWindowThreadProcessId(hwnd, &dwProcessID);
result = SbieApi_QueryProcess((HANDLE)dwProcessID, procboxname, procimage, procsid, &sessionid);
if (procboxname[0] == 0)
{
return FALSE;
}
myCreateIcon(hwnd, 0);
}
return true;
}
HICON getAppIcon(HWND hwnd) {
HICON hicon_app = reinterpret_cast<HICON>(::SendMessageW(hwnd, WM_GETICON, ICON_BIG, 0));
if (hicon_app == 0) {
#ifdef _WIN64
hicon_app = (HICON)GetClassLongPtr(hwnd, GCLP_HICON);
#else
hicon_app = (HICON)GetClassLongPtr(hwnd, GCL_HICON);
#endif
}
if (hicon_app == 0) {
hicon_app = ::LoadIcon(GetModuleHandleW(0), MAKEINTRESOURCE(0));
}
if (hicon_app == 0) {
hicon_app = ::LoadIcon(0, IDI_APPLICATION);
}
return hicon_app;
}
char* back_icon_file_data = 0;
HICON myCreateIcon(HWND hwnd, HICON hicon)
{
int result = 0;
HICON h_myicon = (HICON)LoadImageW(g_dllModule, (WCHAR*)IDI_ICON1, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
return 0;
setOverLay(hwnd, h_myicon, (WCHAR*)L"Warning");
return 0;
DWORD dw = 0;
HDC hdcScreen = GetDC(NULL);
HICON hicon_app = 0;
if (hicon == 0)
{
hicon_app = getAppIcon(hwnd);
}
else {
hicon_app = hicon;
}
ICONINFO iconInfo_app;
result = GetIconInfo(hicon_app, &iconInfo_app);
BITMAP bmpIcon_app;
result = GetObjectW(iconInfo_app.hbmColor, sizeof(BITMAP), &bmpIcon_app);
if (bmpIcon_app.bmWidth % 8 || bmpIcon_app.bmHeight % 8 || bmpIcon_app.bmBitsPixel % 8)
{
return FALSE;
}
#define ICON_FILE
#ifdef ICON_FILE
HICON hicon_res = (HICON)LoadImageW(g_dllModule, (WCHAR*)IDI_ICON1, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
ICONINFO iconInfo_res;
result = GetIconInfo(hicon_res, &iconInfo_res);
HDC hdcResIcon = CreateCompatibleDC(hdcScreen);
SelectObject(hdcResIcon, iconInfo_res.hbmColor);
BITMAP bmp_res_icon;
GetObjectW(iconInfo_res.hbmColor, sizeof(BITMAP), &bmp_res_icon);
BITMAPINFO stback_icon_bmpinfo = { 0 };
BITMAPINFOHEADER* back_icon_bmpinfo = &stback_icon_bmpinfo.bmiHeader;
stback_icon_bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
stback_icon_bmpinfo.bmiHeader.biBitCount = bmp_res_icon.bmBitsPixel;
stback_icon_bmpinfo.bmiHeader.biPlanes = bmp_res_icon.bmPlanes;
stback_icon_bmpinfo.bmiHeader.biXPelsPerMeter = 0;
stback_icon_bmpinfo.bmiHeader.biYPelsPerMeter = 0;
stback_icon_bmpinfo.bmiHeader.biHeight = bmp_res_icon.bmHeight;
stback_icon_bmpinfo.bmiHeader.biWidth = bmp_res_icon.bmWidth;
stback_icon_bmpinfo.bmiHeader.biSizeImage = bmp_res_icon.bmHeight * bmp_res_icon.bmWidth * bmp_res_icon.bmBitsPixel / 8;
BYTE* back_icon_pixel = (BYTE*) new char[stback_icon_bmpinfo.bmiHeader.biSizeImage + 0x1000];
result = GetDIBits(hdcResIcon, iconInfo_res.hbmColor, 0, bmp_res_icon.bmHeight, back_icon_pixel, &stback_icon_bmpinfo, 0);
#else
if (back_icon_file_data == 0)
{
WCHAR filename[MAX_PATH];
GetModuleFileNameW(g_dllModule, filename, MAX_PATH);
WCHAR* ptr = wcsrchr(filename, L'\\');
if (ptr)
{
ptr[1] = 0;
lstrcatW(filename, L"boxed_icon16.ico");
}
HANDLE hf_icon_back = CreateFileW(filename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
if (hf_icon_back == INVALID_HANDLE_VALUE)
{
log(L"CreateFileW:%ws error", filename);
return FALSE;
}
int back_icon_filesize = GetFileSize(hf_icon_back, 0);
back_icon_file_data = new char[back_icon_filesize + 0x1000];
result = ReadFile(hf_icon_back, back_icon_file_data, back_icon_filesize, &dw, 0);
CloseHandle(hf_icon_back);
}
LPICONDIR back_icondir = (LPICONDIR)back_icon_file_data;
LPICONDIRENTRY back_icondir_entry = (LPICONDIRENTRY)back_icondir->idEntries;
BITMAPINFOHEADER* back_icon_bmpinfo = (BITMAPINFOHEADER*)(back_icon_file_data + sizeof(ICONDIR));
BYTE* back_icon_pixel = (BYTE*)back_icon_bmpinfo + sizeof(BITMAPINFOHEADER);
if (back_icondir_entry->bWidth % 8 || back_icondir_entry->bHeight % 8 || back_icondir_entry->wBitCount % 8)
{
return FALSE;
}
back_icon_bmpinfo->biHeight = back_icon_bmpinfo->biHeight / 2;
int icon_width = 0;
int icon_height = 0;
if (back_icon_bmpinfo->biWidth > bmpIcon_app.bmWidth)
{
icon_width = back_icon_bmpinfo->biWidth;
}
else {
icon_width = bmpIcon_app.bmWidth;
}
if (back_icon_bmpinfo->biHeight > bmpIcon_app.bmHeight)
{
icon_height = back_icon_bmpinfo->biHeight;
}
else {
icon_height = bmpIcon_app.bmHeight;
}
#endif
BITMAPINFO bmpinfo_addicon = { 0 };
bmpinfo_addicon.bmiHeader.biSize = back_icon_bmpinfo->biSize;
bmpinfo_addicon.bmiHeader.biBitCount = back_icon_bmpinfo->biBitCount;
bmpinfo_addicon.bmiHeader.biPlanes = back_icon_bmpinfo->biPlanes;
bmpinfo_addicon.bmiHeader.biXPelsPerMeter = back_icon_bmpinfo->biXPelsPerMeter;
bmpinfo_addicon.bmiHeader.biYPelsPerMeter = back_icon_bmpinfo->biYPelsPerMeter;
bmpinfo_addicon.bmiHeader.biHeight = back_icon_bmpinfo->biHeight;
bmpinfo_addicon.bmiHeader.biWidth = back_icon_bmpinfo->biWidth;
bmpinfo_addicon.bmiHeader.biSizeImage = back_icon_bmpinfo->biSizeImage;
if (0)
{
HDC hdcBackground = CreateCompatibleDC(hdcScreen);
BYTE* background_pixel_buffer = 0;
HBITMAP hbmp_Background = CreateDIBSection(hdcBackground, (BITMAPINFO*)&bmpinfo_addicon,
DIB_RGB_COLORS, (void**)&background_pixel_buffer, NULL, 0);
memset(background_pixel_buffer, 0xff,
bmpinfo_addicon.bmiHeader.biHeight * bmpinfo_addicon.bmiHeader.biWidth * bmpinfo_addicon.bmiHeader.biBitCount / 8);
copyScanline(background_pixel_buffer, back_icon_pixel, back_icon_bmpinfo->biWidth * back_icon_bmpinfo->biBitCount / 8,
bmpinfo_addicon.bmiHeader.biWidth * bmpinfo_addicon.bmiHeader.biBitCount / 8, back_icon_bmpinfo->biHeight);
SelectObject(hdcBackground, hbmp_Background);
DeleteDC(hdcBackground);
DeleteObject(hbmp_Background);
}
HDC hdc_tmp = CreateCompatibleDC(hdcScreen);
HBITMAP hbmp_tmp = iconInfo_app.hbmColor;
SelectObject(hdc_tmp, hbmp_tmp);
BITMAP bmp_tmp;
result = GetObjectW(hbmp_tmp, sizeof(BITMAP), &bmp_tmp);
BITMAPINFO bmpinfo_app = { 0 };
bmpinfo_app.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpinfo_app.bmiHeader.biBitCount = bmpIcon_app.bmBitsPixel;
bmpinfo_app.bmiHeader.biPlanes = bmpIcon_app.bmPlanes;
bmpinfo_app.bmiHeader.biXPelsPerMeter = 0;
bmpinfo_app.bmiHeader.biYPelsPerMeter = 0;
bmpinfo_app.bmiHeader.biHeight = bmpIcon_app.bmHeight;
bmpinfo_app.bmiHeader.biWidth = bmpIcon_app.bmWidth;
bmpinfo_app.bmiHeader.biSizeImage = bmpinfo_app.bmiHeader.biHeight * bmpinfo_app.bmiHeader.biWidth * bmpinfo_app.bmiHeader.biBitCount / 8;
BYTE* pixel_tmp_buf = (BYTE*)new char[bmpinfo_app.bmiHeader.biSizeImage + 0x1000];
result = GetDIBits(hdc_tmp, hbmp_tmp, 0, bmpIcon_app.bmHeight, pixel_tmp_buf, &bmpinfo_app, 0);
HDC hdcback_icon_mask = CreateCompatibleDC(hdcScreen);
SelectObject(hdcback_icon_mask, iconInfo_res.hbmMask);
BYTE* pixel_icon_res_mask = (BYTE*)new char[bmp_res_icon.bmWidth * bmp_res_icon.bmHeight * bmp_res_icon.bmBitsPixel / 8 + 0x1000];
result = GetDIBits(hdcback_icon_mask, iconInfo_res.hbmMask, 0, bmp_res_icon.bmHeight, pixel_icon_res_mask, &stback_icon_bmpinfo, 0);
if (bmpIcon_app.bmWidth < bmpinfo_addicon.bmiHeader.biWidth || bmpIcon_app.bmHeight < bmpinfo_addicon.bmiHeader.biHeight)
{
blendPixel(pixel_tmp_buf, pixel_icon_res_mask, back_icon_bmpinfo->biWidth * back_icon_bmpinfo->biBitCount / 8,
bmpinfo_app.bmiHeader.biWidth * bmpinfo_app.bmiHeader.biBitCount / 8, back_icon_bmpinfo->biHeight, PIXERL_BLEND_APP_ICON_WEIGH);
blendPixel(pixel_tmp_buf, back_icon_pixel, back_icon_bmpinfo->biWidth * back_icon_bmpinfo->biBitCount / 8,
bmpinfo_app.bmiHeader.biWidth * bmpinfo_app.bmiHeader.biBitCount / 8, back_icon_bmpinfo->biHeight, PIXERL_BLEND_APP_ICON_WEIGH);
}
else
{
blendPixel(pixel_tmp_buf, pixel_icon_res_mask, back_icon_bmpinfo->biWidth * back_icon_bmpinfo->biBitCount / 8,
bmpinfo_app.bmiHeader.biWidth * bmpinfo_app.bmiHeader.biBitCount / 8, back_icon_bmpinfo->biHeight, 0);
blendPixel(pixel_tmp_buf, back_icon_pixel, back_icon_bmpinfo->biWidth * back_icon_bmpinfo->biBitCount / 8,
bmpinfo_app.bmiHeader.biWidth * bmpinfo_app.bmiHeader.biBitCount / 8, back_icon_bmpinfo->biHeight, 0);
}
SetDIBits(hdc_tmp, hbmp_tmp, 0, bmpIcon_app.bmHeight, pixel_tmp_buf, &bmpinfo_app, 0);
HPEN hpen = CreatePen(PS_SOLID, 1, 0x00ff00);
HPEN hpenOld = (HPEN)SelectObject(hdc_tmp, hpen);
HBRUSH nullbrush = (HBRUSH)GetStockObject(NULL_BRUSH);
SelectObject(hdc_tmp, nullbrush);
SelectObject(hdc_tmp, hpenOld);
DeleteObject(hpen);
DeleteObject(nullbrush);
ICONINFO iconinfo_new = { 0 };
iconinfo_new.fIcon = TRUE;
iconinfo_new.hbmMask = iconInfo_app.hbmMask;
iconinfo_new.hbmColor = hbmp_tmp;
HICON hIconNew = CreateIconIndirect(&iconinfo_new);
result = SendMessageW(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconNew);
result = SendMessageW(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIconNew);
result = SendMessageW(hwnd, WM_SETICON, ICON_SMALL2, (LPARAM)hIconNew);
ReleaseDC(NULL, hdcScreen);
DeleteDC(hdc_tmp);
DeleteObject(hbmp_tmp);
DeleteObject(iconInfo_app.hbmColor);
DeleteObject(iconInfo_app.hbmMask);
DeleteDC(hdcResIcon);
DeleteDC(hdcback_icon_mask);
DeleteObject(hicon_res);
delete[]pixel_icon_res_mask;
delete[] pixel_tmp_buf;
delete[]back_icon_pixel;
DeleteObject(hIconNew);
return hIconNew;
}
#include
VOID setOverLay(HWND hWnd, HICON hIcon, const WCHAR* description)
{
ITaskbarList3* ptbl;
HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&ptbl));
if (SUCCEEDED(hr)) {
hr = ptbl->SetOverlayIcon(hWnd, hIcon, description);
}
else {
}
ptbl->Release();
}
VOID resetOverLay(HWND hWnd)
{
ITaskbarList3* ptbl;
HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&ptbl));
if (SUCCEEDED(hr)) {
hr = ptbl->SetOverlayIcon(hWnd, NULL, (const WCHAR*)L"");
}
else {
}
ptbl->Release();
}