#include<windows.h>
#include<windowsx.h>
#include<wchar.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<CommCtrl.h>
#include<io.h>
//多了的自行删除
#define Multiline_Edit 125
//插入入代码段 :
//第一步 :准备好 入口函数 WinMain()
//第二步:在 case WM_CREATE: 下
// Initial_MultilineEdit(hWnd, 430, 10, 400, 480);//坐标随意
// listFiles("C:\\Users\\123456\\Desktop\\大佬",hWnd);
void listFiles(LPCSTR dir , HWND h_wnd)//文件遍历
{
char dirNew[200];
wchar_t re[100];
strcpy_s(dirNew,200, dir);
strcat_s(dirNew,200, "\\*.*");
intptr_t handle;
struct _finddata_t findData;
handle = _findfirst(dirNew, &findData);
if (handle == -1)
return;
do
{
if (findData.attrib & _A_SUBDIR)
{
if (strcmp(findData.name, ".") == 0 || strcmp(findData.name, "..") == 0)
continue;
Edit_NextInsert(GetDlgItem(h_wnd, Multiline_Edit), A2WString(findData.name, re));
wmemset(re,'\0', sizeof(re)/sizeof(wchar_t));
strcpy_s(dirNew, 200, dir);
strcat_s(dirNew, 200, "\\");
strcat_s(dirNew, 200, findData.name);
listFiles(dirNew,h_wnd);
}
else {
Edit_NextInsert(GetDlgItem(h_wnd, Multiline_Edit), A2WString(findData.name, re));
wmemset(re, '\0', sizeof(re) / sizeof(wchar_t));
}
//printf("%s \t %d bytes.\n",findData.name,findData.size);
} while (_findnext(handle, &findData) == 0);
_findclose(handle);
}
HWND Initial_MultilineEdit(HWND h_wnd,int i_x,int i_y,int i_w,int i_h)//创建多行Edit
{
TCHAR text[] = L"等待输入....\n";//供测试使用
HWND h_edit = CreateWindowEx(
0, L"EDIT", // predefined class
NULL, // no window title
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER |
ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
i_x, i_y, i_w, i_h, // set size in WM_SIZE message
h_wnd, // parent window
(HMENU)Multiline_Edit, // edit control ID
(HINSTANCE)GetWindowLongPtr(h_wnd, GWLP_HINSTANCE),
NULL); // pointer not needed
return h_edit;
}
void Edit_NextInsert(HWND h_edit,LPCTSTR text) //在下一行插入
{
SendMessage(h_edit, EM_SETSEL, -2, -1);
Edit_ReplaceSel(h_edit, text);
}
wchar_t* A2WString(const char* str, wchar_t* re)//char 转换到 wchar_t
{
int num = MultiByteToWideChar( //第一次调用获取转换后大小
CP_ACP,//转换格式
0,//默认转换方式
str,//输入字节
-1,//字符串大小
0,//输出地址
0 //输出空间大小 你不知道大小!
);
if (num <= 0) return L"";
wchar_t* data; data = (wchar_t*)calloc(num + 1, sizeof(wchar_t));
//data = L"";
num = MultiByteToWideChar(
CP_ACP,
0,
str,
-1,
data,
num
);
if (num > 0 && data!=0) swprintf(re, 100, L"%s\n",data);
free(data);
data = NULL;
return re;
}