process icon

Update LunaHost.cpp
This commit is contained in:
恍兮惚兮 2024-02-11 23:49:11 +08:00
parent dee56c4dba
commit c306ac0280
9 changed files with 155 additions and 32 deletions

View File

@ -57,7 +57,7 @@
#define MenuRemovePlugin L"移除插件"
#define MenuPluginRankUp L"上移"
#define MenuPluginRankDown L"下移"
#define DefaultFont L""
#define DefaultFont L"微软雅黑"
#define InVaildPlugin L"无效的插件"
#define CantLoadQtLoader L"无法加载QtLoader.dll"
#define LblPluginNotify L"依赖于Qt的插件仅会在启动时载入。"

View File

@ -1,5 +1,5 @@
add_executable(LunaHost WIN32 confighelper.cpp controls.cpp main.cpp processlistwindow.cpp LunaHost.cpp window.cpp luna.rc pluginmanager.cpp Plugin/pluginexample.cpp app.manifest)
target_precompile_headers(LunaHost REUSE_FROM pch)
set_target_properties(LunaHost PROPERTIES OUTPUT_NAME "LunaHost${bitappendix}")
target_link_libraries(LunaHost pch host ${YY_Thunks_for_WinXP})
target_link_libraries(LunaHost comctl32 pch host ${YY_Thunks_for_WinXP})
add_subdirectory(Plugin)

View File

