加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mainform.cpp 5.25 KB
一键复制 编辑 原始数据 按行查看 历史
lgao622 提交于 2016-09-09 16:50 . rep 1.txt now
<<<<<<< HEAD
#include "mainform.h"
#include "ui_mainform.h"
#include <QListWidgetItem>
#include <QDebug>
#include <QPixmap>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMimeData>
#include <QUrl>
int idx = 0;
ICONDIR ico;
MainForm::MainForm(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainForm)
{
ui->setupUi(this);
memset(&ico, 0, sizeof(ICONDIR));
ico.idType = 1;
ico.idCount = 1;
ico.idEntries[0].wPlanes = 1;
ico.idEntries[0].dwImageOffset = 22;
setWindowTitle("");
setAcceptDrops(true);
}
MainForm::~MainForm()
{
delete ui;
}
void MainForm::on_lstIcon_itemSelectionChanged()
{
QListWidgetItem* item = ui->lstIcon->currentItem();
if (item) {
QIcon ico = item->icon();
ui->labIcon->setPixmap(ico.pixmap(ico.availableSizes().first().width()));
}
}
BOOL CALLBACK UpdateIcons(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG lParam)
{
Ui::MainForm *ui = (Ui::MainForm *)lParam;
HRSRC hRes = FindResource(hModule, lpszName, lpszType);
HGLOBAL hResLoaded = LoadResource(hModule, hRes);
void* pData = LockResource(hResLoaded);
int nSizeOfIconRes = SizeofResource(hModule,hRes);
qDebug() << "data:" << pData << ":" << nSizeOfIconRes;
QByteArray arr;
ico.idEntries[0].dwBytesInRes = nSizeOfIconRes*4;
ico.idEntries[0].bWidth = ico.idEntries[0].bHeight = (byte)((char*)pData)[4];
arr.clear();
arr.append((char*)&ico, 22);
arr.append((char*)pData, nSizeOfIconRes);
QPixmap p;
p.loadFromData(arr, "ico");
QString str = QString("%1 (%2x%2)").arg(++idx).arg(p.width());
QListWidgetItem* item = new QListWidgetItem(str);
item->setIcon(QIcon(p));
ui->lstIcon->addItem(item);
UnlockResource(hResLoaded);
FreeResource(hResLoaded);
return TRUE;
}
void MainForm::getIcons(const QString &appName)
{
idx = 0;
ui->lstIcon->clear();
HMODULE hModule = LoadLibraryExA( appName.toLocal8Bit().data(), NULL, LOAD_LIBRARY_AS_DATAFILE );//::LoadLibraryA(appName.toLocal8Bit().data());
qDebug() << "e:" << EnumResourceNames(hModule, RT_ICON, UpdateIcons, (long)this->ui);
::FreeLibrary(hModule);
}
void MainForm::dragEnterEvent(QDragEnterEvent *e)
{
if (e->mimeData()->urls().size() != 1)
return;
QString name = e->mimeData()->urls().first().toString();
if (name.endsWith(".exe", Qt::CaseInsensitive) || name.endsWith(".dll", Qt::CaseInsensitive))
e->acceptProposedAction();
}
void MainForm::dropEvent(QDropEvent *e)
{
QString name = e->mimeData()->urls().first().toString().remove("file:///");
setWindowTitle(name);
getIcons(name);
}
=======
#include "mainform.h"
#include "ui_mainform.h"
#include <QListWidgetItem>
#include <QDebug>
#include <QPixmap>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMimeData>
#include <QUrl>
int idx = 0;
ICONDIR ico;
MainForm::MainForm(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainForm)
{
ui->setupUi(this);
memset(&ico, 0, sizeof(ICONDIR));
ico.idType = 1;
ico.idCount = 1;
ico.idEntries[0].wPlanes = 1;
ico.idEntries[0].dwImageOffset = 22;
setWindowTitle("");
setAcceptDrops(true);
}
MainForm::~MainForm()
{
delete ui;
}
void MainForm::on_lstIcon_itemSelectionChanged()
{
QListWidgetItem* item = ui->lstIcon->currentItem();
if (item) {
QIcon ico = item->icon();
ui->labIcon->setPixmap(ico.pixmap(ico.availableSizes().first().width()));
}
}
BOOL CALLBACK UpdateIcons(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG lParam)
{
Ui::MainForm *ui = (Ui::MainForm *)lParam;
HRSRC hRes = FindResource(hModule, lpszName, lpszType);
HGLOBAL hResLoaded = LoadResource(hModule, hRes);
void* pData = LockResource(hResLoaded);
int nSizeOfIconRes = SizeofResource(hModule,hRes);
qDebug() << "data:" << pData << ":" << nSizeOfIconRes;
QByteArray arr;
ico.idEntries[0].dwBytesInRes = nSizeOfIconRes*4;
ico.idEntries[0].bWidth = ico.idEntries[0].bHeight = (byte)((char*)pData)[4];
arr.clear();
arr.append((char*)&ico, 22);
arr.append((char*)pData, nSizeOfIconRes);
QPixmap p;
p.loadFromData(arr, "ico");
QString str = QString("%1 (%2x%2)").arg(++idx).arg(p.width());
QListWidgetItem* item = new QListWidgetItem(str);
item->setIcon(QIcon(p));
ui->lstIcon->addItem(item);
UnlockResource(hResLoaded);
FreeResource(hResLoaded);
return TRUE;
}
void MainForm::getIcons(const QString &appName)
{
idx = 0;
ui->lstIcon->clear();
HMODULE hModule = LoadLibraryExA( appName.toLocal8Bit().data(), NULL, LOAD_LIBRARY_AS_DATAFILE );//::LoadLibraryA(appName.toLocal8Bit().data());
qDebug() << "e:" << EnumResourceNames(hModule, RT_ICON, UpdateIcons, (long)this->ui);
::FreeLibrary(hModule);
}
void MainForm::dragEnterEvent(QDragEnterEvent *e)
{
if (e->mimeData()->urls().size() != 1)
return;
QString name = e->mimeData()->urls().first().toString();
if (name.endsWith(".exe", Qt::CaseInsensitive) || name.endsWith(".dll", Qt::CaseInsensitive))
e->acceptProposedAction();
}
void MainForm::dropEvent(QDropEvent *e)
{
QString name = e->mimeData()->urls().first().toString().remove("file:///");
setWindowTitle(name);
getIcons(name);
}
>>>>>>> 3fab9eac9b2b32ef37fa477b4b150f71d4a4f234
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化