⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dict.c

📁 The combined demo is dedicated for S1C33L05, so DMT33L05 should be used to load and run the demo. F
💻 C
字号:
//      Copyright (C) SEIKO EPSON CORP. 2004 
//
//      GROUP					: SEE LSI
//      FILE                    : sndplayer.c
//      MODULE                  : g723.1 player
//      Function description    : application 
//      Revision history        :                                                                                               
//                                Date            userName        	Description
//                                2004/06/14       David.Ji		      	start
//
//      Notes                   : 
//
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
// Include files (#include)
//---------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ros33.h"
#include "sysGUI.h"
#include "appres.h"
#include "comFS.h"


#define IDC_EDIT1     100
#define IDC_STATIC1   110
#define	IDC_LISTBOX1  120
#define	IDC_TOOLBAR1  130
#define	IDC_TOOLBAR2  140

#define IDC_BAR       501
#define	IDC_BAR_NOTE  502
#define IDC_BAR_GO	  503
#define	IDC_BAR_PRE   504
#define	IDC_BAR_NEXT  505
#define	IDC_BAR_EXIT  506

#define	BARITEM       5	  

T_EXTERN T_BYTE	bDictWnd_exist;

typedef struct t_DictItem{
	unsigned char strWord[20];
	unsigned char strFile[20];
}T_DICT_ITEM;

typedef struct t_DictIndex{
	unsigned int uiCount;
	unsigned int uiPos;
	T_DICT_ITEM* pstItem; 
}T_DICT_INDEX;

T_MODULE T_WORD Dict_IndexParse(T_UBYTE *, T_DICT_INDEX*);
T_MODULE T_WORD Dict_Search(T_UBYTE *, T_DICT_INDEX*);
T_MODULE T_WORD Dict_OutInfo(T_UBYTE *, T_GUI_HWND);
T_MODULE T_WORD Dict_FreeRes();
T_MODULE T_WORD Dict_InitRes();
/******************************************************************
 * FUNCTION: DictWinProc(
 *
 * PURPOSE:
 *		dict win proc
 *
 * PARAMETERS
 *    Input:
 *    Output:
 *    InOut:
 *
 * Return value:
 *
 * Reentrant : No
*****************************************************************/
T_BYTE* pButtonDict[5];

