diff --git a/Makefile b/Makefile index 4b160c3..1da684a 100644 --- a/Makefile +++ b/Makefile @@ -18,9 +18,9 @@ CFLAGS = -Wall -O2 -I$(INCLUDE_DIR) -I$(LOCAL_INCLUDE_DIR) -D_WIN32 -DUNICODE -D LDFLAGS = -L$(LIB_DIR) -liup -liupcd -lgdi32 -lcomdlg32 -lcomctl32 -luuid -lole32 -ladvapi32 -mwindows # Source -SRC = src/main.c src/utils.c src/registry.c src/callbacks.c src/ui.c +SRC = src/main.c src/utils.c src/registry.c src/callbacks.c src/ui.c src/globals.c RES = ico/resources.rc -OBJ = $(OBJ_DIR)/main.o $(OBJ_DIR)/utils.o $(OBJ_DIR)/registry.o $(OBJ_DIR)/callbacks.o $(OBJ_DIR)/ui.o $(OBJ_DIR)/resources.o +OBJ = $(OBJ_DIR)/main.o $(OBJ_DIR)/utils.o $(OBJ_DIR)/registry.o $(OBJ_DIR)/callbacks.o $(OBJ_DIR)/ui.o $(OBJ_DIR)/globals.o $(OBJ_DIR)/resources.o EXE = $(BIN_DIR)/PathEditor.exe all: $(BIN_DIR) $(OBJ_DIR) $(EXE) @@ -49,6 +49,9 @@ $(OBJ_DIR)/callbacks.o: src/callbacks.c $(OBJ_DIR)/ui.o: src/ui.c $(CC) $(CFLAGS) -c -o $@ $< +$(OBJ_DIR)/globals.o: src/globals.c + $(CC) $(CFLAGS) -c -o $@ $< + $(OBJ_DIR)/resources.o: ico/resources.rc $(WINDRES) -i $< -o $@ diff --git a/bin/PathEditor.exe b/bin/PathEditor.exe index 0bce9f1..41babf2 100644 Binary files a/bin/PathEditor.exe and b/bin/PathEditor.exe differ diff --git a/include/config.h b/include/config.h new file mode 100644 index 0000000..670c931 --- /dev/null +++ b/include/config.h @@ -0,0 +1,28 @@ +#ifndef CONFIG_H +#define CONFIG_H + +// ============================================================================ +// UI的配置常量 +// ============================================================================ + +// 对话框设置 +#define UI_DLG_SIZE "500x400" + +// 列表控件设置 +#define UI_LIST_ITEM_PADDING "5x5" +#define UI_LIST_BACKCOLOR "255 255 255" + +// 按钮设置 +#define UI_BTN_RASTERSIZE "100x32" + +// 布局间隙和边距 +#define UI_VBOX_GAP "5" +#define UI_VBOX_MARGIN "0x0" +#define UI_VBOX_ALL_MARGIN "10x10" +#define UI_VBOX_ALL_GAP "5" + +#define UI_HBOX_GAP "10" +#define UI_HBOX_MARGIN "10x10" +#define UI_HBOX_ALIGNMENT "ACENTER" + +#endif // CONFIG_H diff --git a/include/globals.h b/include/globals.h index 85e9949..cb102b7 100644 --- a/include/globals.h +++ b/include/globals.h @@ -3,6 +3,16 @@ #include +// 定义 Windows 消息常量 +#ifndef WM_COPYGLOBALDATA +#define WM_COPYGLOBALDATA 0x0049 +#endif + +// 消息过滤器常量 +#ifndef MSGFLT_ADD +#define MSGFLT_ADD 1 +#endif + // 注册表路径常量 #define REG_PATH_SYS L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" #define REG_PATH_USER L"Environment" diff --git a/src/globals.c b/src/globals.c new file mode 100644 index 0000000..5621e44 --- /dev/null +++ b/src/globals.c @@ -0,0 +1,14 @@ +#include "globals.h" +#include +#include + +// 全局变量定义 +StringList raw_sys_paths = {0}; +StringList raw_user_paths = {0}; + +// 全局控件定义 +Ihandle *dlg, *tabs_main, *list_sys, *list_user, *lbl_status; // 主窗口、标签页、系统路径列表、用户路径列表、状态标签 +Ihandle *btn_new, *btn_edit, *btn_browse, *btn_del, *btn_up, *btn_down; // 右侧按钮 +Ihandle *btn_ok, *btn_cancel, *btn_help; // 确认取消帮助按钮 +Ihandle *btn_clean; // 一键清理按钮 +Ihandle *txt_search; // 搜索框 \ No newline at end of file diff --git a/src/main.c b/src/main.c index b72ff57..b8c795b 100644 --- a/src/main.c +++ b/src/main.c @@ -8,26 +8,7 @@ #include "registry.h" #include "callbacks.h" #include "ui.h" - -// 定义 Windows 消息常量 -#ifndef WM_COPYGLOBALDATA -#define WM_COPYGLOBALDATA 0x0049 -#endif - -#ifndef MSGFLT_ADD -#define MSGFLT_ADD 1 -#endif - -// 全局变量定义 -StringList raw_sys_paths = {0}; -StringList raw_user_paths = {0}; - -// 全局控件定义 -Ihandle *dlg, *tabs_main, *list_sys, *list_user, *lbl_status; // 主窗口、标签页、系统路径列表、用户路径列表、状态标签 -Ihandle *btn_new, *btn_edit, *btn_browse, *btn_del, *btn_up, *btn_down; // 右侧按钮 -Ihandle *btn_ok, *btn_cancel, *btn_help; // 确认取消帮助按钮 -Ihandle *btn_clean; // 一键清理按钮 -Ihandle *txt_search; // 搜索框 +#include "config.h" // 主函数 int main(int argc, char **argv) @@ -80,8 +61,8 @@ int main(int argc, char **argv) // 上部布局:Tabs + 按钮 Ihandle *hbox_main = IupHbox(tabs_main, vbox_btns, NULL); - IupSetAttribute(hbox_main, "GAP", "10"); - IupSetAttribute(hbox_main, "MARGIN", "10x10"); + IupSetAttribute(hbox_main, "GAP", UI_HBOX_GAP); + IupSetAttribute(hbox_main, "MARGIN", UI_HBOX_MARGIN); // 状态标签 lbl_status = IupLabel("状态: 就绪"); @@ -97,13 +78,13 @@ int main(int argc, char **argv) hbox_main, hbox_bottom, NULL); - IupSetAttribute(vbox_all, "MARGIN", "10x10"); - IupSetAttribute(vbox_all, "GAP", "5"); + IupSetAttribute(vbox_all, "MARGIN", UI_VBOX_ALL_MARGIN); + IupSetAttribute(vbox_all, "GAP", UI_VBOX_ALL_GAP); // 创建对话框 dlg = IupDialog(vbox_all); IupSetAttribute(dlg, "TITLE", "编辑环境变量 (IUP版)"); - IupSetAttribute(dlg, "SIZE", "500x400"); // 稍微调大一点 + IupSetAttribute(dlg, "SIZE", UI_DLG_SIZE); // 稍微调大一点 IupSetAttribute(dlg, "MINBOX", "NO"); IupSetAttribute(dlg, "MAXBOX", "NO"); diff --git a/src/ui.c b/src/ui.c index ddfbe94..5cfc21e 100644 --- a/src/ui.c +++ b/src/ui.c @@ -1,6 +1,7 @@ #include "ui.h" #include "globals.h" #include "callbacks.h" +#include "config.h" #include // 创建列表控件 @@ -8,8 +9,8 @@ Ihandle *create_path_list() { Ihandle *list = IupFlatList(); IupSetAttribute(list, "EXPAND", "YES"); - IupSetAttribute(list, "ITEMPADDING", "5x5"); - IupSetAttribute(list, "BACKCOLOR", "255 255 255"); + IupSetAttribute(list, "ITEMPADDING", UI_LIST_ITEM_PADDING); + IupSetAttribute(list, "BACKCOLOR", UI_LIST_BACKCOLOR); IupSetAttribute(list, "BORDER", "YES"); IupSetAttribute(list, "CANFOCUS", "YES"); IupSetAttribute(list, "HLINE", "NO"); @@ -40,14 +41,14 @@ Ihandle *create_main_buttons() IupSetCallback(btn_down, "ACTION", (Icallback)btn_down_cb); IupSetCallback(btn_clean, "ACTION", (Icallback)btn_clean_cb); - // 设置按钮大小 (宽度和高度都增加约1/4) - IupSetAttribute(btn_new, "RASTERSIZE", "100x32"); - IupSetAttribute(btn_edit, "RASTERSIZE", "100x32"); - IupSetAttribute(btn_browse, "RASTERSIZE", "100x32"); - IupSetAttribute(btn_del, "RASTERSIZE", "100x32"); - IupSetAttribute(btn_up, "RASTERSIZE", "100x32"); - IupSetAttribute(btn_down, "RASTERSIZE", "100x32"); - IupSetAttribute(btn_clean, "RASTERSIZE", "100x32"); + // 设置按钮大小 + IupSetAttribute(btn_new, "RASTERSIZE", UI_BTN_RASTERSIZE); + IupSetAttribute(btn_edit, "RASTERSIZE", UI_BTN_RASTERSIZE); + IupSetAttribute(btn_browse, "RASTERSIZE", UI_BTN_RASTERSIZE); + IupSetAttribute(btn_del, "RASTERSIZE", UI_BTN_RASTERSIZE); + IupSetAttribute(btn_up, "RASTERSIZE", UI_BTN_RASTERSIZE); + IupSetAttribute(btn_down, "RASTERSIZE", UI_BTN_RASTERSIZE); + IupSetAttribute(btn_clean, "RASTERSIZE", UI_BTN_RASTERSIZE); Ihandle *vbox_btns = IupVbox( btn_new, btn_edit, btn_browse, btn_del, @@ -56,8 +57,8 @@ Ihandle *create_main_buttons() IupFill(), btn_up, btn_down, NULL); - IupSetAttribute(vbox_btns, "GAP", "5"); - IupSetAttribute(vbox_btns, "MARGIN", "0x0"); + IupSetAttribute(vbox_btns, "GAP", UI_VBOX_GAP); + IupSetAttribute(vbox_btns, "MARGIN", UI_VBOX_MARGIN); return vbox_btns; } @@ -74,14 +75,14 @@ Ihandle *create_bottom_buttons() IupSetCallback(btn_cancel, "ACTION", (Icallback)btn_cancel_cb); IupSetCallback(btn_help, "ACTION", (Icallback)btn_help_cb); - IupSetAttribute(btn_ok, "RASTERSIZE", "100x32"); - IupSetAttribute(btn_cancel, "RASTERSIZE", "100x32"); - IupSetAttribute(btn_help, "RASTERSIZE", "100x32"); + IupSetAttribute(btn_ok, "RASTERSIZE", UI_BTN_RASTERSIZE); + IupSetAttribute(btn_cancel, "RASTERSIZE", UI_BTN_RASTERSIZE); + IupSetAttribute(btn_help, "RASTERSIZE", UI_BTN_RASTERSIZE); Ihandle *hbox_bottom = IupHbox(lbl_status, IupFill(), btn_help, btn_ok, btn_cancel, NULL); - IupSetAttribute(hbox_bottom, "GAP", "10"); - IupSetAttribute(hbox_bottom, "MARGIN", "10x10"); - IupSetAttribute(hbox_bottom, "ALIGNMENT", "ACENTER"); + IupSetAttribute(hbox_bottom, "GAP", UI_HBOX_GAP); + IupSetAttribute(hbox_bottom, "MARGIN", UI_HBOX_MARGIN); + IupSetAttribute(hbox_bottom, "ALIGNMENT", UI_HBOX_ALIGNMENT); return hbox_bottom; } \ No newline at end of file