Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
scrolling support for group icons
Browse files Browse the repository at this point in the history
  • Loading branch information
zodiacon committed May 10, 2022
1 parent 0c74338 commit 872828b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
44 changes: 27 additions & 17 deletions TotalPE/IconGroupView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ void CIconGroupView::SetGroupIconData(std::vector<uint8_t> const& data) {
};

struct IconHeader {
WORD Reserved;
WORD Type;
WORD Count;
IconDirectoryEntry Entries[1];
WORD Reserved;
WORD Type;
WORD Count;
IconDirectoryEntry Entries[1];
};
#pragma pack(pop)

Expand All @@ -34,29 +34,34 @@ void CIconGroupView::SetGroupIconData(std::vector<uint8_t> const& data) {
ResourceHelper rh(*pe);
icons = rh.GetFlatResources(L"Icon");
}
int y = 10;
for (int i = 0; i < header->Count; i++) {
auto const& entry = header->Entries[i];
auto id = std::format(L"#{}", entry.Id);
if (auto it = std::find_if(icons.begin(), icons.end(), [&](auto& e) { return e.Name == id; }); it != icons.end()) {
if (auto it = std::ranges::find_if(icons, [&](auto& e) { return e.Name == id; }); it != icons.end()) {
CIconHandle icon;
auto& idata = it->Entry->get_data();
icon.CreateIconFromResourceEx((PBYTE)idata.data(), (DWORD)idata.size(), 0x30000, entry.bWidth, entry.bHeight, LR_DEFAULTCOLOR);
if (icon)
m_Icons.emplace_back(icon, entry.bWidth);
auto width = entry.bWidth ? entry.bWidth : 256;
icon.CreateIconFromResourceEx(const_cast<PBYTE>(idata.data()),
(DWORD)idata.size(), 0x30000, width, width, LR_DEFAULTCOLOR);
if (icon) {
m_Icons.emplace_back(icon, width);
y += width + 12;
}
}

}
Invalidate();
SetScrollSize(450, y);
}

void CIconGroupView::SetIconData(std::vector<uint8_t> const& data, bool icon) {
m_IconSize = *(int*)(data.data() + sizeof(DWORD));
m_Icon.CreateIconFromResourceEx((PBYTE)data.data(), (DWORD)data.size(), 0x30000, m_IconSize, m_IconSize, LR_DEFAULTCOLOR);
Invalidate();
SetScrollSize(500, 300);
}

LRESULT CIconGroupView::OnCreate(UINT, WPARAM, LPARAM, BOOL&) {
return LRESULT();
LRESULT CIconGroupView::OnCreate(UINT, WPARAM, LPARAM, BOOL& handled) {
handled = FALSE;
return 0;
}

LRESULT CIconGroupView::OnDestroy(UINT, WPARAM, LPARAM, BOOL&) {
Expand All @@ -68,11 +73,17 @@ LRESULT CIconGroupView::OnDestroy(UINT, WPARAM, LPARAM, BOOL&) {
return 0;
}

LRESULT CIconGroupView::OnPaint(UINT, WPARAM, LPARAM, BOOL&) {
CPaintDC dc(m_hWnd);
LRESULT CIconGroupView::OnEraseBkgnd(UINT, WPARAM wp, LPARAM, BOOL&) {
//CDCHandle dc((HDC)wp);
//dc.FillSolidRect(0, 0, 1000, 1000, 255);
return 0;
}

void CIconGroupView::DoPaint(CDCHandle dc) {
CFont font;
font.CreatePointFont(110, L"Consolas");
dc.SelectFont(font);
dc.SetBkMode(TRANSPARENT);
if (m_Icon) {
dc.TextOutW(10, 10, std::format(L"{} X {}", m_IconSize, m_IconSize).c_str());
dc.DrawIconEx(10, 50, m_Icon, m_IconSize, m_IconSize, 0, nullptr, DI_NORMAL);
Expand All @@ -82,9 +93,8 @@ LRESULT CIconGroupView::OnPaint(UINT, WPARAM, LPARAM, BOOL&) {
for (auto& [icon, size] : m_Icons) {
CRect rc(10, y, 90, y + size);
dc.DrawText(std::format(L"{} X {}", size, size).c_str(), -1, &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
dc.DrawIconEx(100, y, icon, size, size, 0, nullptr, DI_NORMAL);
icon.DrawIconEx(dc, 100, y, size, size, 0, nullptr, DI_NORMAL);
y += size + 12;
}
}
return 0;
}
10 changes: 7 additions & 3 deletions TotalPE/IconGroupView.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@

#include "View.h"

class CIconGroupView : public CView<CIconGroupView> {
class CIconGroupView :
public CView<CIconGroupView>,
public CScrollImpl<CIconGroupView> {
public:
using CView::CView;

void SetGroupIconData(std::vector<uint8_t> const& data);
void SetIconData(std::vector<uint8_t> const& data, bool icon);
void DoPaint(CDCHandle);

BEGIN_MSG_MAP(CIconGroupView)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
CHAIN_MSG_MAP(CScrollImpl<CIconGroupView>)
CHAIN_MSG_MAP(CView)
END_MSG_MAP()

private:
LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnEraseBkgnd(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);

CIconHandle m_Icon;
int m_IconSize;
Expand Down
4 changes: 2 additions & 2 deletions TotalPE/ResourceHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ResourceHelper::ResourceHelper(pe_image_full const& pe) : m_pe(pe) {

std::vector<ResourceItem> ResourceHelper::GetFlatResources(PCWSTR type) const {
pe_resource_directory_entry const* theDir{ nullptr };
for (auto& dir : m_pe.get_resources().get_entry_list()) {
for (auto const& dir : m_pe.get_resources().get_entry_list()) {
auto name = PEStrings::ResourceTypeToString(dir.get_id());
if (name == type) {
theDir = &dir;
Expand All @@ -19,7 +19,7 @@ std::vector<ResourceItem> ResourceHelper::GetFlatResources(PCWSTR type) const {

std::vector<ResourceItem> items;
items.reserve(8);
for (auto& dir : theDir->get_resource_directory().get_entry_list()) {
for (auto const& dir : theDir->get_resource_directory().get_entry_list()) {
auto name = dir.is_named() ? dir.get_name() : std::format(L"#{}", dir.get_id());
for (auto& item : dir.get_resource_directory().get_entry_list()) {
items.emplace_back(name, &item.get_data_entry());
Expand Down
1 change: 1 addition & 0 deletions TotalPE/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern CAppModule _Module;
#include <cor.h>
#include <format>
#include <map>
#include <atlscrl.h>

#include "..\enma_pe\enma_pe.h"

Expand Down

0 comments on commit 872828b

Please sign in to comment.