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

📄 dic.c

📁 国家ASIC工程中心使用的嵌入式操作系统
💻 C
字号:
#include <stdio.h>
#include <string.h> 

#include "asixwin.h"
#include "asixapp.h"
#include "asix_ed.h"
#include "asix_tb.h"
#include "ctype.h"
#include "sysusr.h"
#include "sysmsg.h"

#include "dic.h"

#include "bitmap.h"

//注册表
TASKDESCRIPTION DictionaryTskDesp = 
{ "字典",	ASIX_APP,	0,	yingyong,	2048,	1,	LCD_WIDTH,	LCD_HEIGHT,	Dic, APP_PRI};

void Dic()
{
	//窗口和控件ID
	U32		mainwin; 
	U32		input; 
	U32		list[LIST_NUM]; 
	U32		scroll; 
	U32		meaning; 
	U32		tskbar; 
	U32		kb; 
	U32		keyboard; 

	//函数变量
	MSG		msg; 
	U8		quit = 0; 
	U8		i = 0; 
	int		j;
	U8		kbflag = 0; 
	char	buffer[INPUT_LEN + 1]; 
	U8		explain[EXPLAIN_LEN], tempexplain[EXPLAIN_LEN]; 
	U8		*point, *temppoint; 
	U8		offset[18], tempoffset[18];   //10\18
	U16		OffsetNum[LIST_NUM + 1 ], tempoffnum[LIST_NUM + 1];  
	S16		row = 1, temprow = 1; 
	S16		dragflag = 0; 
	U16		length; 
	S16		pos; 

	U8      margin = 5;

	memset(buffer, 0x00, INPUT_LEN + 1); 

	//创建按钮
	mainwin = CreateWindow(WNDCLASS_WIN, "字典", WS_OVERLAPPEDWINDOW, 0, 0, LCD_WIDTH, LCD_HEIGHT, 0, 0, NULL); 
	input = CreateWindow(WNDCLASS_EDITOR, NULL, WS_CHILD|ES_SINGLE_REGULAR, margin, 25, LCD_WIDTH - 2*margin, 20, mainwin, 0, NULL);     
	for(i = 0; i < LIST_NUM; i++)
	{
		list[i] = CreateWindow(WNDCLASS_BUTTON, NULL, WS_CHILD|BS_ICON|BS_FLAT|BS_LEFT, margin, (U16)(47 + i*20), LCD_WIDTH - 2*margin - 20, 20, mainwin, 0, NULL);   
	}
	meaning = CreateWindow(WNDCLASS_STATIC, NULL, WS_CHILD|SS_TEXT|SS_BOARD|SS_MULTILINE, margin, 50 + LIST_NUM*20, LCD_WIDTH - 2*margin, 88, mainwin, 0, NULL); 
	tskbar = CreateWindow(WNDCLASS_TSKBAR, NULL, WS_CHILD|TBS_TYPICAL, 0, 0, 0, 0, mainwin, 0, NULL); 
	kb = AddBtn2TskBar(tskbar, NULL, BS_ICON, 20, (char *)zi_jianpan); 

	j = find_explain_e2c(buffer, explain, offset, 0, LIST_NUM, EXPLAIN_LEN, &point, &length, &((U16)row)); 
	scroll = CreateWindow(WNDCLASS_SCROLL, NULL, WS_CHILD|SBS_VERT, LCD_WIDTH - margin - 20, 47, 20, LIST_NUM*20, mainwin, MAKELONG(1, length - LIST_NUM + 1), NULL);  
	if(j != -1 && j != 0)
	{
		//获得偏移
		for(i=0; i< (LIST_NUM + 1); i++)   
		{
			Bytes2Word(OffsetNum + i, offset + i*2); 
		}
		//显示列表
		for(i = 0; i < LIST_NUM; i++)
		{
			SetWindowText(list[i], explain + OffsetNum[i], NULL); 
		}
		//显示解释
		SetWindowText(meaning, explain + OffsetNum[j], NULL); 
	}

	while(!quit)
	{
		ASIXGetMessage(&msg, NULL, 0, 0); 
		switch(msg.message)
		{
			case WM_COMMAND:
				if(msg.lparam == kb)			//点击软键盘按钮,切换软键盘和解释
				{
					if(kbflag == 0)
					{
						DestroyWindow(meaning); 
						keyboard = CreateWindow(WNDCLASS_KEYBD, "", WS_CHILD|KBS_HANDWRITE|0xff, 1, 55 + LIST_NUM*20, 160, 70, mainwin, 0, NULL);  
						SetFocus(input); 
						kbflag = 1; 
					}
					else
					{
						DestroyWindow(keyboard); 
						meaning = CreateWindow(WNDCLASS_STATIC, explain + OffsetNum[j], WS_CHILD|SS_TEXT|SS_BOARD|SS_MULTILINE, margin, 50 + LIST_NUM*20, LCD_WIDTH - 2*margin, 88, mainwin, 0, NULL); 
						kbflag = 0; 
					}
				}
				else
				{
					for(i = 0; i < LIST_NUM; i++)			//判断点击哪个单词并显示解释
					{
						if(msg.lparam == list[i])
						{
							//查找该单词或汉字,并更新显示
							j = find_explain_e2c(explain + OffsetNum[i], tempexplain, tempoffset, 0, LIST_NUM, EXPLAIN_LEN, &temppoint, &length, &((U16)row)); 
							Bytes2Word(tempoffnum + j, tempoffset + j*2); 
							if(kbflag == 1)
							{
								DestroyWindow(keyboard); 
								meaning = CreateWindow(WNDCLASS_STATIC, explain + OffsetNum[j], WS_CHILD|SS_TEXT|SS_BOARD|SS_MULTILINE, margin, 50 + LIST_NUM*20, LCD_WIDTH - 2*margin, 88, mainwin, 0, NULL);  
								kbflag = 0; 
							}
							SetWindowText(meaning, tempexplain + tempoffnum[j], NULL); 
							SetWindowText(input, explain + OffsetNum[i], NULL); 
						}
					}
				}
				break; 
			
			case WM_CHAR:
				if(msg.lparam == input)			//当有输入时给自己发消息
				{
					MSG	tempmsg;

					tempmsg.message = WM_CHAR; 
					tempmsg.lparam = 0; 
					SysSendMessage( GetCurTaskID(), &tempmsg );
				}
				else
				if(msg.lparam == 0)			//收到消息读入input,并查找
				{
					if( isChinese(msg.wparam) || isprint(msg.wparam) || msg.wparam == BACKSPACE)
					{
						GetEditorStr(input, buffer, INPUT_LEN); 
						//查找并显示
						j = find_explain_e2c(buffer, explain, offset, 0, LIST_NUM, EXPLAIN_LEN, &point, &length, &((U16)row)); 
						if(j != -1 && j != 0)
						{
							//获得偏移
							for(i=0; i< (LIST_NUM + 1); i++)
							{
								Bytes2Word(OffsetNum + i, offset + i*2); 
							}
							//显示列表
							for(i = 0; i < LIST_NUM; i++)
							{
								if(i < j)
									SetWindowText(list[i], explain + OffsetNum[i], NULL); 
								else
									SetWindowText(list[i], NULL, NULL); 
							}
							//显示解释
							SetWindowText(meaning, explain + OffsetNum[j], NULL); 
							SetScrollRange(scroll, 1, (U16)(length - LIST_NUM + 1)); 
							SetScrollPos(scroll, (U16)(row + 1), 0, 0); 
						}
					}
				}
				break; 

			case WM_VSCROLL:			//滚动条操作
				if(msg.lparam == scroll)
				{
					switch(msg.wparam)
					{
						case SB_PAGEUP:
							row -= LIST_NUM; 
							pos = -LIST_NUM; 
							if (row < 1)	
							{
								row = 1; 
								pos = 0; 
							}
							break; 
						case SB_PAGEDOWN:
							row += LIST_NUM; 
							pos = LIST_NUM; 
							if (row > (length - LIST_NUM + 1))
							{
								row = (length - LIST_NUM + 1); 
								pos = 0; 
							}
							break; 
						case SB_LINEUP:
							row -= 1; 
							pos = -1; 
							if (row < 1)	
							{
								row = 1; 
								pos = 0; 
							}
							break; 
						case SB_LINEDOWN:
							row += 1; 
							pos = 1; 
							if (row > (length - LIST_NUM + 1))	
							{
								row = (length - LIST_NUM + 1); 
								pos = 0; 
							}
							break; 
						case SB_THUMBTRACK:
							dragflag = 1; 
							break; 
						case SB_ENDSCROLL:
							temprow = row; 
							row = GetScrollPos(scroll,0,0,0); 
							pos = row - temprow; 
							dragflag = 0; 
							break;
					}
					if(!dragflag)
					{
						j = find_explain_e2c(explain + OffsetNum[0], explain, offset, pos, LIST_NUM, EXPLAIN_LEN, &point, &length, &((U16)row)); 
						if(j != -1 && j != 0)
						{
							//获得偏移
							for(i = 0; i < (LIST_NUM + 1); i++)
							{
								Bytes2Word(OffsetNum + i, offset + i*2); 
							}
							//显示列表
							for(i = 0; i < LIST_NUM; i++)
							{
								if(i < j)
									SetWindowText(list[i], explain + OffsetNum[i], NULL); 
								else
									SetWindowText(list[i], NULL, NULL); 
							
							  
							}
							//显示解释
							SetWindowText(meaning, explain + OffsetNum[j], NULL); 
                            
							SetWindowText(input, explain + OffsetNum[0], NULL); 
                            						
							SetScrollRange(scroll, 1, (U16)(length - LIST_NUM + 1)); 
							SetScrollPos(scroll, (U16)(row + 1), 0, 0); 			// 滚动条拖动定位
						}
					}
				}
				break; 
				
			case WM_QUIT:
				quit = 1; 
				break; 
		}
		DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam); 
	}
	DestroyWindow( mainwin ); 
	EndofTask(); 
	return; 
}

⌨️ 快捷键说明

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