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

📄 label.c

📁 一个minigui 工程框架,需要windows 下的minigui 开发环境
💻 C
字号:
#include "const.h"
#include "resource.h"
#include "project.h"
#include "page.h"
#include "microwin.h"
#include "queue.h"
#include "liaison.h"
#include "label.h"


BOOL CreatePageText(const char* objstring)
{
	BOOL nReturn;
	int Position_left,Position_top,Position_right,Position_bottom;
	char* AcText_szContent,*AcText_LOG_FONT;
	int AcText_bFring,AcText_eLocation;
	unsigned long AcText_dwTextColor;
	int nID;
	
	_INDEX index;
	int pos =OBJECT_LEN;
	
	nReturn = TRUE;
	
	AcText_szContent = 0;
	AcText_LOG_FONT = 0;
	
	// // position left 
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  {
		nReturn = FALSE;
		goto FAILED;
	}
	Position_left = GetLongVal(objstring,&pos);
	
	
	// position top
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  {
		nReturn = FALSE; 
		goto FAILED;
	}
	Position_top = GetLongVal(objstring,&pos);
	
	// position right
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  {
		nReturn = FALSE;
		goto FAILED;
	}
	Position_right = GetLongVal(objstring,&pos);
	
	// postiion bottom
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  {
		nReturn = FALSE; 
		goto FAILED;
	}
	Position_bottom = GetLongVal(objstring,&pos);
	
	// active text
	
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=1)  { 
		nReturn = FALSE; 
		goto FAILED;
	}
	AcText_szContent = GetStringVal(objstring,index._Length,&pos,0);
//	assert(AcText_szContent);
	
	
	// font 
	
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=1)  {
		nReturn = FALSE; 
		goto FAILED;
	}
	AcText_LOG_FONT = GetStringVal(objstring,index._Length,&pos,0);
//	assert(AcText_LOG_FONT);
	
	
	// fring
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  { 
		nReturn = FALSE; 
		goto FAILED;
	}
	AcText_bFring = GetLongVal(objstring,&pos);
	
	// location
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  { 
		nReturn = FALSE;
		goto FAILED;
	}
	AcText_eLocation = GetLongVal(objstring,&pos);
	
	// text color
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  { 
		nReturn = FALSE;
		goto FAILED;
	}
	AcText_dwTextColor = GetLongVal(objstring,&pos);
	
	// id
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  {
		nReturn = FALSE; 
		goto FAILED;
	}
	nID = GetLongVal(objstring,&pos);
	
	
	// finish.
	label_pointer = Label_Initialize(
		Position_left,
		Position_top,
		Position_right,
		Position_bottom,
		AcText_szContent,	
		AcText_LOG_FONT,	
		AcText_bFring,		
		AcText_eLocation,
		AcText_dwTextColor,
		
		nID,					
		g_page
		);
	if(level == 0 && page_pointer && label_pointer)
		page_add_label(page_pointer,label_pointer);
	else if(level == 1 && subpage_pointer && label_pointer)
		page_add_label(subpage_pointer,label_pointer);
FAILED:
	if(AcText_szContent )
		free (AcText_szContent);
	if(AcText_LOG_FONT )
		free (AcText_LOG_FONT);
	
	return nReturn;
}


Label* Label_Initialize(
					int Position_left,
					int Position_top,
					int Position_right,
					int Position_bottom,

					STRING AcText_szContent,	
					LOG_FONT AcText_LOG_FONT,	
					BOOL AcText_bFring,		
					eLocation AcText_eLocation,
					COLORREF AcText_dwTextColor,

					int nID,					
					Page* gpage
			)
{
	Rect Position;
	TextItem AcText;
			if(!(Position_right-Position_left)%2) Position_right+=1;
			if(!(Position_bottom-Position_top)%2) Position_bottom+=1;

	Position = rect_struct_init(Position_bottom,Position_left,Position_right,Position_top);

	AcText = text_struct_init(AcText_szContent,AcText_LOG_FONT,AcText_bFring,AcText_eLocation,AcText_dwTextColor);


	return label_struct_init(Position,AcText,nID,gpage);
}

Label* label_struct_init(
						 Rect position,
						 TextItem ActiveText,
						 int nID,
						 Page* gpage
						 )
{
	Label* p_label;
	int slen;

	p_label=(Label*)malloc(sizeof(Label));
	if( 0 == p_label )
		return 0;
	memset(p_label,0,sizeof(Label));

		
	if(ActiveText.m_szContent == NULL)
		slen = 0;
	else
		slen = strlen(ActiveText.m_szContent);

	if (slen !=0){
		p_label->m_tiActiveText.m_szContent=(STRING)malloc(slen+1);
		if( 0 == p_label->m_tiActiveText.m_szContent)
		{
			return 0;
		}
		strcpy(p_label->m_tiActiveText.m_szContent,ActiveText.m_szContent);
	}
	else
		p_label->m_tiActiveText.m_szContent = NULL;

	if(ActiveText.m_szContent)
		free (ActiveText.m_szContent);

	p_label->m_tiActiveText .m_bFring = ActiveText.m_bFring;
	p_label->m_tiActiveText.m_ulTextColor = ActiveText.m_ulTextColor;
	p_label->m_tiActiveText.m_eLocation = ActiveText.m_eLocation;

	if(ActiveText.m_LogFont == NULL)
		slen =0;
	else
		slen = strlen (ActiveText.m_LogFont);

	if(slen !=0)
	{
		p_label->m_tiActiveText.m_LogFont = (STRING)malloc(slen+1);
		if( 0 == p_label->m_tiActiveText.m_LogFont)
		{
			return 0;
		}	
		strcpy(p_label->m_tiActiveText.m_LogFont ,ActiveText.m_LogFont);
	}
	else
		p_label->m_tiActiveText.m_LogFont = NULL;

	if(ActiveText.m_LogFont)
		free (ActiveText.m_LogFont);

	p_label->m_grLabelID = 0;
//	p_label->gc = 0;


	p_label->m_nID = nID;
	

	p_label->m_rPosition = position;

	p_label->gpage =gpage;

	return p_label;
}

