www.pudn.com > uCOS-uCGUI-FATFs.rar > explore.c, change:2011-11-17,size:7205b


#include "config.h" 
 
 
extern WM_HWIN Back_window; 
LISTVIEW_Handle _hListView; 
WM_HMEM Explore_Dialog; 
WM_HMEM DROP; 
char bookTable[3][20]; 
int n =0; 
 
 
 
/********************************************************************* 
* 
*       Dialog resource 
* 
* This table conatins the info required to create the dialog. 
* It has been created manually, but could also be created by a GUI-builder. 
*/ 
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = { 
    { FRAMEWIN_CreateIndirect, "EXPLPRE",   0,                0,  0,  320,220,FRAMEWIN_CF_MOVEABLE,0}, 
    { LISTVIEW_CreateIndirect,  NULL,       GUI_ID_LISTVIEW0, 11, 49, 290,110,0,0}, 
    { BUTTON_CreateIndirect,   "DELETE",    GUI_ID_BUTTON2,   23, 166,75, 30, 0,0}, 
    { BUTTON_CreateIndirect,   "NEW",       GUI_ID_BUTTON1,   116,166,75, 30, 0,0}, 
    { BUTTON_CreateIndirect,   "OPEN",      GUI_ID_BUTTON0,   208,166,75, 30, 0,0}, 
    { DROPDOWN_CreateIndirect, "C:\\",       GUI_ID_DROPDOWN0, 11, 19, 290,80, 0,0} 
}; 
 
 
/********************************************************************* 
* 
*       static code 
* 
********************************************************************** 
*/ 
 
 //char *www[1]={"Welcome"}; 
 
 
 
/********************************************************************* 
**      FunctionName:void InitDialog(WM_MESSAGE * pMsg) 
**      Function: to initialize the Dialog items 
**                                                       
**      call this function in _cbCallback --> WM_INIT_DIALOG 
*********************************************************************/ 
 
void InitExploreDialog(WM_MESSAGE * pMsg) 
{ 
    //char i; 
    WM_HWIN hWin = pMsg->hWin; 
    //static const char * _lvTable_00[3] ={"ffff" , "dddd" , "6666" }; 
    // 
    //FRAMEWIN 
    // 
    FRAMEWIN_SetTitleHeight(hWin,15); 
    FRAMEWIN_SetFont(hWin,&GUI_Font8x16); 
    FRAMEWIN_AddCloseButton(hWin, FRAMEWIN_BUTTON_RIGHT, 0); 
    FRAMEWIN_AddMaxButton(hWin, FRAMEWIN_BUTTON_RIGHT, 1); 
    FRAMEWIN_AddMinButton(hWin, FRAMEWIN_BUTTON_RIGHT, 2); 
    // 
     LISTVIEW_SetDefaultGridColor(GUI_BLACK); 
     LISTVIEW_SetGridVis(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0),1); 
     SCROLLBAR_CreateAttached(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0), SCROLLBAR_CF_VERTICAL); 
      
    //GUI_ID_LISTVIEW0 
 
    _hListView= WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0); 
    LISTVIEW_AddColumn(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0),86,"File Name",GUI_TA_VCENTER|GUI_TA_CENTER); 
    LISTVIEW_AddColumn(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0),64,"Size (KB)",GUI_TA_VCENTER|GUI_TA_CENTER); 
    LISTVIEW_AddColumn(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0),148,"Path",GUI_TA_VCENTER|GUI_TA_CENTER); 
 
 
    //GUI_ID_DROPDOWN0 
    // 
    DROP=WM_GetDialogItem(hWin,GUI_ID_DROPDOWN0); 
    DROPDOWN_SetAutoScroll(WM_GetDialogItem(hWin,GUI_ID_DROPDOWN0),1); 
   // DROPDOWN_AddString(WM_GetDialogItem(hWin,GUI_ID_DROPDOWN0),"C:\\"); 
    //DROPDOWN_AddString(WM_GetDialogItem(hWin,GUI_ID_DROPDOWN0),"C:\BMP\\"); 
    DROPDOWN_SetSel(WM_GetDialogItem(hWin,GUI_ID_DROPDOWN0),1); 
   /* for(i=0;i<n;i++) 
    { 
        LISTVIEW_AddRow(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0),0); 
        LISTVIEW_SetItemText(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0), 0,i, bookTable[i][0]); 
    }*/ 
    
 
 
 
} 
 
 
  
 
/********************************************************************* 
* 
*       Dialog callback routine 
*********************************************************************/ 
static void _cbCallback(WM_MESSAGE * pMsg)  
{ 
    int NCode, Id; 
    WM_HWIN hWin = pMsg->hWin; 
    switch (pMsg->MsgId)  
    { 
       case WM_INIT_DIALOG: 
         InitExploreDialog(pMsg); 
         break; 
       case WM_KEY: 
        switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key)  
        { 
          case GUI_KEY_ESCAPE: 
            GUI_EndDialog(hWin, 1); 
            break; 
          case GUI_KEY_ENTER: 
            GUI_EndDialog(hWin, 0); 
            break; 
        } 
        break; 
      case WM_NOTIFY_PARENT: 
        Id = WM_GetId(pMsg->hWinSrc);    /* Id of widget */ 
        NCode = pMsg->Data.v;               /* Notification code */ 
        switch (NCode)  
        { 
          case WM_NOTIFICATION_RELEASED:    /* React only if released */ 
                 switch(Id) 
                { 
                    case GUI_ID_BUTTON0 : 
                        LISTVIEW_SetItemText(WM_GetDialogItem(hWin,GUI_ID_LISTVIEW0), 0, 0, "wertfs"); 
                    break; 
                    case GUI_ID_BUTTON1 : 
                        LISTVIEW_SetItemTextColor(LISTVIEW_GetHeader(_hListView),0,0,LISTVIEW_CI_UNSEL,GUI_RED); 
                    break; 
                } 
          break; 
        } 
        break; 
     default: 
        WM_DefaultProc(pMsg); 
    } 
} 
 
