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

📄 image.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 "image.h"


BOOL CreatePageImage(const char* objstring)
{
	BOOL nReturn;
	int Position_left,Position_top,Position_right,Position_bottom;
	char* AcImage_ImageName;
	unsigned long AcImage_dwForeColor,AcImage_dwBackColor;
	BYTE	 AcImage_bStatus;
	unsigned long AcImage_dwTransparenceColor;
	long AcLockRect_left,AcLockRect_top,AcLockRect_right,AcLockRect_bottom;
	int nID;
	
	_INDEX index;
	int pos =OBJECT_LEN;
	
	nReturn = TRUE;
	
	AcImage_ImageName = 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);
	
	// // position bottom
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  {
		nReturn = FALSE; 
		goto FAILED;
	}
	Position_bottom = GetLongVal(objstring,&pos);
	
	
	// active image.	
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=1)  { 
		nReturn = FALSE;
		goto FAILED;
	}
	AcImage_ImageName = GetStringVal(objstring,index._Length,&pos,0);
//	assert(AcImage_ImageName);
	
	
	// fore color.
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  {
		nReturn = FALSE; 
		goto FAILED;
	}
	AcImage_dwForeColor = GetLongVal(objstring,&pos);
	
	// back color.
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  {
		nReturn = FALSE;
		goto FAILED;
	}
	AcImage_dwBackColor = GetLongVal(objstring,&pos);
	
	// status.
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  {
		nReturn = FALSE; 
		goto FAILED;
	}
	AcImage_bStatus = (unsigned char) GetLongVal(objstring,&pos);
	
	// trans color.
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  { 
		nReturn = FALSE;
		goto FAILED;
	}
	AcImage_dwTransparenceColor = GetLongVal(objstring,&pos);
	
	
	// ac lock left
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  { 
		nReturn = FALSE;
		goto FAILED;
	}
	AcLockRect_left = GetLongVal(objstring,&pos);
	
	// ac lock top
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  {
		nReturn = FALSE;
		goto FAILED;
	}
	AcLockRect_top = GetLongVal(objstring,&pos);
	
	// ac lock right 
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  {
		nReturn = FALSE;
		goto FAILED;
	}
	AcLockRect_right = GetLongVal(objstring,&pos);
	
	// ac lock bottom
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  {
		nReturn = FALSE; 
		goto FAILED;
	}
	AcLockRect_bottom = GetLongVal(objstring,&pos);
	
	// ac id
	index = GetIndexInformation(objstring,&pos);
	if(index._Type!=0)  { 
		nReturn = FALSE;
		goto FAILED;
	}
	nID = GetLongVal(objstring,&pos);
	
	image_pointer = Image_Initialize(
		Position_left,
		Position_top,
		Position_right,
		Position_bottom,
		
		AcImage_ImageName,
		AcImage_dwForeColor,					
		AcImage_dwBackColor,
		AcImage_bStatus,				
		AcImage_dwTransparenceColor,
		
		
		AcLockRect_left,
		AcLockRect_top,
		AcLockRect_right,
		AcLockRect_bottom,
		
		nID,					
		g_page
		);
	
	if(level == 0 && page_pointer && image_pointer)
		page_add_image(page_pointer,image_pointer);
	else if(level == 1 && subpage_pointer && image_pointer)
		page_add_image(subpage_pointer,image_pointer);
	
FAILED:
	if(AcImage_ImageName )
		free (AcImage_ImageName);
	
	return nReturn;	
}


Image* Image_Initialize(
					int Position_left,
					int Position_top,
					int Position_right,
					int Position_bottom,

					STRING   AcImage_ImageName,
					COLORREF AcImage_dwForeColor,					
					COLORREF AcImage_dwBackColor,
					BYTE	 AcImage_bStatus,				
					COLORREF AcImage_dwTransparenceColor,


					LONG    AcLockRect_left,
					LONG    AcLockRect_top,
					LONG    AcLockRect_right,
					LONG    AcLockRect_bottom,

					int nID,					
					Page* gpage
					)
{

	Rect Position,AcLockRect;
	ImageItem AcImage;
			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);
	AcLockRect = rect_struct_init(AcLockRect_bottom,AcLockRect_left,AcLockRect_right,AcLockRect_top);

	AcImage = imageitem_struct_init(AcImage_ImageName,AcImage_dwForeColor,AcImage_dwBackColor,AcImage_bStatus,AcImage_dwTransparenceColor);


	return image_struct_init(Position,AcImage,AcLockRect,nID,gpage);

}


