summaryrefslogtreecommitdiff
path: root/plugins/Toaster/src/images.h
blob: cc22359bc953de4f74314639509d16efe3b51ce6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
extern wchar_t wszTempDir[];

class ToasterImage
{
	HBITMAP _hBitmap;
	ptrT tszId;

public:
	ToasterImage(HICON hIcon)
	{
		ICONINFO icon;
		if (GetIconInfo(hIcon, &icon))
		{
			_hBitmap = icon.hbmColor;
			DeleteObject(icon.hbmMask);
		}
		tszId = CMString(FORMAT, _T("%p"), hIcon).Detach();
	}

	inline ToasterImage(HBITMAP bmp) : _hBitmap(bmp)
	{ 
		tszId = CMString(FORMAT, _T("%p"), bmp).Detach(); 
	}

	ToasterImage(const char *szProto)
	{
		ICONINFO icon;
		if (GetIconInfo(Skin_LoadProtoIcon(szProto, ID_STATUS_ONLINE, 1), &icon))
		{
			_hBitmap = icon.hbmColor;
			DeleteObject(icon.hbmMask);
		}
		tszId = mir_a2t(szProto);
	}

	inline ~ToasterImage()
	{
		DeleteObject(_hBitmap);
	}

	wchar_t* Save()
	{
		wchar_t wszSavePath[MAX_PATH];
		mir_snwprintf(wszSavePath, L"%s\\MirandaToaster.%s.png", wszTempDir, tszId);

		if (!(GetFileAttributes(wszSavePath) < 0xFFFFFFF))
		{
			IMGSRVC_INFO isi = { sizeof(isi) };
			isi.wszName = mir_wstrdup(wszSavePath);
			isi.hbm = _hBitmap;
			isi.dwMask = IMGI_HBITMAP;
			isi.fif = FREE_IMAGE_FORMAT::FIF_PNG;
			CallService(MS_IMG_SAVE, (WPARAM)&isi, IMGL_WCHAR);
		}
		return mir_wstrdup(wszSavePath);
	}

	inline operator wchar_t*()
	{	return Save();
	}
};