win32_C_Edit简单操作_文件遍历

#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;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值