T_WORD DictWinProc(T_GUI_HWND hWnd, T_WORD message, T_GUI_WPARAM wParam, T_GUI_LPARAM lParam)
{
	T_MODULE T_GUI_HWND hChildWnd1, hChildWnd2, hChildWnd3, hChildWnd4, hChildWnd5;
	T_MODULE T_GUI_ToolBarItemInfo  pData;
	T_MODULE T_GUI_Bitmap *pButtonBmptmp[5];

	T_MODULE T_DICT_INDEX stDictIndex;
	T_MODULE T_WORD CurSel;

	//resource
	T_MODULE T_GUI_HICON hIcon;
	T_MODULE T_BYTE InitRes = 0;
	T_MODULE T_BYTE* pIconBuf;

	T_FS_FILECTL stDictFileCtl;
	struct find_t stfind; 
	
	T_BYTE tempString[20];
	
    switch (message)
    {
		case MSG_CREATE:
		{
		T_GUI_HDC hdc;
		T_GUI_ListBoxItemInfo  lbii;
		T_WORD i;

		hdc = fnGUI_BeginPaint(hWnd);
		
		hChildWnd1 = fnGUI_CreateWindow (CTRL_TOOLBAR,
		                                 "",
                        				 WS_CHILD | WS_VISIBLE,
                                         IDC_TOOLBAR1,
                                         2,4,29,50,hWnd, 0);
       	hChildWnd2 = fnGUI_CreateWindow (CTRL_TOOLBAR,
		                                 "",
                        				 WS_CHILD | WS_VISIBLE,
                                         IDC_TOOLBAR2,
                                         112,4,139,50,hWnd, 0);
        
        if(Dict_InitRes() != 1)
        {
        	for(i =0; i<BARITEM; i++)	
        		pButtonDict[i]=	(T_BYTE*)pSysButton;
        }
        else	
        	InitRes = 1;
        
        for(i=0;i<BARITEM;i++)
        {
        	pButtonBmptmp[i] = (T_GUI_Bitmap *) calloc(1,sizeof(T_GUI_Bitmap));
            fnGUI_LoadBitmapFromBmpMemory(hdc,pButtonBmptmp[i],pButtonDict[i]);
            pData.Bmp = pButtonBmptmp[i];
            pData.ItemHint = NULL;
            pData.Caption = NULL ;
            pData.dwAddData = 0 ;
            pData.ItemType = TYPE_BMPITEM ;
       	
        	if(i == 0)
        	{
        		pData.InsPos = 0;
            	pData.id = IDC_BAR+1;
            	fnGUI_SendMessage(hChildWnd1,MSG_TB_ADDITEM,0, (T_GUI_LPARAM)&pData);
            }
            else
            {	pData.InsPos = i+1;
            	pData.id = IDC_BAR+i+1;
	            fnGUI_SendMessage(hChildWnd2,MSG_TB_ADDITEM,0, (T_GUI_LPARAM)&pData);
	        }


        }
		
		hChildWnd3 = fnGUI_CreateWindow (CTRL_EDIT,
              							 "Input",
                                         WS_CHILD | WS_VISIBLE | WS_BORDER |WS_TABSTOP
			                             | STY_EDIT_LEFT | STY_EDIT_BASELINE,
                                         IDC_EDIT1,
                                         32, 4, 80, 25, hWnd, 0);
		
		hChildWnd4 = fnGUI_CreateWindow (CTRL_STATIC,
              							 "",
                                         WS_CHILD | WS_VISIBLE | WS_BORDER
                                         | STY_STATIC_LEFT,
                                         IDC_STATIC1,
                                         82, 32, 171, 154, hWnd, 0);
        
        hChildWnd5 = fnGUI_CreateWindow (CTRL_LISTBOX,
              							 "Listbox",
                                         WS_VISIBLE | WS_BORDER | STY_LB_NOTIFY 
			                             | STY_LB_USEICON | WS_VSCROLL,
                                         IDC_LISTBOX1,
                                         2, 32, 81, 154, hWnd, 0);
                                         
        
        pIconBuf = (T_BYTE *)ComFS_Loadfile("system\\dictlist.ico");
        if(pIconBuf == 0)
 	        hIcon = fnGUI_LoadIconFromMemory ( hdc, pSysIcon,1);
        else
        	hIcon = fnGUI_LoadIconFromMemory ( hdc, pIconBuf,0);
        
       	
        if(ComFS_FindFirst("dict\\dict.idx", _A_NORMAL, &stfind) != FS_SUCCESS)
		{
			fnGUI_EndPaint(hWnd,hdc);
			break;
		}

		memcpy(stDictFileCtl.strFileName, "dict\\dict.idx",14);
        stDictFileCtl.ulReqLen = stfind.size;
		stDictFileCtl.pFileData = (T_BYTE* )malloc( stDictFileCtl.ulReqLen+1);

		if(ComFS_ReadFile( &stDictFileCtl) == FS_SUCCESS)
		{
			*(stDictFileCtl.pFileData+stDictFileCtl.ulTranLen) = 0x00; //end of string
			Dict_IndexParse(stDictFileCtl.pFileData, &stDictIndex);
		}
		
		free (stDictFileCtl.pFileData);
		
 		for(i = 0; i< stDictIndex.uiCount-1; i++)
 		{
			lbii.CMFlag = FLAG_CM_BLANK;
			lbii.string = stDictIndex.pstItem[i].strWord;
			lbii.hIcon = hIcon;
			fnGUI_SendMessage (	hChildWnd5,	MSG_LB_ADDSTRING, 0, (T_GUI_LPARAM)&lbii);
		}
		fnGUI_SetFocus(hChildWnd3);
		
		fnGUI_EndPaint(hWnd,hdc);
		
        CurSel=0;
 		}
		break;
		
    	case MSG_PAINT:
		break;
    	
        case MSG_COMMAND:
        {
        	T_WORD code = LOHWORD(wParam);
            T_WORD id = HIHWORD(wParam);
            T_WORD len, sel;
            T_BYTE input[20];
            
            switch (id)
            {
            case IDC_BAR_NOTE:
            fnGUI_SendMessage ( hChildWnd3, MSG_SETTEXT, 0, (T_GUI_LPARAM)"");
            break;	
            	
            case IDC_BAR_GO:
            {
            	memset(input, 0x0, 20);
            	len = fnGUI_SendMessage ( hChildWnd3, MSG_GETTEXTLENGTH, 0, 0);
            	fnGUI_SendMessage ( hChildWnd3, MSG_GETTEXT, (T_GUI_WPARAM)len, (T_GUI_LPARAM)input);
				
				sel = Dict_Search(input, &stDictIndex);
				
				if(sel == -1)
				{	
					fnGUI_SendMessage ( hChildWnd4, MSG_SETTEXT, 0, (T_GUI_LPARAM)"Sorry, no found");
					break;
				}
				
				CurSel = sel;				
				
				if(Dict_OutInfo(stDictIndex.pstItem[CurSel].strFile, hChildWnd4) != TRUE)
				{
	            	fnGUI_SendMessage ( hChildWnd4, MSG_SETTEXT, 0, (T_GUI_LPARAM)"Sorry, no found");
	            	break;
	            }
	            	
     			fnGUI_SendMessage( hChildWnd5, MSG_LB_SETCURSEL, (T_GUI_WPARAM)CurSel, 0);
            }	
            break;
            
            case IDC_BAR_PRE:
            	CurSel --;
            	if(CurSel == -1)
            		CurSel = 0;
            	fnGUI_SendMessage (hChildWnd5, MSG_LB_SETCURSEL, (T_GUI_WPARAM)CurSel, 0);
            	Dict_OutInfo(stDictIndex.pstItem[CurSel].strFile, hChildWnd4);
            break;
            
            case IDC_BAR_NEXT:
            	CurSel ++;
            	if(CurSel > stDictIndex.uiCount)
            		CurSel == stDictIndex.uiCount;
            	fnGUI_SendMessage (hChildWnd5, MSG_LB_SETCURSEL, (T_GUI_WPARAM)CurSel, 0);
            	Dict_OutInfo(stDictIndex.pstItem[CurSel].strFile, hChildWnd4);
            break;
            	
            case IDC_BAR_EXIT:
               	fnGUI_PostMessage (hWnd, MSG_CLOSE, 0, 0);
            break;
        	}
        	
        	/* check listbox item message */
            /* note, code&id exchanged    */
        	if((code == IDC_LISTBOX1) && (id ==SIG_LB_SELCHANGE))
            {
		       	sel = fnGUI_SendMessage (hChildWnd5, MSG_LB_GETCURSEL, 0, 0);
		       	if(sel == CurSel)
		       		break;
		       	
		       	CurSel = sel;
		       	Dict_OutInfo(stDictIndex.pstItem[CurSel].strFile, hChildWnd4);
                	break;
		    }
		    
		    /* RETURN KEY */
		    if((code == IDC_EDIT1) && (id == SIG_EDIT_ENTER))
		    {
           		memset(input, 0x0, 20);
            	len = fnGUI_SendMessage ( hChildWnd3, MSG_GETTEXTLENGTH, 0, 0);
            	fnGUI_SendMessage ( hChildWnd3, MSG_GETTEXT, (T_GUI_WPARAM)len, (T_GUI_LPARAM)input);
				
				sel = Dict_Search(input, &stDictIndex);
				
				if(sel == -1)
				{	
					fnGUI_SendMessage ( hChildWnd4, MSG_SETTEXT, 0, (T_GUI_LPARAM)"Sorry, no found");
					break;
				}
				
				CurSel = sel;				
				
				if(Dict_OutInfo(stDictIndex.pstItem[CurSel].strFile, hChildWnd4) != TRUE)
				{
	            	fnGUI_SendMessage ( hChildWnd4, MSG_SETTEXT, 0, (T_GUI_LPARAM)"Sorry, no found");
	            	break;
	            }
	            	
     			fnGUI_SendMessage( hChildWnd5, MSG_LB_SETCURSEL, (T_GUI_WPARAM)CurSel, 0);
		    }
		}	
        break ;
        
        case MSG_TIMER:
		break;
		
        case MSG_CLOSE:
        {
        		T_WORD i;
        		
        		free(stDictIndex.pstItem);
        		free(pIconBuf);
        		fnGUI_DestroyIcon(hIcon);
        		
        		if(InitRes == 1)
        		{
        			Dict_FreeRes();	
        			InitRes = 0;
        		}
        		for(i =0; i<5; i++)
	        		fnGUI_UnLoadBitmap(pButtonBmptmp[i]);
	        	
	        	bDictWnd_exist = 0;
	        	
        		fnGUI_DestroyMainWindow (hChildWnd1);
        		fnGUI_DestroyMainWindow (hChildWnd2);
        		fnGUI_DestroyMainWindow (hChildWnd3);
        		fnGUI_DestroyMainWindow (hChildWnd4);
        		fnGUI_DestroyMainWindow (hChildWnd5);
        		fnGUI_DestroyMainWindow (hWnd);
        }
        break;
    }

    return fnGUI_DefaultMainWinProc(hWnd, message, wParam, lParam);
    
}

