diff --git a/include/utils.h b/include/utils.h index b4aba0e..dd775a6 100644 --- a/include/utils.h +++ b/include/utils.h @@ -13,4 +13,7 @@ wchar_t* utf8_to_wide(const char* str); // 检查管理员权限 int check_admin(); +// 刷新列表样式(斑马纹) +void refresh_list_style(); + #endif // UTILS_H \ No newline at end of file diff --git a/src/callbacks.c b/src/callbacks.c index 405aaca..770e22f 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -1,6 +1,7 @@ #include "callbacks.h" #include "globals.h" #include "registry.h" +#include "utils.h" #include #include @@ -17,6 +18,8 @@ int btn_new_cb(Ihandle *self) IupSetAttributeId(list_path, "", count, buffer); IupSetInt(list_path, "COUNT", count); IupSetInt(list_path, "VALUE", count); + + refresh_list_style(); } } return IUP_DEFAULT; @@ -63,6 +66,8 @@ int btn_browse_cb(Ihandle *self) IupSetAttributeId(list_path, "", count, value); IupSetInt(list_path, "COUNT", count); IupSetInt(list_path, "VALUE", count); + + refresh_list_style(); } } IupDestroy(filedlg); @@ -77,6 +82,9 @@ int btn_del_cb(Ihandle *self) return IUP_DEFAULT; IupSetAttribute(list_path, "REMOVEITEM", "SELECTED"); + + // 重新刷新,因为删除了中间项,后面的奇偶性变了 + refresh_list_style(); return IUP_DEFAULT; } @@ -101,6 +109,9 @@ int btn_up_cb(Ihandle *self) IupSetAttributeId(list_path, "", selected - 1, buf_curr); IupSetInt(list_path, "VALUE", selected - 1); + + // 刷新样式(虽然颜色不需要变,但为了保险) + refresh_list_style(); return IUP_DEFAULT; } @@ -125,6 +136,8 @@ int btn_down_cb(Ihandle *self) IupSetAttributeId(list_path, "", selected + 1, buf_curr); IupSetInt(list_path, "VALUE", selected + 1); + + refresh_list_style(); return IUP_DEFAULT; } diff --git a/src/main.c b/src/main.c index 44d476a..f9e5676 100644 --- a/src/main.c +++ b/src/main.c @@ -21,14 +21,6 @@ Ihandle *btn_ok, *btn_cancel, *btn_help; // 主函数 int main(int argc, char **argv) { - // 设置控制台编码为UTF-8,防止中文乱码 -#ifdef _WIN32 - system("chcp 65001 > nul"); // 设置控制台编码为UTF-8 - SetConsoleOutputCP(65001); // 设置控制台输出编码 - SetConsoleCP(65001); // 设置控制台输入编码 - _mkdir("records"); -#endif - // 强制设置 UTF8MODE 环境变量,必须在 IupOpen 之前 putenv("IUP_UTF8MODE=YES"); @@ -38,12 +30,11 @@ int main(int argc, char **argv) // 创建列表控件 list_path = IupFlatList(); IupSetAttribute(list_path, "EXPAND", "YES"); - IupSetAttribute(list_path, "HLINE", "YES"); - IupSetAttribute(list_path, "HLINECOLOR", "100 100 100"); // 灰色 IupSetAttribute(list_path, "ITEMPADDING", "5x5"); IupSetAttribute(list_path, "BACKCOLOR", "255 255 255"); IupSetAttribute(list_path, "BORDER", "YES"); IupSetAttribute(list_path, "CANFOCUS", "YES"); + IupSetAttribute(list_path, "HLINE", "NO"); // 禁用横线,使用斑马纹 // IupFlatList 不支持 VISIBLELINES,高度由 EXPAND 和布局决定 // 创建右侧按钮 diff --git a/src/registry.c b/src/registry.c index a29bef8..1b9f6bb 100644 --- a/src/registry.c +++ b/src/registry.c @@ -84,7 +84,10 @@ void load_path() IupSetInt(list_path, "COUNT", count); // 显式设置列表项数量 IupSetInt(list_path, "VALUE", 1); // 选中第一项 - + + // 刷新斑马纹样式 + refresh_list_style(); + char status_msg[100]; sprintf(status_msg, "状态: 已加载 %d 个条目", count); IupSetAttribute(lbl_status, "TITLE", status_msg); diff --git a/src/utils.c b/src/utils.c index d346a8b..8514d69 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,4 +1,5 @@ #include "utils.h" +#include "globals.h" #include #include #include @@ -36,4 +37,25 @@ int check_admin() return 1; } return 0; +} + +// 刷新列表样式(斑马纹) +void refresh_list_style() +{ + if (!list_path) + return; + int count = IupGetInt(list_path, "COUNT"); + for (int i = 1; i <= count; i++) + { + // 奇数行:白色 + // 偶数行:极浅灰色 (245 245 245) + if (i % 2 == 0) + { + IupSetAttributeId(list_path, "ITEMBGCOLOR", i, "245 245 245"); + } + else + { + IupSetAttributeId(list_path, "ITEMBGCOLOR", i, "255 255 255"); + } + } } \ No newline at end of file