This commit is contained in:
恍兮惚兮 2024-04-25 15:44:28 +08:00
parent 4b6cf1cdce
commit 668e701d6a
9 changed files with 67 additions and 18 deletions

View File

@ -55,7 +55,7 @@ include(generate_product_version)
set(VERSION_MAJOR 3)
set(VERSION_MINOR 1)
set(VERSION_PATCH 1)
set(VERSION_PATCH 2)
set(VERSION_REVISION 0)
add_subdirectory(include)

View File

@ -98,3 +98,4 @@
#define PROC_CONN L"process connected %d"
#define PROC_DISCONN L"process disconnected %d"
#define COPYSELECTION L"auto send selected text in textbox to clipboard"
#define FONTSELECT L"Select Font"

View File

@ -98,3 +98,4 @@
#define PROC_CONN L"进程已连接 %d"
#define PROC_DISCONN L"进程已断开连接 %d"
#define COPYSELECTION L"自动将文本框中选取的文本复制到剪贴板"
#define FONTSELECT L"选择字体"

View File

@ -60,8 +60,10 @@ void LunaHost::savesettings()
configs->set("defaultCodepage",Host::defaultCodepage);
configs->set("autoattachexes",autoattachexes);
configs->set("savedhookcontext",savedhookcontext);
configs->set("DefaultFont",defaultFont);
}
void LunaHost::loadsettings(){
defaultFont=configs->get("DefaultFont",std::wstring(DefaultFont));
check_toclipboard_selection=configs->get("ToClipboardSelection",false);
check_toclipboard=configs->get("ToClipboard",false);
autoattach=configs->get("AutoAttach",false);
@ -166,7 +168,7 @@ LunaHost::LunaHost(){
configs=new confighelper;
loadsettings();
setfont(25);
setfont(25,defaultFont.c_str());
btnshowsettionwindow=new button(this, BtnShowSettingWindow);
g_selectprocessbutton =new button(this,BtnSelectProcess) ;
@ -504,6 +506,18 @@ Settingwindow::Settingwindow(LunaHost* host):mainwindow(host){
};
g_codepage->setminmax(0,CP_UTF8);
showfont=new lineedit(this);
showfont->settext(host->defaultFont);
showfont->setreadonly(true);
selectfont=new button(this,FONTSELECT);
selectfont->onclick=[=](){
FontSelector(winId,host->defaultFont, [=](const std::wstring& _t){
showfont->settext(_t);
host->defaultFont=_t;
host->setfont(25,_t.c_str());
});
};
mainlayout=new gridlayout();
mainlayout->addcontrol(new label(this,LblFlushDelay),0,0);
mainlayout->addcontrol(g_timeout,0,1);
@ -522,7 +536,8 @@ Settingwindow::Settingwindow(LunaHost* host):mainwindow(host){
mainlayout->addcontrol(autoattach,6,0,1,2);
mainlayout->addcontrol(autoattach_so,7,0,1,2);
mainlayout->addcontrol(readonlycheck,8,0,1,2);
//mainlayout->addcontrol(copyselect,9,0,1,2);
mainlayout->addcontrol(showfont,9,1);
mainlayout->addcontrol(selectfont,9,0);
setlayout(mainlayout);
setcentral(600,500);

View File

@ -24,6 +24,8 @@ class Settingwindow:public mainwindow{
spinbox* spinmaxbuffsize;
spinbox* spinmaxhistsize;
gridlayout* mainlayout;
lineedit* showfont;
button* selectfont;
public:
Settingwindow(LunaHost*);
};
@ -111,6 +113,7 @@ public:
int64_t currentselect=0;
bool check_toclipboard;
bool check_toclipboard_selection;
std::wstring defaultFont;
bool autoattach;
bool autoattach_savedonly;
std::set<std::string>autoattachexes;

View File

@ -1,5 +1,6 @@
#include"controls.h"
#include"window.h"
#include<commdlg.h>
control::control(mainwindow*_parent){
if(_parent==0)return;
parent=_parent;
@ -186,7 +187,6 @@ listview::listview(mainwindow* parent,bool _addicon,bool notheader):control(pare
if(notheader)style|=LVS_NOCOLUMNHEADER;
winId=CreateWindowEx(0, WC_LISTVIEW, NULL, style , 0,0,0,0, parent->winId, NULL,NULL, NULL);
ListView_SetExtendedListViewStyle(winId, LVS_EX_FULLROWSELECT); // Set extended styles
setfont(22);
if(addicon){
hImageList = ImageList_Create(22,22, //GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
ILC_COLOR32, 1 ,1);
@ -398,3 +398,17 @@ void Menu::add_sep(){
menu_callbacks.push_back({MF_SEPARATOR});
}
FontSelector::FontSelector(HWND hwnd,const std::wstring& init,std::function<void(const std::wstring&)>callback){
CHOOSEFONTW cf;
ZeroMemory(&cf, sizeof(CHOOSEFONTW));
cf.lStructSize = sizeof(CHOOSEFONTW);
cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS | CF_EFFECTS;
LOGFONT lf;
wcscpy_s(lf.lfFaceName,init.c_str());
cf.hwndOwner = hwnd;
cf.lpLogFont = &lf;
if (ChooseFontW(&cf))
{
callback(lf.lfFaceName);
}
}

View File

@ -27,6 +27,7 @@ class control:public basewindow{
virtual void dispatch_2(WPARAM wParam, LPARAM lParam);
maybehavemenu menu;
std::function<maybehavemenu()> on_menu=[]()->maybehavemenu{return {};};
};
class button:public control{
@ -139,4 +140,9 @@ public:
gridlayout(int row=0,int col=0);
void setmargin(int m=10);
};
class FontSelector{
public:
FontSelector(HWND hwnd,const std::wstring& init,std::function<void(const std::wstring&)>callback);
};
#endif

View File

@ -10,13 +10,25 @@ HICON GetExeIcon(const std::wstring& filePath) {
}
return hIcon;
}
void basewindow::setfont(int sz,LPCWSTR fn){
void mainwindow::visfont(){
if(hfont==0)hfont=parent->hfont;
if(hfont){
for(auto ctr:controls){
SendMessage(ctr->winId, WM_SETFONT, (LPARAM)hfont, TRUE);
}
}
}
void mainwindow::setfont(int sz,LPCWSTR fn){
if(fn==0)fn=DefaultFont;
hfont=CreateFont(sz, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
DEFAULT_CHARSET , OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, fn);
SendMessage(winId, WM_SETFONT, (WPARAM)hfont, TRUE);
visfont();
for(auto child:childrens){
child->setfont(sz,fn);
}
}
std::wstring basewindow::text(){
int textLength = GetWindowTextLength(winId);
@ -44,14 +56,7 @@ LRESULT mainwindow::wndproc(UINT message, WPARAM wParam, LPARAM lParam){
case WM_SHOWWINDOW:
{
on_show();
if(hfont==0)hfont=parent->hfont;
if(hfont)
EnumChildWindows(winId, [](HWND hwndChild, LPARAM lParam)
{
if(0==SendMessage(hwndChild, WM_GETFONT, 0, 0))
SendMessage(hwndChild, WM_SETFONT, lParam, TRUE);
return TRUE;
}, (LPARAM)hfont);
visfont();
break;
}
case WM_SIZE:
@ -171,6 +176,8 @@ mainwindow::mainwindow(mainwindow* _parent){
);
winId = hWnd;
parent=_parent;
if(parent)
parent->childrens.push_back(this);
SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)this);
}
void mainwindow::show(){

View File

@ -3,19 +3,21 @@
class control;
class basewindow{
public:
HFONT hfont=0;
HWND winId;
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&);
void setfont(int,LPCWSTR fn=0);
operator HWND(){return winId;}
};
class mainwindow:public basewindow{
HFONT hfont=0;
public:
void setfont(int,LPCWSTR fn=0);
void visfont();
std::vector<control*>controls;
std::vector<mainwindow*>childrens;
mainwindow* parent;
HWND lastcontexthwnd;
control* layout;