Files
PathEditor/src/utils.c
T
Serendipity fd9dca924a feat(ui): 为路径列表添加斑马纹样式并移除横线分隔符
- 新增 refresh_list_style 函数,根据行号奇偶性设置交替背景色
- 在列表加载、新增、删除、上下移动条目时自动刷新样式
- 移除原有的横线分隔符,使界面更简洁
- 调整主函数中控制台编码设置的位置
2026-03-16 17:44:38 +08:00

61 lines
1.6 KiB
C

#include "utils.h"
#include "globals.h"
#include <stdio.h>
#include <stdlib.h>
#include <iup.h>
// 宽字符转UTF-8 (用于IUP显示)
char *wide_to_utf8(const wchar_t *wstr)
{
if (!wstr)
return NULL;
int size_needed = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
char *str = (char *)malloc(size_needed);
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, size_needed, NULL, NULL);
return str;
}
// UTF-8转宽字符 (用于Windows API)
wchar_t *utf8_to_wide(const char *str)
{
if (!str)
return NULL;
int size_needed = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
wchar_t *wstr = (wchar_t *)malloc(size_needed * sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0, str, -1, wstr, size_needed);
return wstr;
}
// 检查管理员权限
int check_admin()
{
HKEY hKey;
LONG result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", 0, KEY_WRITE, &hKey);
if (result == ERROR_SUCCESS)
{
RegCloseKey(hKey);
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");
}
}
}