/******************************************************************
 * FUNCTION: Dict_IndexParse(
 *
 * PURPOSE:
 *		dict win proc
 *
 * PARAMETERS
 *    Input:
 *    Output:
 *    InOut:
 *
 * Return value:
 *
 * Reentrant : No
*****************************************************************/

T_MODULE T_WORD Dict_IndexParse(T_UBYTE * pBuffer, T_DICT_INDEX* pstIndex)
{
	unsigned char strhead[10], strnum[10];
	T_DICT_ITEM item;
	unsigned int num, i;
	char tempstr[20];
	
	i=0;
	
	sscanf(pBuffer, "%s\t%s\t%d\n", strhead, strnum, &num); 
	if(strcmp(strhead, "dictres"))
		return -1;
	
	if(strcmp(strnum, "wordnum"))
		return -1;
	
	pstIndex->uiCount = num;
	
	pstIndex->pstItem = (T_DICT_ITEM* )calloc(num, sizeof(T_DICT_ITEM));
	
	while (*pBuffer != 0x00)
	{
		if((*pBuffer==0x0D)&&(*(pBuffer+1)==0x0A))
		{
			pBuffer +=2;
			memset(item.strWord, 0x0, 20);
			sscanf(pBuffer, "%s\t%s\n", item.strWord, tempstr);
			sprintf(item.strFile,"dict\\%s",tempstr);
			memcpy(pstIndex->pstItem+i, &item, sizeof(T_DICT_ITEM));
			i++;
		}				
		pBuffer++;
	}
	
	pstIndex->uiPos = 0;
	return 1;
}

