初级会员

- 积分
- 170
- 金钱
- 170
- 注册时间
- 2013-10-27
- 在线时间
- 12 小时
|
发表于 2014-8-20 08:06:38
|
显示全部楼层
回复【8楼】lzw520:
---------------------------------
GUI_MessageBox()是不是死机还是出不来,我没有调试,不清楚。我单独测试GUI_MessageBox还想可以执行,不知道是不是多对话框处理不好的问题。
/*********************************************************************
* *
* SEGGER Microcontroller GmbH & Co. KG *
* Solutions for real time microcontroller applications *
* *
**********************************************************************
* *
* C-file generated by: *
* *
* GUI_Builder for emWin version 5.22 *
* Compiled Jul 4 2013, 15:16:01 *
* (c) 2013 Segger Microcontroller GmbH & Co. KG *
* *
**********************************************************************
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
*/
#include "DIALOG.h"
#include "MyTask.h"
#define FILE_PATH_MAX 150
static WM_HWIN hWin_parent;
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00)
#define ID_TREEVIEW_0 (GUI_ID_USER + 0x01)
static void OpenFileProcess(WM_HWIN hWin,u8* path)
{
if(strstr((char*)path,".txt")||strstr((char*)path,".TXT")
||strstr((char*)path,".c")||strstr((char*)path,".C")
||strstr((char*)path,".cpp")||strstr((char*)path,".CPP")
||strstr((char*)path,".h")||strstr((char*)path,".H"))//判断是否可以使用txt格式打开
{
TEXTReader(hWin,path);
}
else if(strstr((char*)path,".bmp")||strstr((char*)path,".BMP")||
strstr((char*)path,".jpg")||strstr((char*)path,".JPG")||
strstr((char*)path,".png")||strstr((char*)path,".PNG")||
strstr((char*)path,".gif")||strstr((char*)path,".GIF"))
{
/* 显示图片 */
// ImageReader_FrameWin((char*)path);
}
else if(strstr((char*)path,".mp3")||strstr((char*)path,".MP3")
||strstr((char*)path,".wav")||strstr((char*)path,".WAV"))
{
GUI_MessageBox("Sorry,do not support open the file!","Sorry",GUI_MESSAGEBOX_CF_MOVEABLE);
}
else
{
GUI_MessageBox("Sorry,do not support open the file!","Sorry",GUI_MESSAGEBOX_CF_MOVEABLE);
}
}
/************************************************************************************
*函数: ScanFiles
*作者: alan
*日期: 2014.07.07
*参数: path:遍历路径名
hFile:记录文件路径的文件指针结构体
*返回: None
*描述: 遍历此文件夹及子文件夹下所有文件
************************************************************************************/
static FRESULT ScanFiles(char* path,WM_HWIN hTree, TREEVIEW_ITEM_Handle hNode,FILE_TYPE fileType,u32 *fileNum,u8 treeflag)
{
FRESULT res;
FILINFO fno;
DIR dir;
UINT rw;
int i;
char *fn; /* This function is assuming non-Unicode cfg. */
TREEVIEW_ITEM_Handle hItem;
#if _USE_LFN
static char lfn[FILE_PATH_MAX]={0}; /* Buffer to store the LFN */
fno.lfname = lfn;
fno.lfsize = sizeof(lfn);
#endif
res = f_opendir(&dir, (const TCHAR*)path); /* Open the directory */
if (res == FR_OK)
{
i = strlen((const char*)path);
for (;;)
{
res = f_readdir(&dir, &fno); /* Read a directory item */
if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
if (fno.fname[0] == '.') continue; /* Ignore dot entry */ //忽略上级目录
#if _USE_LFN
fn = *fno.lfname ? fno.lfname: fno.fname;
#else
fn = fno.fname;
#endif
if (fno.fattrib & AM_DIR) /* It is a directory */
{
if(hTree != NULL && hNode != NULL && treeflag)
{
//目录,创建结点
hItem = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_NODE,fn,0);
//把结点加入到目录树中
TREEVIEW_AttachItem(hTree,hItem,hNode,TREEVIEW_INSERT_FIRST_CHILD);
}
else
{
hItem=hNode;
}
//在路径最后添加文件夹路径名
sprintf(&path, "/%s", fn);
//遍历此新文件夹下的文件
res = ScanFiles(path,hTree,hItem,fileType,fileNum,treeflag);
if (res != FR_OK) break;//打开失败,跳出循环
path = 0;//末尾添加结束字符
}
else /* It is a file. */
{
if(fileType == TEXTFILE )
{
//判断如果不是txt文件,跳出本函数
if(!(strstr(fn,".txt")||strstr(fn,".TXT")
||strstr(fn,".c")||strstr(fn,".C")
||strstr(fn,".cpp")||strstr(fn,".CPP")
||strstr(fn,".h")||strstr(fn,".H")))
{
return res;
}
}
//判断如果不是Image文件,跳出本函数
else if(fileType ==IMAGEFILE)
{
if(!(strstr(fn,".bmp")||strstr(fn,".BMP")||
strstr(fn,".jpg")||strstr(fn,".JPG")||
strstr(fn,".gif")||strstr(fn,".GIF")||
strstr(fn,".png")||strstr(fn,".PNG")))
{
return res;
}
}
/* 根据要求是否创建目录树 */
if(hTree != NULL && hNode != NULL)//创建目录树
{
hItem = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_LEAF,fn,0);//文件,创建树叶
TREEVIEW_AttachItem(hTree,hItem,hNode,TREEVIEW_INSERT_FIRST_CHILD);//把树叶添加到目录树
// (*fileNum)++;//记录文件数目
}
else
{
(*fileNum)++;//记录文件数目
}
}
}
f_closedir(&dir);
}
return res;
}
void Fill_FileList(char *path,WM_HWIN hTree, TREEVIEW_ITEM_Handle hNode,FILE_TYPE fileType,u32 *fileNum,u8 treeflag)
{
TREEVIEW_ITEM_Handle hTreeItem_Flash;
TREEVIEW_ITEM_Handle hTreeItemCur;
static char p_path[FILE_PATH_MAX]={0}; //目录名 指针
// FIL hFile; //文件句柄
FRESULT fres; //返回结果
hTreeItemCur=hNode;
strcpy(p_path,path); //复制目录名到指针
fres = ScanFiles(p_path,hTree,hNode,fileType,fileNum,treeflag); //递归扫描文件
hTreeItem_Flash = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_NODE, "Flash[1:]", 0);
TREEVIEW_AttachItem(hTree, hTreeItem_Flash, hTreeItemCur, TREEVIEW_INSERT_BELOW);
strcpy(p_path,"1:"); //复制目录名到指针
fres = ScanFiles(p_path,hTree,hTreeItem_Flash,fileType,fileNum,treeflag); //递归扫描文件
}
/*********************************************************************
*
* _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ FRAMEWIN_CreateIndirect, "FileBrower", ID_FRAMEWIN_0, 0, 0, 240, 320, 0, 0x64, 0 },
// { TREEVIEW_CreateIndirect, "Treeview", ID_TREEVIEW_0, 0, 0, 230, 293, 0, 0x0, 0 },
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
void get_pathname(WM_HWIN hTree,TREEVIEW_ITEM_Handle hNode,int level,u8* path)
{
int i;
u8 len=0;
static TREEVIEW_ITEM_Handle hparent[50]={0};//最大50级目录
static u8 hItemname[100]={0};
hparent[level]=hNode;//先保存最后一级的句柄
//获取各级句柄
for(i=level;i>0;i--)
{
hparent[i-1]=TREEVIEW_GetItem(hTree, hparent, TREEVIEW_GET_PARENT);//父句柄
}
//先判断根目录
TREEVIEW_ITEM_GetText(hparent[0],hItemname,99);
if(0==strcmp((char*)hItemname,"SDCard[0:]"))
{
sprintf((char*)path,"%s","0:");
}
else if(0!=strcmp((char*)hItemname,"Flash[1:]"))
{
sprintf((char*)path,"%s","1:");
}
else
{
sprintf((char*)path,"%s",hItemname);
}
//根据句柄获取文本
for(i=1;i<=level;i++)
{
TREEVIEW_ITEM_GetText(hparent,hItemname,99);
len=strlen((char*)path);
sprintf((char*)(path+len),"/%s",hItemname);
}
}
/*********************************************************************
*
* _cbDialog
*/
static void _cbDialog(WM_MESSAGE * pMsg) {
TREEVIEW_ITEM_INFO ItemInfo;
TREEVIEW_ITEM_Handle hNode;
WM_HWIN hItem;
int NCode;
int Id;
u8 *pathname;
GUI_HMEM hMem_pathname;
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
//
// Initialization of 'FileBrower'
//
hItem = pMsg->hWin;
FRAMEWIN_SetFont(hItem, &GUI_FontHZ16);
FRAMEWIN_SetTitleHeight(hItem, 20);
FRAMEWIN_SetText(hItem, "FileBrower");
FRAMEWIN_AddCloseButton(hItem, FRAMEWIN_BUTTON_RIGHT, 0);
FRAMEWIN_AddMaxButton(hItem, FRAMEWIN_BUTTON_RIGHT, 1);
FRAMEWIN_AddMinButton(hItem, FRAMEWIN_BUTTON_RIGHT, 2);
FRAMEWIN_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
FRAMEWIN_SetTextColor(hItem, 0x00000000);
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) {
case ID_TREEVIEW_0: // Notifications sent by 'Treeview'
/* 查看选中了哪个项目 */
hNode = TREEVIEW_GetSel(pMsg->hWinSrc);
/* 获取该项目的信息 */
TREEVIEW_ITEM_GetInfo(hNode,&ItemInfo);
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
if(ItemInfo.IsNode == 0)//点击的是目录树的叶子(即文件)
{
hMem_pathname = GUI_ALLOC_AllocZero(FILE_PATH_MAX);
pathname = GUI_ALLOC_h2p(hMem_pathname);
hItem=WM_GetDialogItem(pMsg->hWin, ID_TREEVIEW_0);
get_pathname(hItem,hNode,ItemInfo.Level,pathname);
printf("\r\n%s\r\n",pathname);
GUI_ALLOC_Free(hMem_pathname);
//调用打开文件相应的程序
OpenFileProcess(pMsg->hWinSrc,pathname);
}
break;
case WM_NOTIFICATION_MOVED_OUT:
break;
case WM_NOTIFICATION_SEL_CHANGED:
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
*   ublic code
*
**********************************************************************
*/
/*********************************************************************
*
* CreateFileBrower
*/
void CreateFileBrower(WM_HWIN hWin,u8 treeflag);
void CreateFileBrower(WM_HWIN hWin,u8 treeflag)
{
WM_HWIN hFileBrower;//浏览器窗口
WM_HWIN hFileBrowerC;//浏览器客户区窗口
WM_HWIN hTree;//树形窗口
TREEVIEW_ITEM_Handle hTreeItemCur;
TREEVIEW_ITEM_Handle hTreeItem_SDCard;
u32 FileNum=0;
hWin_parent=hWin;
hFileBrower = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
hFileBrowerC = WM_GetClientWindow(hFileBrower);/* 获取框架窗口用户区的句柄 */
hTree = TREEVIEW_CreateEx(0, 0,
WM_GetWindowSizeX(hFileBrowerC),
WM_GetWindowSizeY(hFileBrowerC),
hFileBrowerC,
WM_CF_SHOW,
0,
ID_TREEVIEW_0);
SCROLLBAR_CreateAttached(hTree,0);//水平滚动条
SCROLLBAR_CreateAttached(hTree,SCROLLBAR_CF_VERTICAL);//垂直
// TREEVIEW_SetAutoScrollV(hTree, 1); //使用自动滑动条
// TREEVIEW_SetAutoScrollH(hTree, 1); //使用自动滑动条
TREEVIEW_SetSelMode(hTree, TREEVIEW_SELMODE_ROW);
TREEVIEW_SetFont(hTree,&GUI_FontHZ16);
hTreeItemCur = TREEVIEW_GetItem(hTree, 0, TREEVIEW_GET_LAST);
hTreeItem_SDCard = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_NODE, "SDCard[0:]", 0);
TREEVIEW_AttachItem(hTree, hTreeItem_SDCard, hTreeItemCur, TREEVIEW_INSERT_BELOW);
Fill_FileList("0:",hTree,hTreeItem_SDCard,ALLFILE,&FileNum,treeflag);
}
/*************************** End of file ****************************/
上面有GUI_MessageBox,执行后就死了。 |
|