@ -33,18 +33,21 @@ void LunaHost::on_close(){
Sleep(100);
}
void LunaHost::on_size(int w,int h){
int height = h-140;
int height = h-110;
w-=20;
g_selectprocessbutton->setgeo(10,10,w/3,40);
btnshowsettionwindow->setgeo(10+w/3,10,w/3,40);
btnplugin->setgeo(10+w*2/3,10,w/3,40);
g_hListBox_listtext->setgeo(10, 110, w , height/2);
g_showtexts->setgeo(10, 120+height/2, w , height/2);
g_hEdit_userhook->setgeo(10,60,w*2/3,40);
g_hButton_insert->setgeo(10+w*2/3,60,w/3,40);
auto _w=w-20;
g_selectprocessbutton->setgeo(10,10,_w/3,30);
btnshowsettionwindow->setgeo(10+10+_w/3,10,_w/3,30);
btnplugin->setgeo(10+20+_w*2/3,10,_w/3,30);
g_hListBox_listtext->setgeo(10, 90, w , height/2);
g_showtexts->setgeo(10, 100+height/2, w , height/2);
g_hEdit_userhook->setgeo(10,50,_w*2/3+10,30);
g_hButton_insert->setgeo(10+20+_w*2/3,50,_w/3,30);
}
LunaHost::LunaHost(){
setfont(25);
configs=new confighelper;
settext(WndLunaHostGui);
btnshowsettionwindow=new button(this, BtnShowSettingWindow,100,100,100,100);
@ -138,7 +141,6 @@ LunaHost::LunaHost(){
std::bind(&LunaHost::on_text_recv,this,std::placeholders::_1,std::placeholders::_2)
);
setfont(25);
setcentral(1000,600);
}
@ -181,9 +183,9 @@ void LunaHost::on_thread_delete(TextThread& thread){
}
Settingwindow::Settingwindow(LunaHost* host):mainwindow(host){
new label(this,LblFlushDelay,10, 10, 150, 40);
new label(this,LblCodePage,10, 60, 150, 40);
ckbfilterrepeat=new checkbox(this,LblFilterRepeat,10, 160, 200, 40);
new label(this,LblFlushDelay,10, 10, 150, 30);
new label(this,LblCodePage,10, 50, 150, 30);
ckbfilterrepeat=new checkbox(this,LblFilterRepeat,10, 130, 200, 30);
ckbfilterrepeat->onclick=[=](){
auto ck=ckbfilterrepeat->ischecked();
TextThread::filterRepetition=ck;
@ -191,7 +193,7 @@ Settingwindow::Settingwindow(LunaHost* host):mainwindow(host){
};
ckbfilterrepeat->setcheck(host->configs->get("filterrepeat",false));
g_check_clipboard =new checkbox(this,BtnToClipboard,10, 110, 200, 40) ;
g_check_clipboard =new checkbox(this,BtnToClipboard,10, 90, 200, 30) ;
g_check_clipboard->onclick=[=](){
auto ck=g_check_clipboard->ischecked();
((LunaHost*)parent)->check_toclipboard=ck;
@ -199,8 +201,8 @@ Settingwindow::Settingwindow(LunaHost* host):mainwindow(host){
};
g_check_clipboard->setcheck(host->configs->get("ToClipboard",false));
g_timeout = new spinbox(this,std::to_wstring(host->configs->get("flushDelay",TextThread::flushDelay)).c_str(),160, 10, 100, 40) ;
g_codepage = new spinbox(this,std::to_wstring(host->configs->get("codepage",Host::defaultCodepage)).c_str(),160, 60, 100, 40) ;
g_timeout = new spinbox(this,std::to_wstring(host->configs->get("flushDelay",TextThread::flushDelay)).c_str(),150, 10, 100, 30) ;
g_codepage = new spinbox(this,std::to_wstring(host->configs->get("codepage",Host::defaultCodepage)).c_str(),150, 50, 100, 30) ;
g_timeout->onvaluechange=[=](int v){
TextThread::flushDelay=v;
host->configs->set("flushDelay",v);
@ -213,11 +215,11 @@ Settingwindow::Settingwindow(LunaHost* host):mainwindow(host){
}
};
g_codepage->setminmax(0,CP_UTF8);
setcentral(300,300);
setcentral(300,240);
settext(WndSetting);
}
void Pluginwindow::on_size(int w,int h){
listplugins->setgeo(10,80,w-20,h-100);
listplugins->setgeo(10,80,w-20,h-90);
}
Pluginwindow::Pluginwindow(mainwindow*p,Pluginmanager* pl):mainwindow(p){
pluginmanager=pl;

View File

@ -1,13 +1,13 @@
#include"controls.h"
#include"window.h"
#include <CommCtrl.h>
control::control(mainwindow*_parent){
parent=_parent;
parent->controls.push_back(this);
}
void control::dispatch(WPARAM){}
void control::dispatch_2(WPARAM wParam, LPARAM lParam){};
button::button(mainwindow* parent,LPCWSTR text,int x,int y,int w,int h,DWORD style):control(parent){
winId=CreateWindowEx(0, L"BUTTON", text, WS_CHILD | WS_VISIBLE |style ,
x, y, w, h, parent->winId , NULL, NULL, NULL);
@ -138,4 +138,75 @@ int listbox::count(){
}
int listbox::insertitem(int i,LPCWSTR t){
return SendMessage(winId, LB_INSERTSTRING, i, (LPARAM)t);
}
listview::listview(mainwindow* parent,int x,int y,int w,int h):control(parent){
winId=CreateWindowEx(0, WC_LISTVIEW, NULL, WS_VISIBLE |WS_VSCROLL| WS_CHILD | LVS_REPORT |LVS_SINGLESEL, x, y, w, h, parent->winId, NULL,NULL, NULL);
ListView_SetExtendedListViewStyle(winId, LVS_EX_FULLROWSELECT); // Set extended styles
setfont(22);
hImageList = ImageList_Create(22,22, //GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
ILC_COLOR32, 1 ,1);
ListView_SetImageList(winId, hImageList, LVSIL_SMALL);
}
int listview::insertcol(int i,const std::wstring& text){
LVCOLUMN lvc;
lvc.mask = LVCF_TEXT;
lvc.pszText = const_cast<LPWSTR>(text.c_str());
//lvc.cx = 100;
return ListView_InsertColumn(winId, i, &lvc);
}
int listview::insertitem(int row,const std::wstring& text,HICON hicon){
LVITEM lvi;
lvi.mask = LVIF_TEXT | LVIF_IMAGE;
lvi.pszText = const_cast<LPWSTR>(text.c_str());
lvi.iItem = row;
lvi.iSubItem = 0;
lvi.iImage = ImageList_AddIcon(hImageList, hicon);
return ListView_InsertItem(winId, &lvi);
}
int listview::additem(const std::wstring& text,HICON hicon){
return insertitem(count(),text,hicon);
}
void listview::clear(){
ListView_DeleteAllItems(winId);
}
int listview::count(){
return ListView_GetItemCount(winId);
}
void listview::dispatch_2(WPARAM wParam, LPARAM lParam){
NMHDR* pnmhdr = (NMHDR*)lParam;
switch (pnmhdr->code){
case LVN_ITEMCHANGED:
{
NMLISTVIEW* pnmListView = (NMLISTVIEW*)lParam;
if ((pnmListView->uChanged & LVIF_STATE) && (pnmListView->uNewState & LVIS_SELECTED))
{
oncurrentchange(pnmListView->iItem);
}
break;
}
}
}
std::wstring listview::text(int row,int col){
std::wstring text;text.resize(65535);
LV_ITEM _macro_lvi;
_macro_lvi.iSubItem = (col);
_macro_lvi.cchTextMax = (65535);
_macro_lvi.pszText = (text.data());
SNDMSG((winId), LVM_GETITEMTEXT, (WPARAM)(row), (LPARAM)(LV_ITEM *)&_macro_lvi);
return text.c_str();
}
void listview::setheader(const std::vector<std::wstring>& headers){
for(int i=0;i<headers.size();i++){
insertcol(i,headers[i]);
ListView_SetColumnWidth(winId, i, LVSCW_AUTOSIZE_USEHEADER);
}
headernum=headers.size();
}
void listview::autosize(){
for(int i=0;i<headernum;i++){
ListView_SetColumnWidth(winId, i, LVSCW_AUTOSIZE_USEHEADER);
}
}

View File

@ -1,12 +1,13 @@
#ifndef LUNA_BASE_CONTROLS_H
#define LUNA_BASE_CONTROLS_H
#include"window.h"
#include <CommCtrl.h>
class control:public basewindow{
public:
mainwindow* parent;
control(mainwindow*);
virtual void dispatch(WPARAM);
virtual void dispatch_2(WPARAM wParam, LPARAM lParam);
std::function<HMENU()>oncontextmenu=[](){return (HMENU)nullptr;};
std::function<void(WPARAM)>oncontextmenucallback=[](WPARAM){};
};
@ -62,4 +63,20 @@ public:
LONG_PTR getdata(int);
int count();
};
class listview:public control{
int headernum=1;
HIMAGELIST hImageList;
public:
listview(mainwindow*,int,int,int,int);
int insertitem(int,const std::wstring&,HICON hicon);
int insertcol(int,const std::wstring& );
void clear();
int count();
std::function<void(int)> oncurrentchange=[](int){};
std::wstring text(int,int=0);
void setheader(const std::vector<std::wstring>&);
void autosize();
int additem(const std::wstring&,HICON hicon);
void listview::dispatch_2(WPARAM wParam, LPARAM lParam);
};
#endif

View File

@ -4,6 +4,7 @@
#include"host.h"
#include"processlistwindow.h"
#include"Lang/Lang.h"
#include<shellapi.h>
std::unordered_map<std::wstring,std::vector<int>> getprocesslist()
{
std::unordered_map<std::wstring,std::vector<int>>exe_pid;
@ -42,17 +43,20 @@ std::unordered_map<std::wstring,std::vector<int>> getprocesslist()
}
return exe_pid;
}
void processlistwindow::PopulateProcessList(listbox* _listbox,std::unordered_map<std::wstring,std::vector<int>>&exe_pid){
void processlistwindow::PopulateProcessList(listview* _listbox,std::unordered_map<std::wstring,std::vector<int>>&exe_pid){
_listbox->clear();
for(auto& exe:exe_pid){
_listbox->additem(exe.first.c_str());
auto hicon=GetExeIcon(exe.first.c_str());
_listbox->additem(exe.first.c_str(),hicon);
DestroyIcon(hicon);
}
}
processlistwindow::processlistwindow(mainwindow* p):mainwindow(p){
g_hEdit = new textedit(this,L"",10, 10, 400, 40,ES_AUTOHSCROLL);
g_hButton=new button(this,BtnAttach,420, 10, 100, 40);
g_refreshbutton =new button(this,BtnRefresh,530, 10, 100, 40);
g_hEdit = new textedit(this,L"",10, 10, 400, 30,ES_AUTOHSCROLL);
g_hButton=new button(this,BtnAttach,420, 10, 100, 30);
g_refreshbutton =new button(this,BtnRefresh,530, 10, 100, 30);
g_hButton->onclick=[&](){
auto str=g_hEdit->text();
if(str.size()){
@ -72,7 +76,8 @@ processlistwindow::processlistwindow(mainwindow* p):mainwindow(p){
g_exe_pid=getprocesslist();
PopulateProcessList(g_hListBox,g_exe_pid);
};
g_hListBox = new listbox(this,10, 60, 310, 200);
g_hListBox = new listview(this,10, 60, 310, 200);
g_hListBox->setheader({L""});
g_hListBox->oncurrentchange=[&](int idx){
auto pids=g_exe_pid[g_hListBox->text(idx)];
@ -94,5 +99,11 @@ void processlistwindow::on_show(){
PopulateProcessList(g_hListBox,g_exe_pid);
}
void processlistwindow::on_size(int w,int h){
g_hListBox->setgeo(10,60,w-20,h-70);
w=w-20;
auto _w=w-20;
g_hEdit->setgeo(10,10,_w/2,30);
g_hButton->setgeo(10+_w/2+10,10,_w/4,30);
g_refreshbutton->setgeo(10+_w/2+_w/4+20,10,_w/4,30);
g_hListBox->setgeo(10,50,w,h-60);
g_hListBox->autosize();
}

View File

@ -5,10 +5,10 @@
class processlistwindow:public mainwindow{
textedit* g_hEdit;
button* g_hButton;
listbox* g_hListBox;
listview* g_hListBox;
button* g_refreshbutton;
std::unordered_map<std::wstring,std::vector<int>> g_exe_pid;
void PopulateProcessList(listbox*,std::unordered_map<std::wstring,std::vector<int>>&);
void PopulateProcessList(listview*,std::unordered_map<std::wstring,std::vector<int>>&);
public:
processlistwindow(mainwindow* parent=0);
void on_size(int w,int h);

View File

@ -1,6 +1,15 @@
#include"window.h"
#include"controls.h"
#include"Lang/Lang.h"
#include<shellapi.h>
HICON GetExeIcon(const wchar_t* filePath) {
SHFILEINFO fileInfo;
HICON hIcon = NULL;
if (SHGetFileInfo(filePath, 0, &fileInfo, sizeof(fileInfo), SHGFI_ICON | SHGFI_LARGEICON)) {
hIcon = fileInfo.hIcon;
}
return hIcon;
}
void basewindow::setfont(int sz,LPCWSTR fn){
if(fn==0)fn=DefaultFont;
hfont=CreateFont(sz, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
@ -51,6 +60,17 @@ LRESULT mainwindow::wndproc(UINT message, WPARAM wParam, LPARAM lParam){
on_size(width,height);
break;
}
case WM_NOTIFY:
{
NMHDR* pnmhdr = (NMHDR*)lParam;
for(auto ctl:controls)
{
if(pnmhdr->hwndFrom==ctl->winId)
{
ctl->dispatch_2(wParam,lParam);break;
}
}
}
case WM_COMMAND:
{
if(lParam==0){
@ -133,7 +153,8 @@ mainwindow::mainwindow(mainwindow* _parent){
wc.hInstance = GetModuleHandle(0);
wc.lpszClassName = CLASS_NAME;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW );
wc.hIcon=LoadIconW(GetModuleHandle(0),L"IDI_ICON1");
wc.hIcon= GetExeIcon(GetModuleFilename().value().c_str());//LoadIconW(GetModuleHandle(0),L"IDI_ICON1");
static auto _=RegisterClass(&wc);
HWND hWnd = CreateWindowEx(
WS_EX_CLIENTEDGE,CLASS_NAME,CLASS_NAME,WS_OVERLAPPEDWINDOW,

View File

@ -28,4 +28,5 @@ public:
void setcentral(int,int);
std::pair<int,int>calculateXY(int w,int h);
};
HICON GetExeIcon(const wchar_t* filePath);
#endif