/******************************************************************
 * FUNCTION: Dict_Search()
 *
 * PURPOSE:
 *		dict win proc
 *
 * PARAMETERS
 *    Input:
 *    Output:
 *    InOut:
 *
 * Return value:
 *
 * Reentrant : No
*****************************************************************/
T_MODULE T_WORD Dict_Search(T_UBYTE * str, T_DICT_INDEX* pstIndex)
{
	T_WORD i;
	
	for(i =0; i< pstIndex->uiCount; i++)
	{
		if(!strcmp(pstIndex->pstItem[i].strWord, str))
			return i;	
	}
	return -1;
}

/******************************************************************
 * FUNCTION: Dict_OutInfo()
 *
 * PURPOSE:
 *		dict win proc
 *
 * PARAMETERS
 *    Input:
 *    Output:
 *    InOut:
 *
 * Return value:
 *
 * Reentrant : No
*****************************************************************/
T_MODULE T_WORD Dict_OutInfo(T_UBYTE *filename, T_GUI_HWND hWnd)
{
	struct find_t find;
	
	T_BYTE* pfiledata;
	
	if(ComFS_FindFirst(filename, _A_NORMAL, &find) != FS_SUCCESS)
		return FALSE;
	
	pfiledata = (T_BYTE* )malloc( find.size+1);

	pfiledata = (T_BYTE *)ComFS_Loadfile(filename);
	
	if(pfiledata == 0L)
	{
		free(pfiledata);
		return FALSE;
	}

  	*(pfiledata+find.size) = 0x00; //end of string
   	fnGUI_SendMessage( hWnd, MSG_SETTEXT, 0, (T_GUI_LPARAM)pfiledata);
   	free(pfiledata);
   	return TRUE;
}

/******************************************************************
 * FUNCTION: Dict_InitRes()
 *
 * PURPOSE:
 *
 * PARAMETERS
 * Return value:
*****************************************************************/
T_MODULE T_WORD Dict_InitRes()
{
		T_BYTE *pBmpBuf;
				
        pBmpBuf = (char *)ComFS_Loadfile("system\\dictnote.bmp");
        if(pBmpBuf == 0)
        	return -1;
        pButtonDict[0] = pBmpBuf;
        
        pBmpBuf = (char *)ComFS_Loadfile("system\\dictgo.bmp");
        if(pBmpBuf == 0)
        	return -1;
        pButtonDict[1] = pBmpBuf;
        
        pBmpBuf = (char *)ComFS_Loadfile("system\\dictpre.bmp");
        if(pBmpBuf == 0)
        	return -1;
        pButtonDict[2] = pBmpBuf;
        
        pBmpBuf = (char *)ComFS_Loadfile("system\\dictnext.bmp");
        if(pBmpBuf == 0)
        	return -1;
        pButtonDict[3] = pBmpBuf;
        
        pBmpBuf = (char *)ComFS_Loadfile("system\\dictexit.bmp");
        if(pBmpBuf == 0)
        	return -1;
        pButtonDict[4] = pBmpBuf;

		return 1;
	
}

/******************************************************************
 * FUNCTION: Dict_FreeRes()
 *
 * PURPOSE:
 *
 * PARAMETERS
 * Return value:
*****************************************************************/
T_MODULE T_WORD Dict_FreeRes()
{
	T_BYTE i;
	
	for(i=0; i<5; i++)	
		free(pButtonDict[i]);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -