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

📄 control.c

📁 S3C44B0X全套培训资料及源代码 e008s3c44b0x
💻 C
📖 第 1 页 / 共 3 页
字号:
		return;		pTextCtrl->text[--i]=0;	if(IsReDraw)		DrawTextCtrl(pTextCtrl);}void SetTextCtrlEdit(PTextCtrl pTextCtrl, U8 bIsEdit){	pTextCtrl->bIsEdit=bIsEdit;}void TextCtrlOnTchScr(PTextCtrl pListCtrl, int x, int y, U32 tchaction){}void	TextCtrlOnKey(PTextCtrl pTextCtrl, int nkey, int fnkey){	static U16 tempbuffer[100]=0;	switch(nkey){	case 11://OK		if(!pTextCtrl->bIsEdit){			UstrCpy(tempbuffer, pTextCtrl->text);			pTextCtrl->text[0]=0;			SetTextCtrlEdit(pTextCtrl, TRUE);			DrawTextCtrl(pTextCtrl);		}		else{			SetTextCtrlEdit(pTextCtrl, FALSE);			DrawTextCtrl(pTextCtrl);		}		break;	case 15://cancel		if(pTextCtrl->bIsEdit){			UstrCpy(pTextCtrl->text,tempbuffer);			SetTextCtrlEdit(pTextCtrl, FALSE);			DrawTextCtrl(pTextCtrl);		}		break;	default:{			U16 charactor=pTextCtrl->KeyTable[nkey];			if(charactor==0 || (!pTextCtrl->bIsEdit))				return;			if(charactor=='\b')				TextCtrlDeleteChar(pTextCtrl, TRUE);			else				AppendChar2TextCtrl(pTextCtrl,charactor,TRUE);		}	}}void OSTextCtrlOnMessage(PTextCtrl pTextCtrl, POSMSG pMsg){	switch(pMsg->Message){	case OSM_TOUCH_SCREEN:		TextCtrlOnTchScr(pTextCtrl, (S16)(pMsg->WParam&0xffff), (S16)(pMsg->WParam>>16), pMsg->LParam);		break;	case OSM_KEY:		if(IsCtrlFocus((POS_Ctrl)pTextCtrl))			TextCtrlOnKey(pTextCtrl, pMsg->WParam,pMsg->LParam);		break;	}}PPictureCtrl CreatePictureCtrl(U32 CtrlID, structRECT* prect,  char filename[], U32 style, PWnd parentWnd){	PPictureCtrl pPicutureCtrl;	pPicutureCtrl=(PPictureCtrl)CreateOSCtrl(CtrlID,CTRLTYPE_PICTURECTRL,prect, NULL,style,parentWnd);	strcpy(pPicutureCtrl->picfilename,filename);	return pPicutureCtrl;}void DestoryPictureCtrl(PPictureCtrl pPictureCtrl){	PList pList=GetCtrlList(pPictureCtrl->parentWnd, pPictureCtrl->CtrlID);	DeleteListNode(pList);	OSMemPut(pCtrlMem, (void*)pPictureCtrl);}void DrawPictureCtrl(PPictureCtrl pPictureCtrl){	structRECT rect;	int tmp,width,height;	PDC pdc;	pdc=GetCtrlParentDC((POS_Ctrl)pPictureCtrl);	if(!pdc)		return;	//清空图片框的显示区域	FillRect2(pdc, &pPictureCtrl->PictureCtrlRect,GRAPH_MODE_NORMAL, COLOR_WHITE);	CopyRect(&rect, &pPictureCtrl->PictureCtrlRect);	switch(pPictureCtrl->style){	case CTRL_STYLE_DBFRAME:		Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0));		InflateRect(&rect, -1,-1);		Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0));		InflateRect(&rect, -1,-1);		Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(0,0,0));		InflateRect(&rect, -1,-1);		Draw3DRect2(pdc, &rect, RGB(255,255,255), RGB(255,255,255));		InflateRect(&rect, -1,-1);		Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(192,192,192));		InflateRect(&rect, -1,-1);		Draw3DRect2(pdc, &rect, RGB(0,0,0), RGB(192,192,192));		break;	case CTRL_STYLE_FRAME:		DrawRectFrame2(pdc,&rect);		break;	case CTRL_STYLE_3DUPFRAME:		Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0));		InflateRect(&rect, -1,-1);		Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(128,128,128));		break;	case CTRL_STYLE_3DDOWNFRAME:		Draw3DRect2(pdc, &rect, RGB(0,0,0),RGB(192,192,192));		InflateRect(&rect, -1,-1);		Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(192,192,192));		break;	case CTRL_STYLE_NOFRAME:		break;	}	InflateRect(&rect, -1,-1);	GetBmpSize(pPictureCtrl->picfilename, &width,&height);	tmp=(rect.bottom-rect.top-height)/2;	if(tmp>0){		rect.top+=tmp;	}	tmp=(rect.right-rect.left-width)/2;	if(tmp>0){		rect.left+=tmp;	}	ShowBmp(pdc, pPictureCtrl->picfilename, rect.left, rect.top);	ReleaseCtrlParentDC((POS_Ctrl)pPictureCtrl);}PWnd CreateWindow(U32 CtrlID, structRECT* prect,  U32 FontSize, U32 style, U16 Caption[], PWnd parentWnd){	PWnd pwnd;	int oldx,oldy;	pwnd=(PWnd)CreateOSCtrl(CtrlID,CTRLTYPE_WINDOW,prect, FontSize,style,parentWnd);	UstrCpy(pwnd->Caption,Caption);	pwnd->ChildWndList.pNextList=NULL;	pwnd->ChildWndList.pPreList=NULL;	pwnd->ChildWndList.pData=NULL;	pwnd->pdc=CreateDC();	pwnd->pdc->WndOrgx=prect->left;	pwnd->pdc->WndOrgy=prect->top;	pwnd->FocusCtrlID=NULL;	pwnd->preParentFocusCtrlID=NULL;	pwnd->bVisible=FALSE;	pwnd->WndDC_Ctrl_mem=OSSemCreate(1);	return pwnd;}void DrawWindow(PWnd pwnd){	PDC pdc;	structRECT rect,rect1;	if(pwnd==NULL){		ReDrawOSCtrl();		return;	}	pdc=GetCtrlParentDC((POS_Ctrl)pwnd);	if(!pdc)		return;	//清空图片框的显示区域	FillRect2(pdc, &pwnd->WndRect,GRAPH_MODE_NORMAL, COLOR_WHITE);	CopyRect(&rect, &pwnd->WndRect);	switch(pwnd->style&0xffff){	case CTRL_STYLE_DBFRAME:		Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0));		InflateRect(&rect, -1,-1);		Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0));		InflateRect(&rect, -1,-1);		Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(0,0,0));		InflateRect(&rect, -1,-1);		break;	case CTRL_STYLE_FRAME:		DrawRectFrame2(pdc,&rect);		break;	case CTRL_STYLE_NOFRAME:		break;	}	InflateRect(&rect, -1,-1);	if(pwnd->style&WND_STYLE_TITLE){		rect1.left=rect.left;		rect1.top=rect.top;		rect1.right=rect.right;		rect1.bottom=rect1.top+GetFontHeight(pwnd->FontSize);		rect.top+=GetFontHeight(pwnd->FontSize)+1;		FillRect2(pdc, &rect1, NULL , COLOR_BLACK);		TextOutRect(pdc, &rect1, pwnd->Caption, TRUE, FONT_BLACKBK,TEXTOUT_MID_Y);	}			CopyRect(&pwnd->ClientRect, &rect);	pwnd->pdc->WndOrgx=rect.left;	pwnd->pdc->WndOrgy=rect.top;	CopyRect(&pwnd->pdc->DrawRect, &rect);	ReleaseCtrlParentDC((POS_Ctrl)pwnd);	ReDrawListOsCtrl(&pwnd->ChildWndList);	}void ShowWindow(PWnd pwnd, BOOLEAN isShow){	if(pwnd->bVisible==isShow)		return;	pwnd->bVisible=isShow;	if(isShow){		//设置焦点到当前窗口		pwnd->preParentFocusCtrlID=SetWndCtrlFocus(pwnd->parentWnd, pwnd->CtrlID);		DrawWindow(pwnd);	}	else{		PDC pdc=CreateDC();		FillRect2(pdc, &pwnd->WndRect,GRAPH_MODE_NORMAL, COLOR_WHITE);		DestoryDC(pdc);		//还原原来的父窗口焦点		SetWndCtrlFocus(pwnd->parentWnd, pwnd->preParentFocusCtrlID);		DrawWindow(pwnd->parentWnd);	}}void WndOnTchScr(PWnd pWnd, int x,int y, U32 tchaction){/*	if(IsInRect(&pWnd->ClientRect, x, y)){		OSCtrlOnTouchScr(&pWnd->ChildWndList, 			x-pWnd->ClientRect.left, y-pWnd->ClientRect.top, tchaction);	}*/}void DestoryWindow(PWnd pWnd){	OS_Ctrl* pCtrl;	PList pOsCtrl=&pWnd->ChildWndList;	ShowWindow(pWnd, FALSE);	while(pOsCtrl->pNextList!= NULL){		pOsCtrl=pOsCtrl->pNextList;		pCtrl=(OS_Ctrl*)pOsCtrl->pData;		if(!(pCtrl->bVisible))			continue;
		switch(pCtrl->CtrlType){		case CTRLTYPE_LISTCTRL://			DrawListCtrl((PListCtrl)pCtrl);			break;		case CTRLTYPE_TEXTCTRL:			DestoryTextCtrl((PTextCtrl)pCtrl);			break;		case CTRLTYPE_PICTURECTRL:			DestoryPictureCtrl((PPictureCtrl)pCtrl);			break;		case CTRLTYPE_WINDOW:			DestoryWindow((PWnd)pCtrl);			break;		case CTRLTYPE_BUTTONCTRL:			DestoryButton((PButtonCtrl)pCtrl);			break;		}	}	DestoryDC(pWnd->pdc);	pOsCtrl=GetCtrlList(pWnd->parentWnd, pWnd->CtrlID);	DeleteListNode(pOsCtrl);	OSMemPut(pCtrlMem, (void*)pWnd);}void OSWndOnMessage(PWnd pWnd, POSMSG pMsg){	OS_Ctrl *pCtrl;	switch(pMsg->Message){	case OSM_TOUCH_SCREEN:		WndOnTchScr(pWnd, (S16)(pMsg->WParam&0xffff), (S16)(pMsg->WParam>>16), pMsg->LParam);		pCtrl=GetCtrlfromID(pWnd, GetWndCtrlFocus(pWnd));		if(pCtrl){			if(pCtrl->CtrlType==CTRLTYPE_WINDOW){				if((((PWnd)pCtrl)->style&WND_STYLE_MODE)==WND_STYLE_MODE){					//焦点是有模式窗口,消息直接传递过去					OSSendAllListMessage(&((PWnd)pCtrl)->ChildWndList, pMsg);					return;				}			}		}		OSSendAllListMessage(&pWnd->ChildWndList, pMsg);		break;	case OSM_KEY:		if(IsCtrlFocus((POS_Ctrl)pWnd))			OSSendAllListMessage(&pWnd->ChildWndList, pMsg);		break;	}}PButtonCtrl CreateButton(U32 CtrlID, structRECT* prect,  U32 FontSize, U32 style, U16 Caption[], PWnd parentWnd){	PButtonCtrl pButton;	pButton=(PButtonCtrl)CreateOSCtrl(CtrlID,CTRLTYPE_BUTTONCTRL,prect, FontSize,style,parentWnd);	UstrCpy(pButton->Caption,Caption);	return pButton;}void DestoryButton(PButtonCtrl pButton){	PList pList=GetCtrlList(pButton->parentWnd, pButton->CtrlID);	DeleteListNode(pList);	OSMemPut(pCtrlMem, (void*)pButton);}void DrawButton(PButtonCtrl pButton){	PDC pdc;	structRECT rect;	pdc=GetCtrlParentDC((POS_Ctrl)pButton);	if(!pdc)		return;	FillRect2(pdc, &pButton->ButtonCtrlRect,GRAPH_MODE_NORMAL, COLOR_WHITE);	CopyRect(&rect, &pButton->ButtonCtrlRect);	Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0));	InflateRect(&rect, -1,-1);	Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0));	InflateRect(&rect, -1,-1);	Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(0,0,0));	InflateRect(&rect, -1,-1);	CopyRect(&pButton->ClientRect, &rect);	TextOutRect(pdc, &rect, pButton->Caption, TRUE, pButton->FontSize,TEXTOUT_MID_Y|TEXTOUT_MID_X);	ReleaseCtrlParentDC((POS_Ctrl)pButton);}void ButtonOnTchScr(PButtonCtrl pButtonCtrl, int x, int y, U32 tchaction){	POSMSG pMsg;	structRECT rect;	CopyRect(&rect, &pButtonCtrl->ClientRect);	Client2Screen(pButtonCtrl->parentWnd, &rect);	if(IsInRect(&rect,x,y)){			PDC pdc;			structRECT rect;			CopyRect(&rect, &pButtonCtrl->ButtonCtrlRect);			pdc=GetCtrlParentDC((POS_Ctrl)pButtonCtrl);			switch(tchaction){			case TCHSCR_ACTION_UP:				Draw3DRect2(pdc,&rect, RGB(192,192,192), RGB(0,0,0));				InflateRect(&rect, -1, -1);				Draw3DRect2(pdc,&rect,RGB(192,192,192), RGB(128,128,128));				pMsg=OSCreateMessage((POS_Ctrl)pButtonCtrl->parentWnd, 					OSM_BUTTON_CLICK, pButtonCtrl->CtrlID, NULL);				SendMessage(pMsg);				break;			case TCHSCR_ACTION_DOWN:				Draw3DRect2(pdc,&rect, RGB(0,0,0), RGB(192,192,192));				InflateRect(&rect, -1, -1);				Draw3DRect2(pdc,&rect, RGB(128,128,128),RGB(192,192,192));				break;			}			ReleaseCtrlParentDC((POS_Ctrl)pButtonCtrl);	}}void OSButtonCtrlOnMessage(PButtonCtrl pButtonCtrl, POSMSG pMsg){	switch(pMsg->Message){	case OSM_TOUCH_SCREEN:		ButtonOnTchScr(pButtonCtrl, (S16)(pMsg->WParam&0xffff), (S16)(pMsg->WParam>>16), pMsg->LParam);		break;	case OSM_KEY://		onKey(pMsg->WParam,pMsg->LParam);		break;	}}

⌨️ 快捷键说明

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