Image* image_struct_init(
						 Rect Position,
						 ImageItem ActiveImage,
						 Rect lockposition,
						 int nID,
						 Page* gpage
						 )
{
	Image* p_image;
	int slen;

	p_image=(Image*)malloc(sizeof(Image));
	if( 0 == p_image)
		return 0;
	p_image->m_rPosition=Position;
	p_image->m_rRect = lockposition;

	if(ActiveImage.szImageName  ==NULL)
		slen=0;
	else
		slen = strlen(ActiveImage.szImageName);
	if (slen !=0)
	{
		p_image->m_iiImage.szImageName = (STRING)malloc(slen+1);
		if ( 0 == p_image->m_iiImage.szImageName)
		{
			return 0;
		}
		strcpy(p_image->m_iiImage.szImageName ,ActiveImage.szImageName );		
	}
	else
		p_image->m_iiImage.szImageName =NULL;

	if(ActiveImage.szImageName)
		free (ActiveImage.szImageName );

	p_image->m_iiImage.m_bStatus = ActiveImage.m_bStatus;
	p_image->m_iiImage .m_ulBackColor = ActiveImage.m_ulBackColor;
	p_image->m_iiImage.m_ulForeColor = ActiveImage.m_ulForeColor;
	p_image->m_iiImage.m_ulTransparenceColor = ActiveImage.m_ulTransparenceColor; 

	
	p_image->m_grImageID = 0;
	p_image->m_nID = nID;

	p_image->gpage =gpage;

	return p_image;
}
void image_free_resource (Image* imp)
{
	if(!imp)
		return;
	if(imp->m_iiImage.szImageName)
		free (imp->m_iiImage.szImageName);
	free (imp);
	imp = 0;
	return;
}
void ExposureImage(Image* image)
{
	HDC hdc;
	HWND hWnd;
	BITMAP bitmap;
	int x,y,w,h;

	x = image->m_rPosition.left - image->m_rPosition.left;
	y = image->m_rPosition.top - image->m_rPosition.top;
	w = image->m_rPosition.right - image->m_rPosition.left;
	h = image->m_rPosition.bottom - image->m_rPosition.top;

	hWnd = image->m_grImageID;
	hdc = BeginPaint(hWnd);


	if(image->m_iiImage.szImageName !=NULL)
	{
		LoadBitmap (hdc, &bitmap, image->m_iiImage.szImageName);
		FillBoxWithBitmap(hdc,x,y,w,h,&bitmap);
		UnloadBitmap (&bitmap);
	}

	EndPaint(hWnd,hdc);

}




BOOL RegisterImageminiGUI (void)
{
	WNDCLASS MyClass;
	MyClass.spClassName = IMAGE_MINIGUI;
    MyClass.dwStyle     = WS_NONE;
    MyClass.dwExStyle   = WS_EX_NONE;
    MyClass.hCursor     = GetSystemCursor (IDC_ARROW);
    MyClass.iBkColor    = COLOR_lightwhite;
    MyClass.WinProc     = Image_miniGUIProc;
	return RegisterWindowClass (&MyClass);
	
}
void UnRegisterImageminiGUI (void)
{
	UnregisterWindowClass (IMAGE_MINIGUI);
	
}
int Image_miniGUIProc (HWND hwnd, int message, WPARAM wParam, LPARAM lParam)
{
	switch (message) 
	{
	case MSG_PAINT:
		{
			Image* image;
			WinInfo* info = 0;
			info = (WinInfo*)SearchInfo(hwnd);
			if(!info)
				return 0;
			image = (Image*)info->obj;
			
			ExposureImage(image);
		}
		return 0;
	default:
		break;
		
	}
	return DefaultControlProc (hwnd, message, wParam, lParam);
	
}

⌨️ 快捷键说明

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