This commit is contained in:
恍兮惚兮 2024-02-12 00:17:58 +08:00
parent 657e014135
commit f35ea99f3c
6 changed files with 31 additions and 31 deletions

View File

@ -201,8 +201,8 @@ Settingwindow::Settingwindow(LunaHost* host):mainwindow(host){
}; };
g_check_clipboard->setcheck(host->configs->get("ToClipboard",false)); 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(),150, 10, 100, 30) ; g_timeout = new spinbox(this,std::to_wstring(host->configs->get("flushDelay",TextThread::flushDelay)),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_codepage = new spinbox(this,std::to_wstring(host->configs->get("codepage",Host::defaultCodepage)),150, 50, 100, 30) ;
g_timeout->onvaluechange=[=](int v){ g_timeout->onvaluechange=[=](int v){
TextThread::flushDelay=v; TextThread::flushDelay=v;
host->configs->set("flushDelay",v); host->configs->set("flushDelay",v);
@ -226,7 +226,7 @@ Pluginwindow::Pluginwindow(mainwindow*p,Pluginmanager* pl):mainwindow(p){
new label(this,LblPluginNotify, 10,10,500,30); new label(this,LblPluginNotify, 10,10,500,30);
new label(this,LblPluginRemove, 10,40,500,30); new label(this,LblPluginRemove, 10,40,500,30);
static auto listadd=[&](const std::wstring& s){ static auto listadd=[&](const std::wstring& s){
auto idx=listplugins->additem(std::filesystem::path(s).stem().c_str()); auto idx=listplugins->additem(std::filesystem::path(s).stem());
auto _s=new wchar_t[s.size()+1];wcscpy(_s,s.c_str()); auto _s=new wchar_t[s.size()+1];wcscpy(_s,s.c_str());
listplugins->setdata(idx,(LONG_PTR)_s); listplugins->setdata(idx,(LONG_PTR)_s);
}; };
@ -264,7 +264,7 @@ Pluginwindow::Pluginwindow(mainwindow*p,Pluginmanager* pl):mainwindow(p){
auto pb=((LPCWSTR)listplugins->getdata(b)); auto pb=((LPCWSTR)listplugins->getdata(b));
listplugins->deleteitem(a); listplugins->deleteitem(a);
listplugins->insertitem(b,std::filesystem::path(pa).stem().c_str()); listplugins->insertitem(b,std::filesystem::path(pa).stem());
listplugins->setdata(b,(LONG_PTR)pa); listplugins->setdata(b,(LONG_PTR)pa);
break; break;
} }

View File

@ -8,8 +8,8 @@ control::control(mainwindow*_parent){
} }
void control::dispatch(WPARAM){} void control::dispatch(WPARAM){}
void control::dispatch_2(WPARAM wParam, LPARAM lParam){}; 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){ button::button(mainwindow* parent,const std::wstring& text,int x,int y,int w,int h,DWORD style):control(parent){
winId=CreateWindowEx(0, L"BUTTON", text, WS_CHILD | WS_VISIBLE |style , winId=CreateWindowEx(0, L"BUTTON", text.c_str(), WS_CHILD | WS_VISIBLE |style ,
x, y, w, h, parent->winId , NULL, NULL, NULL); x, y, w, h, parent->winId , NULL, NULL, NULL);
} }
void button::dispatch(WPARAM wparam){ void button::dispatch(WPARAM wparam){
@ -21,13 +21,13 @@ bool checkbox::ischecked(){
int state = SendMessage(winId, BM_GETCHECK, 0, 0); int state = SendMessage(winId, BM_GETCHECK, 0, 0);
return (state == BST_CHECKED); return (state == BST_CHECKED);
} }
checkbox::checkbox(mainwindow* parent,LPCWSTR text,int x,int y,int w,int h):button(parent,text,x,y,w,h,BS_AUTOCHECKBOX|BS_RIGHTBUTTON ){ checkbox::checkbox(mainwindow* parent,const std::wstring& text,int x,int y,int w,int h):button(parent,text,x,y,w,h,BS_AUTOCHECKBOX|BS_RIGHTBUTTON ){
} }
void checkbox::setcheck(bool b){ void checkbox::setcheck(bool b){
SendMessage(winId, BM_SETCHECK, (WPARAM)BST_CHECKED*b, 0); SendMessage(winId, BM_SETCHECK, (WPARAM)BST_CHECKED*b, 0);
} }
spinbox::spinbox(mainwindow* parent,LPCWSTR text,int x,int y,int w,int h,DWORD stype):control(parent){ spinbox::spinbox(mainwindow* parent,const std::wstring& text,int x,int y,int w,int h,DWORD stype):control(parent){
winId=CreateWindowEx(0, L"EDIT", text, WS_CHILD | WS_VISIBLE | WS_BORDER|ES_NUMBER , winId=CreateWindowEx(0, L"EDIT", text.c_str(), WS_CHILD | WS_VISIBLE | WS_BORDER|ES_NUMBER ,
x, y, w, h, parent->winId, NULL, NULL, NULL); x, y, w, h, parent->winId, NULL, NULL, NULL);
hUpDown = CreateWindowEx(0, UPDOWN_CLASS, NULL, hUpDown = CreateWindowEx(0, UPDOWN_CLASS, NULL,
@ -72,8 +72,8 @@ void spinbox::setminmax(int min,int max){
SendMessage(hUpDown, UDM_SETRANGE32,min, max); SendMessage(hUpDown, UDM_SETRANGE32,min, max);
std::tie(minv,maxv)= getminmax(); std::tie(minv,maxv)= getminmax();
} }
textedit::textedit(mainwindow* parent,LPCWSTR text,int x,int y,int w,int h,DWORD stype):control(parent){ textedit::textedit(mainwindow* parent,const std::wstring& text,int x,int y,int w,int h,DWORD stype):control(parent){
winId=CreateWindowEx(0, L"EDIT", text, WS_CHILD | WS_VISIBLE | WS_BORDER|stype , winId=CreateWindowEx(0, L"EDIT", text.c_str(), WS_CHILD | WS_VISIBLE | WS_BORDER|stype ,
x, y, w, h, parent->winId, NULL, NULL, NULL); x, y, w, h, parent->winId, NULL, NULL, NULL);
} }
void textedit::scrolltoend(){ void textedit::scrolltoend(){
@ -91,8 +91,8 @@ void textedit::dispatch(WPARAM wparam){
ontextchange(text()); ontextchange(text());
} }
} }
label::label(mainwindow* parent,LPCWSTR text,int x,int y,int w,int h):control(parent){ label::label(mainwindow* parent,const std::wstring& text,int x,int y,int w,int h):control(parent){
winId=CreateWindowEx(0, L"STATIC", text, WS_CHILD | WS_VISIBLE, winId=CreateWindowEx(0, L"STATIC", text.c_str(), WS_CHILD | WS_VISIBLE,
x, y, w, h, parent->winId , NULL, NULL, NULL); x, y, w, h, parent->winId , NULL, NULL, NULL);
} }
@ -121,8 +121,8 @@ std::wstring listbox::text(int idx){
void listbox::clear(){ void listbox::clear(){
SendMessage(winId, LB_RESETCONTENT, 0, 0); SendMessage(winId, LB_RESETCONTENT, 0, 0);
} }
int listbox::additem(LPCWSTR text){ int listbox::additem(const std::wstring& text){
return SendMessage(winId, LB_ADDSTRING, 0, (LPARAM)text); return SendMessage(winId, LB_ADDSTRING, 0, (LPARAM)text.c_str());
} }
void listbox::deleteitem(int i){ void listbox::deleteitem(int i){
SendMessage(winId, LB_DELETESTRING, (WPARAM)i, (LPARAM)i); SendMessage(winId, LB_DELETESTRING, (WPARAM)i, (LPARAM)i);
@ -136,8 +136,8 @@ LONG_PTR listbox::getdata(int idx){
int listbox::count(){ int listbox::count(){
return SendMessage(winId, LB_GETCOUNT, 0, 0); return SendMessage(winId, LB_GETCOUNT, 0, 0);
} }
int listbox::insertitem(int i,LPCWSTR t){ int listbox::insertitem(int i,const std::wstring& t){
return SendMessage(winId, LB_INSERTSTRING, i, (LPARAM)t); return SendMessage(winId, LB_INSERTSTRING, i, (LPARAM)t.c_str());
} }
listview::listview(mainwindow* parent,int x,int y,int w,int h):control(parent){ listview::listview(mainwindow* parent,int x,int y,int w,int h):control(parent){

View File

@ -14,19 +14,19 @@ class control:public basewindow{
class button:public control{ class button:public control{
public: public:
button(mainwindow*,LPCWSTR,int,int,int,int,DWORD=BS_PUSHBUTTON); button(mainwindow*,const std::wstring&,int,int,int,int,DWORD=BS_PUSHBUTTON);
void dispatch(WPARAM); void dispatch(WPARAM);
std::function<void()> onclick=[](){}; std::function<void()> onclick=[](){};
}; };
class checkbox:public button{ class checkbox:public button{
public: public:
checkbox(mainwindow*,LPCWSTR,int,int,int,int); checkbox(mainwindow*,const std::wstring&,int,int,int,int);
bool ischecked(); bool ischecked();
void setcheck(bool); void setcheck(bool);
}; };
class textedit:public control{ class textedit:public control{
public: public:
textedit(mainwindow*,LPCWSTR,int,int,int,int,DWORD stype=0); textedit(mainwindow*,const std::wstring&,int,int,int,int,DWORD stype=0);
void dispatch(WPARAM); void dispatch(WPARAM);
std::function<void(const std::wstring&)> ontextchange=[&](const std::wstring &text){}; std::function<void(const std::wstring&)> ontextchange=[&](const std::wstring &text){};
void appendtext(const std::wstring&); void appendtext(const std::wstring&);
@ -37,7 +37,7 @@ class spinbox:public control{
int minv,maxv; int minv,maxv;
public: public:
void dispatch(WPARAM); void dispatch(WPARAM);
spinbox(mainwindow*,LPCWSTR,int,int,int,int,DWORD stype=0); spinbox(mainwindow*,const std::wstring&,int,int,int,int,DWORD stype=0);
void setminmax(int,int); void setminmax(int,int);
std::pair<int,int>getminmax(); std::pair<int,int>getminmax();
void setcurr(int); void setcurr(int);
@ -45,7 +45,7 @@ class spinbox:public control{
}; };
class label:public control{ class label:public control{
public: public:
label(mainwindow*,LPCWSTR,int,int,int,int); label(mainwindow*,const std::wstring&,int,int,int,int);
}; };
class listbox:public control{ class listbox:public control{
@ -56,10 +56,10 @@ public:
std::wstring text(int); std::wstring text(int);
std::function<void(int)> oncurrentchange=[](int){}; std::function<void(int)> oncurrentchange=[](int){};
void clear(); void clear();
int additem(LPCWSTR); int additem(const std::wstring&);
void deleteitem(int); void deleteitem(int);
void setdata(int,LONG_PTR); void setdata(int,LONG_PTR);
int insertitem(int,LPCWSTR); int insertitem(int,const std::wstring&);
LONG_PTR getdata(int); LONG_PTR getdata(int);
int count(); int count();
}; };
@ -77,6 +77,6 @@ public:
void setheader(const std::vector<std::wstring>&); void setheader(const std::vector<std::wstring>&);
void autosize(); void autosize();
int additem(const std::wstring&,HICON hicon); int additem(const std::wstring&,HICON hicon);
void listview::dispatch_2(WPARAM wParam, LPARAM lParam); void dispatch_2(WPARAM wParam, LPARAM lParam);
}; };
#endif #endif

View File

@ -47,8 +47,8 @@ std::unordered_map<std::wstring,std::vector<int>> getprocesslist()
void processlistwindow::PopulateProcessList(listview* _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(); _listbox->clear();
for(auto& exe:exe_pid){ for(auto& exe:exe_pid){
auto hicon=GetExeIcon(exe.first.c_str()); auto hicon=GetExeIcon(exe.first);
_listbox->additem(exe.first.c_str(),hicon); _listbox->additem(exe.first,hicon);
DestroyIcon(hicon); DestroyIcon(hicon);
} }
} }

View File

@ -2,10 +2,10 @@
#include"controls.h" #include"controls.h"
#include"Lang/Lang.h" #include"Lang/Lang.h"
#include<shellapi.h> #include<shellapi.h>
HICON GetExeIcon(const wchar_t* filePath) { HICON GetExeIcon(const std::wstring& filePath) {
SHFILEINFO fileInfo; SHFILEINFO fileInfo;
HICON hIcon = NULL; HICON hIcon = NULL;
if (SHGetFileInfo(filePath, 0, &fileInfo, sizeof(fileInfo), SHGFI_ICON | SHGFI_LARGEICON)) { if (SHGetFileInfo(filePath.c_str(), 0, &fileInfo, sizeof(fileInfo), SHGFI_ICON | SHGFI_LARGEICON)) {
hIcon = fileInfo.hIcon; hIcon = fileInfo.hIcon;
} }
return hIcon; return hIcon;
@ -153,7 +153,7 @@ mainwindow::mainwindow(mainwindow* _parent){
wc.hInstance = GetModuleHandle(0); wc.hInstance = GetModuleHandle(0);
wc.lpszClassName = CLASS_NAME; wc.lpszClassName = CLASS_NAME;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW ); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW );
wc.hIcon= GetExeIcon(GetModuleFilename().value().c_str());//LoadIconW(GetModuleHandle(0),L"IDI_ICON1"); wc.hIcon= GetExeIcon(GetModuleFilename().value());//LoadIconW(GetModuleHandle(0),L"IDI_ICON1");
static auto _=RegisterClass(&wc); static auto _=RegisterClass(&wc);
HWND hWnd = CreateWindowEx( HWND hWnd = CreateWindowEx(

View File

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