mirror of
https://github.com/HIllya51/LunaHook.git
synced 2024-10-22 23:18:16 +08:00
refactor gui
1 1 1 1 1
This commit is contained in:
parent
68f178e451
commit
6f3bc497ab
@ -1,4 +1,4 @@
|
||||
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)
|
||||
add_executable(LunaHost 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 comctl32 pch host ${YY_Thunks_for_WinXP})
|
||||
|
@ -33,21 +33,7 @@ void LunaHost::on_close(){
|
||||
if(attachedprocess.size())
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
void LunaHost::on_size(int w,int h){
|
||||
int height = h-110;
|
||||
w-=20;
|
||||
auto _w=w-20;
|
||||
|
||||
g_selectprocessbutton->setgeo(10,10,_w/4,30);
|
||||
btndetachall->setgeo(10+10+_w/4,10,_w/4,30);
|
||||
btnshowsettionwindow->setgeo(10+20+_w*2/4,10,_w/4,30);
|
||||
btnplugin->setgeo(10+30+_w*3/4,10,_w/4,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*3/4+20,30);
|
||||
//g_hButton_insert->setgeo(10+20+_w*2/4,50,_w/4,30);
|
||||
g_hButton_insert->setgeo(10+30+_w*3/4,50,_w/4,30);
|
||||
}
|
||||
|
||||
void LunaHost::savesettings()
|
||||
{
|
||||
configs->set("ToClipboard",check_toclipboard);
|
||||
@ -123,12 +109,12 @@ LunaHost::LunaHost(){
|
||||
|
||||
setfont(25);
|
||||
settext(WndLunaHostGui);
|
||||
btnshowsettionwindow=new button(this, BtnShowSettingWindow,100,100,100,100);
|
||||
g_selectprocessbutton =new button(this,BtnSelectProcess,830, 10, 200, 40) ;
|
||||
btnshowsettionwindow=new button(this, BtnShowSettingWindow);
|
||||
g_selectprocessbutton =new button(this,BtnSelectProcess) ;
|
||||
|
||||
// btnsavehook=new button(this,BtnSaveHook,10,10,10,10);
|
||||
// btnsavehook->onclick=std::bind(&LunaHost::btnsavehookscallback,this);
|
||||
btndetachall=new button(this,BtnDetach,10,10,10,10);
|
||||
btndetachall=new button(this,BtnDetach);
|
||||
btndetachall->onclick=[&](){
|
||||
for(auto pid:attachedprocess){
|
||||
Host::DetachProcess(pid);
|
||||
@ -136,15 +122,15 @@ LunaHost::LunaHost(){
|
||||
}
|
||||
};
|
||||
|
||||
g_hEdit_userhook = new textedit(this,L"",10, 60, 600, 40,ES_AUTOHSCROLL);
|
||||
btnplugin=new button(this,BtnPlugin,830,60,200,40);
|
||||
g_hEdit_userhook = new lineedit(this);
|
||||
btnplugin=new button(this,BtnPlugin);
|
||||
|
||||
plugins=new Pluginmanager(this);
|
||||
btnplugin->onclick=[&](){
|
||||
if(pluginwindow==0) pluginwindow=new Pluginwindow(this,plugins);
|
||||
pluginwindow->show();
|
||||
};
|
||||
g_hButton_insert = new button(this,BtnInsertUserHook,610, 60, 200, 40) ;
|
||||
g_hButton_insert = new button(this,BtnInsertUserHook) ;
|
||||
btnshowsettionwindow->onclick=[&](){
|
||||
if(settingwindow==0) settingwindow=new Settingwindow(this);
|
||||
settingwindow->show();
|
||||
@ -165,7 +151,7 @@ LunaHost::LunaHost(){
|
||||
}
|
||||
};
|
||||
|
||||
g_hListBox_listtext = new listbox(this,10, 120, 200, 200);
|
||||
g_hListBox_listtext = new listbox(this);
|
||||
g_hListBox_listtext->oncurrentchange=[&](int idx){
|
||||
uint64_t handle = g_hListBox_listtext->getdata(idx);
|
||||
std::wstring get;
|
||||
@ -243,7 +229,7 @@ LunaHost::LunaHost(){
|
||||
break;
|
||||
}
|
||||
};
|
||||
g_showtexts = new textedit(this,L"",10, 330, 200, 200,ES_MULTILINE |ES_AUTOVSCROLL| WS_VSCROLL);
|
||||
g_showtexts = new multilineedit(this);
|
||||
g_showtexts->setreadonly(true);
|
||||
|
||||
Host::Start(
|
||||
@ -256,6 +242,20 @@ LunaHost::LunaHost(){
|
||||
std::bind(&LunaHost::on_text_recv,this,std::placeholders::_1,std::placeholders::_2)
|
||||
);
|
||||
|
||||
mainlayout=new gridlayout();
|
||||
mainlayout->addcontrol(g_selectprocessbutton,0,0);
|
||||
mainlayout->addcontrol(btndetachall,0,1);
|
||||
mainlayout->addcontrol(btnshowsettionwindow,0,2);
|
||||
mainlayout->addcontrol(btnplugin,0,3);
|
||||
mainlayout->addcontrol(g_hEdit_userhook,1,0,1,3);
|
||||
mainlayout->addcontrol(g_hButton_insert,1,3);
|
||||
|
||||
mainlayout->addcontrol(g_hListBox_listtext,2,0,1,4);
|
||||
mainlayout->addcontrol(g_showtexts,3,0,1,4);
|
||||
|
||||
mainlayout->setfixedheigth(0,30);
|
||||
mainlayout->setfixedheigth(1,30);
|
||||
setlayout(mainlayout);
|
||||
setcentral(1200,800);
|
||||
}
|
||||
void LunaHost::on_text_recv_checkissaved(TextThread& thread)
|
||||
@ -332,14 +332,14 @@ void LunaHost::on_thread_delete(TextThread& thread){
|
||||
Settingwindow::Settingwindow(LunaHost* host):mainwindow(host){
|
||||
int height=30;int curry=10;int space=10;
|
||||
int labelwidth=300;int spinwidth=200;
|
||||
g_timeout = new spinbox(this,std::to_wstring(TextThread::flushDelay),space+labelwidth, curry, spinwidth, height) ;
|
||||
new label(this,LblFlushDelay,10, curry, labelwidth, height);curry+=height+space;
|
||||
g_timeout = new spinbox(this,std::to_wstring(TextThread::flushDelay)) ;
|
||||
|
||||
g_codepage = new spinbox(this,std::to_wstring(Host::defaultCodepage),space+labelwidth, curry, spinwidth, height) ;
|
||||
new label(this,LblCodePage,10, curry, labelwidth, height);curry+=height+space;
|
||||
|
||||
spinmaxbuffsize = new spinbox(this,std::to_wstring(TextThread::maxBufferSize),space+labelwidth, curry, spinwidth, height) ;
|
||||
new label(this,LblMaxBuff,10, curry, labelwidth, height);curry+=height+space;
|
||||
g_codepage = new spinbox(this,std::to_wstring(Host::defaultCodepage)) ;
|
||||
|
||||
|
||||
spinmaxbuffsize = new spinbox(this,std::to_wstring(TextThread::maxBufferSize)) ;
|
||||
;curry+=height+space;
|
||||
|
||||
spinmaxbuffsize->onvaluechange=[=](int v){
|
||||
TextThread::maxBufferSize=v;
|
||||
@ -347,40 +347,40 @@ Settingwindow::Settingwindow(LunaHost* host):mainwindow(host){
|
||||
spinmaxbuffsize->setminmax(0,0x7fffffff);
|
||||
|
||||
|
||||
spinmaxhistsize = new spinbox(this,std::to_wstring(TextThread::maxHistorySize),space+labelwidth, curry, spinwidth, height) ;
|
||||
new label(this,LblMaxHist,10, curry, labelwidth, height);curry+=height+space;
|
||||
spinmaxhistsize = new spinbox(this,std::to_wstring(TextThread::maxHistorySize)) ;
|
||||
;curry+=height+space;
|
||||
|
||||
spinmaxhistsize->onvaluechange=[=](int v){
|
||||
TextThread::maxHistorySize=v;
|
||||
};
|
||||
spinmaxhistsize->setminmax(0,0x7fffffff);
|
||||
|
||||
ckbfilterrepeat=new checkbox(this,LblFilterRepeat,10, curry, labelwidth, height);curry+=height+space;
|
||||
ckbfilterrepeat=new checkbox(this,LblFilterRepeat);
|
||||
ckbfilterrepeat->onclick=[=](){
|
||||
TextThread::filterRepetition=ckbfilterrepeat->ischecked();
|
||||
};
|
||||
ckbfilterrepeat->setcheck(TextThread::filterRepetition);
|
||||
|
||||
g_check_clipboard =new checkbox(this,BtnToClipboard,10, curry, labelwidth, height) ;curry+=height+space;
|
||||
g_check_clipboard =new checkbox(this,BtnToClipboard);
|
||||
g_check_clipboard->onclick=[=](){
|
||||
host->check_toclipboard=g_check_clipboard->ischecked();
|
||||
};
|
||||
g_check_clipboard->setcheck(host->check_toclipboard);
|
||||
|
||||
autoattach =new checkbox(this,LblAutoAttach,10, curry, labelwidth, height) ;curry+=height+space;
|
||||
autoattach =new checkbox(this,LblAutoAttach);
|
||||
autoattach->onclick=[=](){
|
||||
host->autoattach=autoattach->ischecked();
|
||||
};
|
||||
autoattach->setcheck(host->autoattach);
|
||||
|
||||
autoattach_so =new checkbox(this,LblAutoAttach_savedonly,10, curry, labelwidth, height) ;curry+=height+space;
|
||||
autoattach_so =new checkbox(this,LblAutoAttach_savedonly);
|
||||
autoattach_so->onclick=[=](){
|
||||
host->autoattach_savedonly=autoattach_so->ischecked();
|
||||
};
|
||||
autoattach_so->setcheck(host->autoattach_savedonly);
|
||||
|
||||
|
||||
readonlycheck=new checkbox(this,BtnReadOnly,10,curry,labelwidth,height);curry+=height+space;
|
||||
readonlycheck=new checkbox(this,BtnReadOnly);
|
||||
readonlycheck->onclick=[=](){
|
||||
host->g_showtexts->setreadonly(readonlycheck->ischecked());
|
||||
};
|
||||
@ -396,6 +396,27 @@ Settingwindow::Settingwindow(LunaHost* host):mainwindow(host){
|
||||
}
|
||||
};
|
||||
g_codepage->setminmax(0,CP_UTF8);
|
||||
|
||||
mainlayout=new gridlayout();
|
||||
mainlayout->addcontrol(new label(this,LblFlushDelay),0,0);
|
||||
mainlayout->addcontrol(g_timeout,0,1);
|
||||
|
||||
mainlayout->addcontrol(new label(this,LblCodePage),1,0);
|
||||
mainlayout->addcontrol(g_codepage,1,1);
|
||||
|
||||
mainlayout->addcontrol(new label(this,LblMaxBuff),2,0);
|
||||
mainlayout->addcontrol(spinmaxbuffsize,2,1);
|
||||
|
||||
mainlayout->addcontrol(new label(this,LblMaxHist),3,0);
|
||||
mainlayout->addcontrol(spinmaxhistsize,3,1);
|
||||
|
||||
mainlayout->addcontrol(ckbfilterrepeat,4,0,1,2);
|
||||
mainlayout->addcontrol(g_check_clipboard,5,0,1,2);
|
||||
mainlayout->addcontrol(autoattach,6,0,1,2);
|
||||
mainlayout->addcontrol(autoattach_so,7,0,1,2);
|
||||
mainlayout->addcontrol(readonlycheck,8,0,1,2);
|
||||
|
||||
setlayout(mainlayout);
|
||||
setcentral(600,500);
|
||||
settext(WndSetting);
|
||||
}
|
||||
@ -404,14 +425,14 @@ void Pluginwindow::on_size(int w,int h){
|
||||
}
|
||||
Pluginwindow::Pluginwindow(mainwindow*p,Pluginmanager* pl):mainwindow(p){
|
||||
pluginmanager=pl;
|
||||
new label(this,LblPluginNotify, 10,10,500,30);
|
||||
new label(this,LblPluginRemove, 10,40,500,30);
|
||||
(new label(this,LblPluginNotify))->setgeo(10,10,500,30);
|
||||
(new label(this,LblPluginRemove))->setgeo( 10,40,500,30);
|
||||
static auto listadd=[&](const std::wstring& s){
|
||||
auto idx=listplugins->additem(std::filesystem::path(s).stem());
|
||||
auto _s=new wchar_t[s.size()+1];wcscpy(_s,s.c_str());
|
||||
listplugins->setdata(idx,(LONG_PTR)_s);
|
||||
};
|
||||
listplugins = new listbox(this,10, 10,360,340);
|
||||
listplugins = new listbox(this);
|
||||
#define IDM_ADD_PLUGIN 1004
|
||||
#define IDM_REMOVE_PLUGIN 1006
|
||||
#define IDM_RANK_UP 1007
|
||||
|
@ -21,12 +21,14 @@ class Settingwindow:public mainwindow{
|
||||
checkbox* autoattach_so;
|
||||
spinbox* spinmaxbuffsize;
|
||||
spinbox* spinmaxhistsize;
|
||||
gridlayout* mainlayout;
|
||||
public:
|
||||
Settingwindow(LunaHost*);
|
||||
};
|
||||
|
||||
class processlistwindow:public mainwindow{
|
||||
textedit* g_hEdit;
|
||||
gridlayout* mainlayout;
|
||||
lineedit* g_hEdit;
|
||||
button* g_hButton;
|
||||
listview* g_hListBox;
|
||||
button* g_refreshbutton;
|
||||
@ -34,7 +36,6 @@ class processlistwindow:public mainwindow{
|
||||
void PopulateProcessList(listview*,std::unordered_map<std::wstring,std::vector<int>>&);
|
||||
public:
|
||||
processlistwindow(mainwindow* parent=0);
|
||||
void on_size(int w,int h);
|
||||
void on_show();
|
||||
};
|
||||
|
||||
@ -43,11 +44,12 @@ class LunaHost:public mainwindow{
|
||||
std::map<int64_t,std::vector<std::wstring>>savetext;
|
||||
std::set<int>attachedprocess;
|
||||
std::mutex settextmutex;
|
||||
textedit* g_hEdit_userhook;
|
||||
lineedit* g_hEdit_userhook;
|
||||
gridlayout* mainlayout;
|
||||
button* g_hButton_insert;
|
||||
button* btnplugin;
|
||||
listbox* g_hListBox_listtext;
|
||||
textedit* g_showtexts;
|
||||
multilineedit* g_showtexts;
|
||||
button* g_selectprocessbutton;
|
||||
button* btndetachall;
|
||||
button* btnshowsettionwindow;
|
||||
@ -71,7 +73,6 @@ public:
|
||||
std::unordered_map<std::string,nlohmann::json>savedhookcontext;
|
||||
std::set<int>userdetachedpids;
|
||||
std::set<int64_t>onceautoselectthread;
|
||||
void on_size(int w,int h);
|
||||
void on_close();
|
||||
LunaHost();
|
||||
friend class Settingwindow;
|
||||
|
@ -1,16 +1,17 @@
|
||||
#include"controls.h"
|
||||
#include"window.h"
|
||||
|
||||
control::control(mainwindow*_parent){
|
||||
if(_parent==0)return;
|
||||
parent=_parent;
|
||||
parent->controls.push_back(this);
|
||||
|
||||
}
|
||||
void control::dispatch(WPARAM){}
|
||||
void control::dispatch_2(WPARAM wParam, LPARAM lParam){};
|
||||
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.c_str(), WS_CHILD | WS_VISIBLE |style ,
|
||||
x, y, w, h, parent->winId , NULL, NULL, NULL);
|
||||
button::button(mainwindow* parent):control(parent){}
|
||||
button::button(mainwindow* parent,const std::wstring& text):control(parent)
|
||||
{
|
||||
winId=CreateWindowEx(0, L"BUTTON", text.c_str(), WS_CHILD | WS_VISIBLE ,
|
||||
0,0,0,0, parent->winId , NULL, NULL, NULL);
|
||||
}
|
||||
void button::dispatch(WPARAM wparam){
|
||||
if(wparam==BN_CLICKED){
|
||||
@ -21,14 +22,17 @@ bool checkbox::ischecked(){
|
||||
int state = SendMessage(winId, BM_GETCHECK, 0, 0);
|
||||
return (state == BST_CHECKED);
|
||||
}
|
||||
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 ){
|
||||
checkbox::checkbox(mainwindow* parent,const std::wstring& text):button(parent)
|
||||
{
|
||||
winId=CreateWindowEx(0, L"BUTTON", text.c_str(), WS_CHILD | WS_VISIBLE |BS_AUTOCHECKBOX|BS_RIGHTBUTTON,
|
||||
0,0,0,0, parent->winId , NULL, NULL, NULL);
|
||||
}
|
||||
void checkbox::setcheck(bool b){
|
||||
SendMessage(winId, BM_SETCHECK, (WPARAM)BST_CHECKED*b, 0);
|
||||
}
|
||||
spinbox::spinbox(mainwindow* parent,const std::wstring& text,int x,int y,int w,int h,DWORD stype):control(parent){
|
||||
spinbox::spinbox(mainwindow* parent,const std::wstring& text):control(parent){
|
||||
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);
|
||||
0,0,0,0, parent->winId, NULL, NULL, NULL);
|
||||
|
||||
hUpDown = CreateWindowEx(0, UPDOWN_CLASS, NULL,
|
||||
WS_CHILD | WS_VISIBLE | UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_ARROWKEYS | UDS_NOTHOUSANDS ,
|
||||
@ -37,6 +41,11 @@ spinbox::spinbox(mainwindow* parent,const std::wstring& text,int x,int y,int w,i
|
||||
SendMessage(hUpDown, UDM_SETBUDDY, (WPARAM)winId, 0);
|
||||
std::tie(minv,maxv)= getminmax();
|
||||
}
|
||||
void spinbox::setgeo(int x,int y,int w,int h)
|
||||
{
|
||||
MoveWindow(winId,x,y,w,h,TRUE);
|
||||
SendMessage(hUpDown, UDM_SETBUDDY, (WPARAM)winId, 0);
|
||||
}
|
||||
void spinbox::setcurr(int cur){
|
||||
SendMessage(hUpDown, UDM_SETPOS32, 0, cur);
|
||||
}
|
||||
@ -72,38 +81,43 @@ void spinbox::setminmax(int min,int max){
|
||||
SendMessage(hUpDown, UDM_SETRANGE32,min, max);
|
||||
std::tie(minv,maxv)= getminmax();
|
||||
}
|
||||
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.c_str(), WS_CHILD | WS_VISIBLE | WS_BORDER|stype ,
|
||||
x, y, w, h, parent->winId, NULL, NULL, NULL);
|
||||
multilineedit::multilineedit(mainwindow* parent):texteditbase(parent){
|
||||
winId=CreateWindowEx(0, L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER| ES_MULTILINE |ES_AUTOVSCROLL| WS_VSCROLL ,
|
||||
0,0,0,0, parent->winId, NULL, NULL, NULL);
|
||||
SendMessage(winId, EM_SETLIMITTEXT, 0, 0);
|
||||
}
|
||||
void textedit::setreadonly(bool ro){
|
||||
lineedit::lineedit(mainwindow* parent):texteditbase(parent){
|
||||
winId=CreateWindowEx(0, L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER| ES_AUTOHSCROLL ,
|
||||
0,0,0,0, parent->winId, NULL, NULL, NULL);
|
||||
}
|
||||
texteditbase::texteditbase(mainwindow* parent):control(parent){}
|
||||
void texteditbase::setreadonly(bool ro){
|
||||
SendMessage(winId, EM_SETREADONLY, ro, 0);
|
||||
}
|
||||
void textedit::scrolltoend(){
|
||||
void texteditbase::scrolltoend(){
|
||||
int textLength = GetWindowTextLength(winId);
|
||||
SendMessage(winId, EM_SETSEL, (WPARAM)textLength, (LPARAM)textLength);
|
||||
SendMessage(winId, EM_SCROLLCARET, 0, 0);
|
||||
}
|
||||
void textedit::appendtext(const std::wstring& text){
|
||||
void texteditbase::appendtext(const std::wstring& text){
|
||||
auto _=std::wstring(L"\r\n")+text;
|
||||
SendMessage(winId, EM_REPLACESEL, 0, (LPARAM)_.c_str());
|
||||
}
|
||||
|
||||
void textedit::dispatch(WPARAM wparam){
|
||||
void texteditbase::dispatch(WPARAM wparam){
|
||||
if(HIWORD(wparam)==EN_CHANGE){
|
||||
ontextchange(text());
|
||||
}
|
||||
}
|
||||
label::label(mainwindow* parent,const std::wstring& text,int x,int y,int w,int h):control(parent){
|
||||
label::label(mainwindow* parent,const std::wstring& text):control(parent){
|
||||
winId=CreateWindowEx(0, L"STATIC", text.c_str(), WS_CHILD | WS_VISIBLE,
|
||||
x, y, w, h, parent->winId , NULL, NULL, NULL);
|
||||
0,0,0,0, parent->winId , NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
listbox::listbox(mainwindow* parent,int x,int y,int w,int h):control(parent){
|
||||
listbox::listbox(mainwindow* parent):control(parent){
|
||||
|
||||
winId=CreateWindowEx(WS_EX_CLIENTEDGE, L"LISTBOX", L"", WS_CHILD | WS_VISIBLE | WS_VSCROLL | LBS_NOTIFY|LBS_NOINTEGRALHEIGHT,
|
||||
x, y, w, h, parent->winId , NULL, NULL, NULL);
|
||||
0,0,0,0, parent->winId , NULL, NULL, NULL);
|
||||
}
|
||||
void listbox::dispatch(WPARAM wparam){
|
||||
if(HIWORD(wparam) == LBN_SELCHANGE){
|
||||
@ -148,8 +162,8 @@ int listbox::insertitem(int i,const std::wstring& 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){
|
||||
winId=CreateWindowEx(0, WC_LISTVIEW, NULL, WS_VISIBLE |WS_VSCROLL| WS_CHILD | LVS_REPORT |LVS_SINGLESEL|LVS_NOCOLUMNHEADER , x, y, w, h, parent->winId, NULL,NULL, NULL);
|
||||
listview::listview(mainwindow* parent):control(parent){
|
||||
winId=CreateWindowEx(0, WC_LISTVIEW, NULL, WS_VISIBLE |WS_VSCROLL| WS_CHILD | LVS_REPORT |LVS_SINGLESEL|LVS_NOCOLUMNHEADER , 0,0,0,0, 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),
|
||||
@ -214,8 +228,85 @@ void listview::setheader(const std::vector<std::wstring>& headers){
|
||||
}
|
||||
headernum=headers.size();
|
||||
}
|
||||
void listview::on_size(int,int){
|
||||
autosize();
|
||||
}
|
||||
void listview::autosize(){
|
||||
for(int i=0;i<headernum;i++){
|
||||
ListView_SetColumnWidth(winId, i, LVSCW_AUTOSIZE_USEHEADER);
|
||||
}
|
||||
}
|
||||
void gridlayout::setgeo(int x,int y,int w,int h){
|
||||
|
||||
auto dynarow=maxrow;
|
||||
auto dynacol=maxcol;
|
||||
for(auto fw:fixedwidth){
|
||||
dynacol-=1;
|
||||
w-=fw.second+margin;
|
||||
}
|
||||
for(auto fh:fixedheight){
|
||||
dynarow-=1;
|
||||
h-=fh.second+margin;
|
||||
}
|
||||
auto wpercol=(w-margin*(dynacol+1))/dynacol;
|
||||
auto hperrow=(h-margin*(dynarow+1))/dynarow;
|
||||
|
||||
for(auto ctr:savecontrol){
|
||||
|
||||
int _x=0,_y=0,_w=0,_h=0;
|
||||
for(int c=0;c<ctr.col+ctr.colrange;c++)
|
||||
{
|
||||
if(fixedwidth.find(c)!=fixedwidth.end())
|
||||
if(c<ctr.col)
|
||||
_x+=fixedwidth[c];
|
||||
else
|
||||
_w+=fixedwidth[c];
|
||||
else
|
||||
if(c<ctr.col)
|
||||
_x+=wpercol;
|
||||
else
|
||||
_w+=wpercol;
|
||||
|
||||
}
|
||||
_x+=(ctr.col+1)*margin;
|
||||
_w+=(ctr.colrange-1)*margin;
|
||||
for(int r=0;r<ctr.row+ctr.rowrange;r++)
|
||||
{
|
||||
if(fixedheight.find(r)!=fixedheight.end())
|
||||
if(r<ctr.row)
|
||||
_y+=fixedheight[r];
|
||||
else
|
||||
_h+=fixedheight[r];
|
||||
else
|
||||
if(r<ctr.row)
|
||||
_y+=hperrow;
|
||||
else
|
||||
_h+=hperrow;
|
||||
}
|
||||
_y+=(ctr.row+1)*margin;
|
||||
_h+=(ctr.rowrange-1)*margin;
|
||||
|
||||
ctr.ctr->setgeo(_x,_y,_w,_h);
|
||||
}
|
||||
}
|
||||
void gridlayout::setfixedwidth(int col,int width){
|
||||
fixedwidth.insert({col,width});
|
||||
}
|
||||
void gridlayout::setfixedheigth(int row,int height){
|
||||
fixedheight.insert({row,height});
|
||||
}
|
||||
void gridlayout::addcontrol(control* _c,int row,int col,int rowrange,int colrange){
|
||||
maxrow=max(maxrow,row+rowrange);
|
||||
maxcol=max(maxcol,col+colrange);
|
||||
savecontrol.push_back(
|
||||
{_c,row,col,rowrange,colrange}
|
||||
);
|
||||
}
|
||||
gridlayout::gridlayout(int row,int col):control(0){
|
||||
maxrow=row;
|
||||
maxcol=col;
|
||||
margin=10;
|
||||
}
|
||||
void gridlayout::setmargin(int m){
|
||||
margin=m;
|
||||
}
|
@ -14,44 +14,54 @@ class control:public basewindow{
|
||||
|
||||
class button:public control{
|
||||
public:
|
||||
button(mainwindow*,const std::wstring&,int,int,int,int,DWORD=BS_PUSHBUTTON);
|
||||
button(mainwindow* parent);
|
||||
button(mainwindow*,const std::wstring&);//,int,int,int,int,DWORD=BS_PUSHBUTTON);
|
||||
void dispatch(WPARAM);
|
||||
std::function<void()> onclick=[](){};
|
||||
};
|
||||
class checkbox:public button{
|
||||
public:
|
||||
checkbox(mainwindow*,const std::wstring&,int,int,int,int);
|
||||
checkbox(mainwindow*,const std::wstring&);//,int,int,int,int);
|
||||
bool ischecked();
|
||||
void setcheck(bool);
|
||||
};
|
||||
class textedit:public control{
|
||||
class texteditbase:public control{
|
||||
public:
|
||||
textedit(mainwindow*,const std::wstring&,int,int,int,int,DWORD stype=0);
|
||||
texteditbase(mainwindow*);
|
||||
void dispatch(WPARAM);
|
||||
std::function<void(const std::wstring&)> ontextchange=[&](const std::wstring &text){};
|
||||
void appendtext(const std::wstring&);
|
||||
void scrolltoend();
|
||||
void setreadonly(bool);
|
||||
};
|
||||
class multilineedit:public texteditbase{
|
||||
public:
|
||||
multilineedit(mainwindow*);
|
||||
};
|
||||
class lineedit:public texteditbase{
|
||||
public:
|
||||
lineedit(mainwindow*);
|
||||
};
|
||||
class spinbox:public control{
|
||||
HWND hUpDown;
|
||||
int minv,maxv;
|
||||
public:
|
||||
void dispatch(WPARAM);
|
||||
spinbox(mainwindow*,const std::wstring&,int,int,int,int,DWORD stype=0);
|
||||
spinbox(mainwindow*,const std::wstring&);
|
||||
void setminmax(int,int);
|
||||
std::pair<int,int>getminmax();
|
||||
void setcurr(int);
|
||||
std::function<void(int)> onvaluechange=[&](int){};
|
||||
void setgeo(int,int,int,int);
|
||||
};
|
||||
class label:public control{
|
||||
public:
|
||||
label(mainwindow*,const std::wstring&,int,int,int,int);
|
||||
label(mainwindow*,const std::wstring&);
|
||||
};
|
||||
|
||||
class listbox:public control{
|
||||
public:
|
||||
listbox(mainwindow*,int,int,int,int);
|
||||
listbox(mainwindow*);
|
||||
void dispatch(WPARAM);
|
||||
int currentidx();
|
||||
std::wstring text(int);
|
||||
@ -69,7 +79,7 @@ class listview:public control{
|
||||
int headernum=1;
|
||||
HIMAGELIST hImageList;
|
||||
public:
|
||||
listview(mainwindow*,int,int,int,int);
|
||||
listview(mainwindow*);
|
||||
int insertitem(int,const std::wstring&,HICON hicon);
|
||||
int insertcol(int,const std::wstring& );
|
||||
void clear();
|
||||
@ -80,5 +90,24 @@ public:
|
||||
void autosize();
|
||||
int additem(const std::wstring&,HICON hicon);
|
||||
void dispatch_2(WPARAM wParam, LPARAM lParam);
|
||||
void on_size(int,int);
|
||||
};
|
||||
|
||||
class gridlayout:public control{
|
||||
struct _c{
|
||||
control* ctr;
|
||||
int row,col,rowrange,colrange;
|
||||
};
|
||||
int margin;
|
||||
int maxrow,maxcol;
|
||||
std::vector<_c>savecontrol;
|
||||
std::map<int,int>fixedwidth,fixedheight;
|
||||
public:
|
||||
void setgeo(int,int,int,int);
|
||||
void setfixedwidth(int col,int width);
|
||||
void setfixedheigth(int row,int height);
|
||||
void addcontrol(control*,int row,int col,int rowrange=1,int colrange=1);
|
||||
gridlayout(int row=0,int col=0);
|
||||
void setmargin(int m=10);
|
||||
};
|
||||
#endif
|
@ -54,9 +54,9 @@ void processlistwindow::PopulateProcessList(listview* _listbox,std::unordered_ma
|
||||
}
|
||||
|
||||
processlistwindow::processlistwindow(mainwindow* p):mainwindow(p){
|
||||
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_hEdit = new lineedit(this);
|
||||
g_hButton=new button(this,BtnAttach);
|
||||
g_refreshbutton =new button(this,BtnRefresh);
|
||||
g_hButton->onclick=[&](){
|
||||
auto str=g_hEdit->text();
|
||||
if(str.size()){
|
||||
@ -76,7 +76,7 @@ processlistwindow::processlistwindow(mainwindow* p):mainwindow(p){
|
||||
g_exe_pid=getprocesslist();
|
||||
PopulateProcessList(g_hListBox,g_exe_pid);
|
||||
};
|
||||
g_hListBox = new listview(this,10, 60, 310, 200);
|
||||
g_hListBox = new listview(this);
|
||||
g_hListBox->setheader({L""});
|
||||
g_hListBox->oncurrentchange=[&](int idx){
|
||||
auto pids=g_exe_pid[g_hListBox->text(idx)];
|
||||
@ -91,19 +91,17 @@ processlistwindow::processlistwindow(mainwindow* p):mainwindow(p){
|
||||
g_hEdit->settext(_);
|
||||
};
|
||||
settext(WndSelectProcess);
|
||||
mainlayout=new gridlayout();
|
||||
mainlayout->addcontrol(g_hEdit,0,0,1,2);
|
||||
mainlayout->addcontrol(g_hButton,0,2);
|
||||
mainlayout->addcontrol(g_refreshbutton,0,3);
|
||||
mainlayout->addcontrol(g_hListBox,1,0,1,4);
|
||||
mainlayout->setfixedheigth(0,30);
|
||||
setlayout(mainlayout);
|
||||
setcentral(800,400);
|
||||
}
|
||||
void processlistwindow::on_show(){
|
||||
g_hEdit->settext(L"");
|
||||
g_exe_pid=getprocesslist();
|
||||
PopulateProcessList(g_hListBox,g_exe_pid);
|
||||
}
|
||||
void processlistwindow::on_size(int w,int h){
|
||||
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();
|
||||
}
|
@ -30,6 +30,7 @@ void basewindow::settext(const std::wstring& text){
|
||||
|
||||
void basewindow::setgeo(int x,int y,int w,int h){
|
||||
MoveWindow(winId,x,y,w,h,TRUE);
|
||||
on_size(w,h);
|
||||
}
|
||||
RECT basewindow::getgeo(){
|
||||
RECT rect;
|
||||
@ -140,7 +141,11 @@ void mainwindow::setcentral(int w,int h){
|
||||
auto [x,y]=calculateXY(w,h);
|
||||
setgeo(x,y,w,h);
|
||||
}
|
||||
void mainwindow::setlayout(control* _l){
|
||||
layout=_l;
|
||||
}
|
||||
mainwindow::mainwindow(mainwindow* _parent){
|
||||
layout=0;
|
||||
const wchar_t CLASS_NAME[] = L"LunaHostWindow";
|
||||
|
||||
WNDCLASS wc = {};
|
||||
@ -183,4 +188,10 @@ void mainwindow::run(){
|
||||
|
||||
void mainwindow::on_close(){}
|
||||
void mainwindow::on_show(){}
|
||||
void mainwindow::on_size(int w,int h){}
|
||||
void mainwindow::on_size(int w,int h){
|
||||
if(layout)
|
||||
{
|
||||
layout->setgeo(0,0,w,h);
|
||||
}
|
||||
}
|
||||
void basewindow::on_size(int w,int h){}
|
||||
|
@ -5,7 +5,8 @@ class basewindow{
|
||||
public:
|
||||
HFONT hfont=0;
|
||||
HWND winId;
|
||||
void setgeo(int,int,int,int);
|
||||
virtual void setgeo(int,int,int,int);
|
||||
virtual void on_size(int w,int h);
|
||||
RECT getgeo();
|
||||
std::wstring text();
|
||||
void settext(const std::wstring&);
|
||||
@ -17,9 +18,10 @@ public:
|
||||
std::vector<control*>controls;
|
||||
mainwindow* parent;
|
||||
HWND lastcontexthwnd;
|
||||
control* layout;
|
||||
virtual void on_show();
|
||||
virtual void on_close();
|
||||
virtual void on_size(int w,int h);
|
||||
void on_size(int w,int h);
|
||||
mainwindow(mainwindow* _parent=0);
|
||||
LRESULT wndproc(UINT message, WPARAM wParam, LPARAM lParam);
|
||||
static void run();
|
||||
@ -27,6 +29,7 @@ public:
|
||||
void close();
|
||||
void setcentral(int,int);
|
||||
std::pair<int,int>calculateXY(int w,int h);
|
||||
void setlayout(control*);
|
||||
};
|
||||
HICON GetExeIcon(const std::wstring& filePath);
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user