c++写一个列表框界面例子
时间: 2023-03-26 21:00:19 浏览: 102
第十二章_列表框和组合框
3星 · 编辑精心推荐
好的,以下是一个简单的列表框界面例子:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ITEMS 10
int main()
{
char items[MAX_ITEMS][20] = {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10"};
int selected_item = ;
int i;
while (1) {
system("clear"); // 清屏
// 打印列表框
printf("┌──────────────────────┐\n");
for (i = ; i < MAX_ITEMS; i++) {
if (i == selected_item) {
printf("│ > %s\n", items[i]);
} else {
printf("│ %s\n", items[i]);
}
}
printf("└──────────────────────┘\n");
// 获取用户输入
char input[10];
printf("\nUse arrow keys to select an item, press Enter to confirm.\n");
fgets(input, 10, stdin);
// 处理用户输入
if (strcmp(input, "\n") == ) {
printf("You selected: %s\n", items[selected_item]);
break;
} else if (strcmp(input, "\e[A") == ) { // Up arrow
selected_item = (selected_item - 1 + MAX_ITEMS) % MAX_ITEMS;
} else if (strcmp(input, "\e[B") == ) { // Down arrow
selected_item = (selected_item + 1) % MAX_ITEMS;
}
}
return ;
}
阅读全文