Created
July 17, 2022 06:26
-
-
Save Far-Se/ce587fe1cfba91a41a9ef873e7fd98fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
else if (method_name.compare("iconToBytes") == 0) | |
{ | |
const flutter::EncodableMap &args = std::get<flutter::EncodableMap>(*method_call.arguments()); | |
std::string iconLocation = std::get<std::string>(args.at(flutter::EncodableValue("iconLocation"))); | |
int iconID = std::get<int>(args.at(flutter::EncodableValue("iconID"))); | |
std::wstring iconLocationW = Encoding::Utf8ToWide(iconLocation); | |
HICON icon = getIconFromFile((LPWSTR)iconLocationW.c_str(), iconID); | |
std::vector<CHAR> buff; | |
bool resultIcon = GetIconData(icon, 32, buff); | |
if (!resultIcon) | |
{ | |
buff.clear(); | |
resultIcon = GetIconData(icon, 24, buff); | |
} | |
std::vector<uint8_t> buff_uint8; | |
for (auto i : buff) | |
{ | |
buff_uint8.push_back(i); | |
} | |
result->Success(flutter::EncodableValue(buff_uint8)); | |
} | |
else if (method_name.compare("getWindowIcon") == 0) | |
{ | |
const flutter::EncodableMap &args = std::get<flutter::EncodableMap>(*method_call.arguments()); | |
int hWND = std::get<int>(args.at(flutter::EncodableValue("hWnd"))); | |
LRESULT iconResult = SendMessage((HWND)((LONG_PTR)hWND), WM_GETICON, 2, 0); // ICON_SMALL2 - User Made Apps | |
if (iconResult == 0) | |
iconResult = GetClassLongPtr((HWND)((LONG_PTR)hWND), -14); // GCLP_HICON - Microsoft Win Apps | |
if (iconResult != 0) | |
{ | |
HICON icon = (HICON)iconResult; | |
std::vector<CHAR> buff; | |
bool resultIcon = GetIconData(icon, 32, buff); | |
if (!resultIcon) | |
{ | |
buff.clear(); | |
resultIcon = GetIconData(icon, 24, buff); | |
} | |
if (resultIcon) | |
{ | |
std::vector<uint8_t> buff_uint8; | |
for (auto i : buff) | |
{ | |
buff_uint8.push_back(i); | |
} | |
result->Success(flutter::EncodableValue(buff_uint8)); | |
} | |
else | |
{ | |
std::vector<uint8_t> iconBytes; | |
iconBytes.push_back(204); | |
iconBytes.push_back(204); | |
iconBytes.push_back(204); | |
result->Success(flutter::EncodableValue(iconBytes)); | |
} | |
} | |
else | |
{ | |
std::vector<uint8_t> iconBytes; | |
iconBytes.push_back(204); | |
iconBytes.push_back(204); | |
iconBytes.push_back(204); | |
result->Success(flutter::EncodableValue(iconBytes)); | |
} | |
} | |
else if (method_name.compare("getIconPng") == 0) | |
{ | |
const flutter::EncodableMap &args = std::get<flutter::EncodableMap>(*method_call.arguments()); | |
int hIcon = std::get<int>(args.at(flutter::EncodableValue("hIcon"))); | |
std::vector<CHAR> buff; | |
bool resultIcon = GetIconData((HICON)((LONG_PTR)hIcon), 32, buff); | |
if (!resultIcon) | |
{ | |
buff.clear(); | |
resultIcon = GetIconData((HICON)((LONG_PTR)hIcon), 24, buff); | |
} | |
if (resultIcon) | |
{ | |
std::vector<uint8_t> buff_uint8; | |
for (auto i : buff) | |
{ | |
buff_uint8.push_back(i); | |
} | |
result->Success(flutter::EncodableValue(buff_uint8)); | |
} | |
else | |
{ | |
std::vector<uint8_t> iconBytes; | |
iconBytes.push_back(204); | |
iconBytes.push_back(204); | |
iconBytes.push_back(204); | |
result->Success(flutter::EncodableValue(iconBytes)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map<String, Uint8List> ___kCacheIcons = <String, Uint8List>{}; | |
Future<Uint8List?> nativeIconToBytes(String iconLocation, {int iconID = 0}) async { | |
if (___kCacheIcons.containsKey(iconLocation) && iconID == 0) return ___kCacheIcons[iconLocation]; | |
final Map<String, dynamic> arguments = <String, dynamic>{'iconLocation': iconLocation, 'iconID': iconID}; | |
final Uint8List? result = await _methodChannel.invokeMethod<Uint8List>('iconToBytes', arguments); | |
___kCacheIcons[iconLocation] = result!; | |
return result; | |
} | |
Future<Uint8List?> getExecutableIcon(String iconlocation, {int iconID = 0}) async { | |
return nativeIconToBytes(iconlocation, iconID: iconID); | |
} | |
Future<Uint8List?> getWindowIcon(int hWnd) async { | |
final Map<String, dynamic> arguments = <String, dynamic>{'hWnd': hWnd}; | |
final Uint8List? result = await _methodChannel.invokeMethod<Uint8List>('getWindowIcon', arguments); | |
return result; | |
} | |
Future<Uint8List?> getIconPng(int hIcon) async { | |
final Map<String, dynamic> arguments = <String, dynamic>{'hIcon': hIcon}; | |
final Uint8List? result = await _methodChannel.invokeMethod<Uint8List>('getIconPng', arguments); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment