void windowsIcon(iw_context* context, const char* filename) { //16x16 //32x32 //48x48 //256x256 ByteStream stream; writeIcoHeader(stream); writeIconDirEntry(stream, 16, 16, iconHeaderSize + iconDirEntrySize * 4); writeIconDirEntry(stream, 32, 32, iconHeaderSize + iconDirEntrySize * 4 + getBMPSize(16, 16)); writeIconDirEntry(stream, 48, 48, iconHeaderSize + iconDirEntrySize * 4 + getBMPSize(16, 16) + getBMPSize(32, 32)); writeIconDirEntry(stream, 256, 256, iconHeaderSize + iconDirEntrySize * 4 + getBMPSize(16, 16) + getBMPSize(32, 32) + getBMPSize(48, 48)); scale(context, 16, 16); iw_image img; iw_get_output_image(context, &img); writeBMP(stream, &img); scale(context, 32, 32); iw_get_output_image(context, &img); writeBMP(stream, &img); scale(context, 48, 48); iw_get_output_image(context, &img); writeBMP(stream, &img); scale(context, 256, 256); iw_get_output_image(context, &img); iw_iodescr writedescr; memset(&writedescr, 0, sizeof(struct iw_iodescr)); writedescr.write_fn = stream_writefn; writedescr.seek_fn = stream_seekfn; writedescr.fp = &stream; iw_write_file_by_fmt(context, &writedescr, IW_FORMAT_PNG); std::vector<byte> pngSize = convertIntToByteArrayLE(static_cast<int>(stream.size()) - (iconHeaderSize + iconDirEntrySize * 4 + getBMPSize(16, 16) + getBMPSize(32, 32) + getBMPSize(48, 48))); for (int i = 0; i < 4; ++i) stream.set(i + iconHeaderSize + iconDirEntrySize * 3 + 8, pngSize[i]); stream.save(filename); }
// setClipboardDIB(bmp) static void setClipboardDIB(BITMAPINFO* src) { size_t nbytes = getBMPSize(src); HANDLE data = GlobalAlloc(GHND, nbytes); if (data != NULL) { LPVOID dst = GlobalLock(data); if (dst != NULL) { CopyMemory(dst, src, nbytes); GlobalUnlock(data); SetClipboardData(CF_DIB, data); data = NULL; } if (data != NULL) { GlobalFree(data); } } }