void getDiv() //从存储器读取文件目录到bookTable中 
{ 
    FATFS fs;                                   /*  文件系统对象结构体           */ 
    DIR dir;                                     /* 声明目录结构体,保存要打开的 */ 
                                               /* 文件夹信息                   */  
    FILINFO fno;                                /*  文件状态结构体               */ 
    FRESULT res; 
    int i=0; 
	MSD_SPI_Configuration(); 
 
	if( _card_insert() == 0 ) 
    { 
	  //printf("-- SD card detected OK \r\n"); 
    } 
    else 
    { 
      //printf("-- Please connect a SD card \r\n"); 
      while( _card_insert() != 0 ); 
      //printf("-- SD card connection detected \r\n"); 
	  //Delay(0xffffff); 
    } 
 
	f_mount(0,&fs);	 
     if(f_opendir(&dir,"0:") == FR_OK) 
     {   /* 打开\folder\zlgmcu文件夹成功   */  
        while(f_readdir(&dir, &fno) == FR_OK) 
        {     /* 读目录信息到文件状态结构体中 */ 
            if(!fno.fname[0])  
                break;                /* 如果文件名为0,结束*/ 
            if(fno.fattrib == AM_ARC )  
            {                     
                LISTVIEW_AddRow(_hListView,0); 
                LISTVIEW_SetItemText(_hListView, 0,i, fno.fname); 
                i++; 
            } 
            if(fno.fattrib == AM_DIR) 
            { 
                 DROPDOWN_AddString(DROP,fno.fname);  
            } 
        }  
    } 
 
        
        
      // err = f_mount(0, &fs);  
      /*  FS_DIR *dirp; 
        struct FS_DIRENT *direntp; 
         
        FS_Init(); 
        //FS_MkDir("\\My_test"); 
        dirp = FS_OpenDir("mmc:");  
        if (dirp)  
        { 
                
            direntp = FS_ReadDir(dirp); 
             while (direntp) 
             {   
                strcpy(bookTable[0], direntp->d_name); 
                strcpy(bookTable[1], (char*)(n+48)); 
                strcpy(bookTable[2], "nothing"); 
                LISTVIEW_AddRow(_hListView,0); 
                LISTVIEW_SetItemText(_hListView, 0,n, bookTable[0]); 
                direntp = FS_ReadDir(dirp); 
                ++n; 
            } 
            FS_CloseDir(dirp); 
        }   
       FS_Exit();*/ 
}    
 
void CreateExplore(void) 
{ 
     //用来存储电子书列表项 
     
     
     
    Explore_Dialog=GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, Back_window, 0, 0); 
    getDiv(); 
     
 
}