/*static*/ HICON Win32UIBinding::LoadImageAsIcon(std::string& path, int sizeX, int sizeY) { std::string ext = path.substr(path.size() - 4, 4); UINT flags = LR_DEFAULTSIZE | LR_LOADFROMFILE | LR_LOADTRANSPARENT | LR_CREATEDIBSECTION; std::wstring widePath(::UTF8ToWide(path)); HICON h = 0; if (_stricmp(ext.c_str(), ".ico") == 0) { h = (HICON) LoadImageW(NULL, widePath.c_str(), IMAGE_ICON, sizeX, sizeY, LR_LOADFROMFILE); } else if (_stricmp(ext.c_str(), ".bmp") == 0) { HBITMAP bitmap = (HBITMAP) LoadImageW( NULL, widePath.c_str(), IMAGE_BITMAP, sizeX, sizeY, flags); h = Win32UIBinding::BitmapToIcon(bitmap, sizeX, sizeY); DeleteObject(bitmap); } else if (_stricmp(ext.c_str(), ".png") == 0) { HBITMAP bitmap = LoadPNGAsBitmap(path, sizeX, sizeY); h = Win32UIBinding::BitmapToIcon(bitmap, sizeX, sizeY); DeleteObject(bitmap); } loadedICOs.push_back(h); return (HICON) h; }
/*static*/ HICON UIWin::LoadImageAsIcon(std::string& path, int sizeX, int sizeY) { UINT flags = LR_DEFAULTSIZE | LR_LOADFROMFILE | LR_LOADTRANSPARENT | LR_CREATEDIBSECTION; const char* ext = path.c_str() + path.size() - 4; std::wstring widePath(::UTF8ToWide(path)); HICON h = 0; if (_stricmp(ext, ".ico") == 0) { h = (HICON) LoadImageW(0, widePath.c_str(), IMAGE_ICON, sizeX, sizeY, LR_LOADFROMFILE); } else if (_stricmp(ext, ".bmp") == 0) { HBITMAP bitmap = (HBITMAP) LoadImageW(0, widePath.c_str(), IMAGE_BITMAP, sizeX, sizeY, flags); h = UIWin::BitmapToIcon(bitmap, sizeX, sizeY); DeleteObject(bitmap); } else if (_stricmp(ext, ".png") == 0) { HBITMAP bitmap = LoadPNGAsBitmap(path, sizeX, sizeY); h = UIWin::BitmapToIcon(bitmap, sizeX, sizeY); DeleteObject(bitmap); } else { throw ValueException::FromFormat("Unsupported image file: %s", path); } loadedICOs.push_back(h); return (HICON) h; }
/*static*/ HBITMAP Win32UIBinding::LoadImageAsBitmap(std::string& path, int sizeX, int sizeY) { std::string ext = path.substr(path.size() - 4, 4); UINT flags = LR_DEFAULTSIZE | LR_LOADFROMFILE | LR_LOADTRANSPARENT | LR_CREATEDIBSECTION; std::wstring widePath(::UTF8ToWide(path)); HBITMAP h = 0; if (_stricmp(ext.c_str(), ".ico") == 0) { HICON hicon = (HICON) LoadImageW(NULL, widePath.c_str(), IMAGE_ICON, sizeX, sizeY, LR_LOADFROMFILE); h = Win32UIBinding::IconToBitmap(hicon, sizeX, sizeY); DestroyIcon(hicon); } else if (_stricmp(ext.c_str(), ".bmp") == 0) { h = (HBITMAP) LoadImageW( NULL, widePath.c_str(), IMAGE_BITMAP, sizeX, sizeY, flags); } else if (_stricmp(ext.c_str(), ".png") == 0) { h = LoadPNGAsBitmap(path, sizeX, sizeY); } loadedBMPs.push_back(h); return h; }
/*static*/ HBITMAP UIWin::LoadImageAsBitmap(std::string& path, int sizeX, int sizeY) { UINT flags = LR_DEFAULTSIZE | LR_LOADFROMFILE | LR_LOADTRANSPARENT | LR_CREATEDIBSECTION; std::wstring widePath(::UTF8ToWide(path)); const char* ext = path.c_str() + path.size() - 4; HBITMAP h = 0; if (_stricmp(ext, ".ico") == 0) { HICON hicon = (HICON) LoadImageW(NULL, widePath.c_str(), IMAGE_ICON, sizeX, sizeY, LR_LOADFROMFILE); h = UIWin::IconToBitmap(hicon, sizeX, sizeY); DestroyIcon(hicon); } else if (_stricmp(ext, ".bmp") == 0) { h = (HBITMAP) LoadImageW( NULL, widePath.c_str(), IMAGE_BITMAP, sizeX, sizeY, flags); } else if (_stricmp(ext, ".png") == 0) { h = LoadPNGAsBitmap(path, sizeX, sizeY); } else { throw ValueException::FromFormat("Unsupported image file: %s", path); } loadedBMPs.push_back(h); return h; }