private Bitmap getIconBitmap(bool mask, bool returnHandle, ref IntPtr hBmp)
{
Bitmap bitmap = null;
BITMAPINFOHEADER structure = new BITMAPINFOHEADER(this.data);
if (mask)
{
IntPtr hdc = CreateCompatibleDC(IntPtr.Zero);
hBmp = CreateCompatibleBitmap(hdc, structure.biWidth, structure.biHeight / 2);
IntPtr hObject = SelectObject(hdc, hBmp);
RGBQUAD rgbquad = new RGBQUAD();
int cb = structure.biSize + (Marshal.SizeOf(rgbquad) * 2);
IntPtr ptr = Marshal.AllocCoTaskMem(cb);
Marshal.WriteInt32(ptr, Marshal.SizeOf(structure));
Marshal.WriteInt32(ptr, 4, structure.biWidth);
Marshal.WriteInt32(ptr, 8, structure.biHeight / 2);
Marshal.WriteInt16(ptr, 12, (short)1);
Marshal.WriteInt16(ptr, 14, (short)1);
Marshal.WriteInt32(ptr, 0x10, 0);
Marshal.WriteInt32(ptr, 20, 0);
Marshal.WriteInt32(ptr, 0x18, 0);
Marshal.WriteInt32(ptr, 0x1c, 0);
Marshal.WriteInt32(ptr, 0x20, 0);
Marshal.WriteInt32(ptr, 0x24, 0);
Marshal.WriteInt32(ptr, 40, 0);
Marshal.WriteByte(ptr, 0x2c, 0xff);
Marshal.WriteByte(ptr, 0x2d, 0xff);
Marshal.WriteByte(ptr, 0x2e, 0xff);
Marshal.WriteByte(ptr, 0x2f, 0);
int num2 = this.MaskImageSize(structure);
IntPtr destination = Marshal.AllocCoTaskMem(num2);
Marshal.Copy(this.data, this.MaskImageIndex(structure), destination, num2);
SetDIBitsToDevice(hdc, 0, 0, structure.biWidth, structure.biHeight / 2, 0, 0, 0, structure.biHeight / 2, destination, ptr, 0);
Marshal.FreeCoTaskMem(destination);
Marshal.FreeCoTaskMem(ptr);
SelectObject(hdc, hObject);
DeleteObject(hdc);
}
else
{
IntPtr ptr5 = CreateDC("DISPLAY", IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
IntPtr ptr6 = CreateCompatibleDC(ptr5);
hBmp = CreateCompatibleBitmap(ptr5, structure.biWidth, structure.biHeight / 2);
DeleteDC(ptr5);
IntPtr ptr7 = SelectObject(ptr6, hBmp);
int num3 = this.XorImageIndex(structure);
int num4 = this.XorImageSize(structure);
IntPtr ptr8 = Marshal.AllocCoTaskMem(num3);
Marshal.Copy(this.data, 0, ptr8, num3);
Marshal.WriteInt32(ptr8, 8, structure.biHeight / 2);
IntPtr ptr9 = Marshal.AllocCoTaskMem(num4);
Marshal.Copy(this.data, num3, ptr9, num4);
SetDIBitsToDevice(ptr6, 0, 0, structure.biWidth, structure.biHeight / 2, 0, 0, 0, structure.biHeight / 2, ptr9, ptr8, 0);
Marshal.FreeCoTaskMem(ptr9);
Marshal.FreeCoTaskMem(ptr8);
SelectObject(ptr6, ptr7);
DeleteObject(ptr6);
}
if (!returnHandle)
{
bitmap = Image.FromHbitmap(hBmp);
}
return bitmap;
}