void ExposureLabel(Label* label)
{
	int i,j,index,offset;
	HDC hdc;
	lattice* latt;
	int 	nwidth ,nheight,x,y,width,height,nx,ny;
	eLocation loc;
	unsigned long color;
	int r,g,b;

	
	HWND hWnd = label->m_grLabelID;
	if(!label->m_tiActiveText.m_szContent)	
		return ;
	hdc = BeginPaint (hWnd);
	latt = (lattice*)SearchLattice(atoi(label->m_tiActiveText.m_szContent+1));
	if(!latt)
		return ;
	nwidth= latt->width ;
	nheight = latt->height;
	x = 0;
	y = 0;
	width = label->m_rPosition.right - label->m_rPosition.left;
	height = label->m_rPosition.bottom - label->m_rPosition.top ;
	loc = MIDDLE_CENTER;

	color = label->m_tiActiveText.m_ulTextColor;
	
	r = (int)(color & 0xFF);
	g = (int)((color >>8) & 0xFF);
	b = (int)((color >> 16) & 0xFF);

	switch(loc)
	{
	case UPPER_LEFT:
		{
			nx=x+2;
			ny=y+2;
		}
		break;
	case MIDDLE_LEFT:
		{
			nx=x+2;
			ny = y+(height-nheight)/2;
		}
		break;
	case LOWER_LEFT:
		{
			nx=x+2;
			ny = y+height-nheight-2;
		}
		break;
	case UPPER_CENTER:
		{
			nx = (width-nwidth)/2+x;	
			ny=y+2;
		}
		break;
	case MIDDLE_CENTER:
		{
			nx = (width-nwidth)/2+x;	
			ny = (height-nheight)/2+y;	
		}
		break;
	case LOWER_CENTER:
		{
			nx = (width-nwidth)/2+x;	
			ny = y+height-nheight-2;
		}
		break;
	case UPPER_RIGHT:
		{
			nx = width-nwidth+x-2;		
			ny=y+2;
		}
		break;
	case MIDDLE_RIGHT:
		{
			nx = width-nwidth+x-2;
			ny = y+(height-nheight)/2;
		}
		break;
	case LOWER_RIGHT:
		{
			nx = width-nwidth+x-2;
			ny = y+height-nheight-2;
		}		
		break;
	default:
		break;
	}
	if(latt)
	{		
		for (j = 0; j<nheight ; j++)
		{
			for ( i = 0; i<nwidth; i++)
			{
				index = (j*nwidth +i)/8;
				offset = 1<<((j*nwidth +i)%8);
				if(latt->pResdata[index] & offset)
				{
					SetPixel(hdc,i+nx,j+ny,(unsigned long)RGBA2Pixel(hdc,r,g,b,0xFF));	
										
				}
			}
		}
	}
	
	EndPaint(hWnd,hdc);
	return ;
}

void label_free_resource (Label* lbp)
{
	if(!lbp)
		return ;
	if(lbp ->m_tiActiveText .m_szContent)
		free (lbp->m_tiActiveText.m_szContent);
	free (lbp);
	lbp = 0;
	return;
}
extern BOOL RegisterLabelminiGUI (void)
{
	WNDCLASS MyClass;
	MyClass.spClassName = LABEL_MINIGUI;
    MyClass.dwStyle     = WS_NONE;
    MyClass.dwExStyle   = WS_EX_NONE;
    MyClass.hCursor     = GetSystemCursor (IDC_ARROW);
    MyClass.iBkColor    = COLOR_lightwhite;
    MyClass.WinProc     = Label_miniGUIProc;
	return RegisterWindowClass (&MyClass);

}
extern void UnRegisterLabelminiGUI (void)
{
	UnregisterWindowClass (LABEL_MINIGUI);
}

extern int Label_miniGUIProc (HWND hwnd, int message, WPARAM wParam, LPARAM lParam)
{
	switch (message) 
	{
	case MSG_PAINT:
		{
			Label* label;
			WinInfo* info = 0;
			info = (WinInfo*)SearchInfo(hwnd);
			if(!info)
				return 0;
			label = (Label*)info->obj;
			ExposureLabel(label);
		}
		break;
	default:
		break;

	}
	return DefaultControlProc (hwnd, message, wParam, lParam);
}

⌨️ 快捷键说明

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