📄 mv_skindlg.cpp
字号:
/*
unsigned char *CMv_skinDlg::bmp_file_parse( FILE *p_file, int *file_size,int *img_w, int *img_h)
{
bmp_file_header_t f_h;
bmp_info_header_t b_h;
mtk_file_header_t custom_f_h;
int bmp_w, bmp_h, bmp_bc;
int tb_size,image_size;
unsigned int total_size;
int custom_w_h;
unsigned char *p_store_file,*p_tmp;
fseek(p_file, 0, SEEK_END); //定位到文件末
total_size = ftell(p_file); //文件长度
if(total_size <= sizeof(f_h)+sizeof(b_h))
{
MessageBox("文件格式错误", NULL, MB_ICONWARNING);
return NULL;
}
rewind(p_file);
fread(&f_h, sizeof(f_h), 1, p_file); //get file header
fread(&b_h, sizeof(b_h), 1, p_file); //get bitmap info header
if(0x4D42!=f_h.bf_type || 0!=f_h.bf_reserved1 || 0!=f_h.bf_reserved2 || 1!=b_h.bi_planes
||(total_size != f_h.bf_size))
{
MessageBox("文件格式错误", NULL, MB_ICONWARNING);
return NULL;
}
bmp_w = b_h.bi_width;
bmp_h = b_h.bi_height;
bmp_bc = b_h.bi_bitcount;
if( ( 1!=bmp_bc && 4!=bmp_bc && 8!=bmp_bc && 16!=bmp_bc && 24!=bmp_bc && 32!=bmp_bc )
||( 0!=b_h.bi_compression ) )
{
MessageBox("文件格式错误", NULL, MB_ICONWARNING);
return NULL;
}
switch(bmp_bc)
{
case 1: tb_size=2; break;
case 4: tb_size=16; break;
case 8: tb_size=256; break;
default: tb_size=0; break;
}
if(0 != tb_size)
{
unsigned char color_tb[256*sizeof(rgb_color_table_t)]={0};
if(0 != b_h.bi_clrused)
{
tb_size = b_h.bi_clrused;
}
tb_size *= sizeof(rgb_color_table_t);
if(total_size < sizeof(f_h)+sizeof(b_h)+tb_size)
{
MessageBox("文件格式错误", NULL, MB_ICONWARNING);
return NULL;
}
fread(color_tb, tb_size, 1, p_file); //get color table
}
image_size = ((((bmp_w*bmp_bc) + 31) & ~31) / 8) * bmp_h;
custom_w_h = (((bmp_w & 0XFFF) << 12) | (bmp_h & 0XFFF));
custom_f_h.file_type = BMP_FILE;
custom_f_h.frame_count = 1;
custom_f_h.file_len_low = (image_size&0xff);
custom_f_h.file_len_mid = ((image_size>>8)&0xff);
custom_f_h.file_len_high = ((image_size>>16)&0xff);
custom_f_h.width_height_low = (custom_w_h&0xff);
custom_f_h.width_height_mid = ((custom_w_h>>8)&0xff);
custom_f_h.width_height_high = ((custom_w_h>>16)&0xff);
p_store_file = (unsigned char *)malloc(image_size+sizeof(mtk_file_header_t));
if( NULL == p_store_file )
{
MessageBox("内存不够", NULL, MB_ICONWARNING);
return NULL;
}
p_tmp = p_store_file;
//store custom file header
memcpy(p_tmp, &custom_f_h, sizeof(mtk_file_header_t));
p_tmp += sizeof(mtk_file_header_t);
//store bmp file data
rewind(p_file);
fseek(p_file, f_h.bf_offbits, SEEK_SET);
fread(p_tmp, image_size, 1, p_file);
*file_size = image_size + sizeof(mtk_file_header_t);
return p_store_file;
}
*/
/*-----------------------------------------------------------
* FUNCTION NAME: draw_img
* DESCRIPTION:
* judge draw image
* ARGUMENTS:
*
* Return:
* FALSE:no draw TRUE:draw
* Note:
*
*------------------------------------------------------------*/
BOOL CMv_skinDlg::draw_img(int img_index)
{
BOOL ret = FALSE;
if((img_index < IMG_ID_MVPLY_AUDIO_BG) || (img_index >= IMG_ID_MVPLY_END))
{
return ret;
}
switch(img_index)
{
case IMG_ID_MVPLY_AUDIO_BG:
case IMG_ID_MVPLY_OSD_INFO_PANNEL:
case IMG_ID_MVPLY_OSD_CNTL_PANNEL:
case IMG_ID_MVPLY_OSD_BAR_RIGHT:
{
ret = TRUE;
}
break;
case IMG_ID_MVPLY_OSD_CNTL_BRIGHTNESS:
case IMG_ID_MVPLY_OSD_CNTL_BRIGHTNESS_P:
case IMG_ID_MVPLY_OSD_CNTL_BRIGHTNESS_G:
{
if( img_index == (button_state+IMG_ID_MVPLY_OSD_CNTL_BRIGHTNESS))
{
ret = TRUE;
}
}
break;
case IMG_ID_MVPLY_OSD_CNTL_CONTRAST:
case IMG_ID_MVPLY_OSD_CNTL_CONTRAST_P:
case IMG_ID_MVPLY_OSD_CNTL_CONTRAST_G:
{
if( img_index == (button_state+IMG_ID_MVPLY_OSD_CNTL_CONTRAST))
{
ret = TRUE;
}
}
break;
case IMG_ID_MVPLY_OSD_CNTL_PLAY:
case IMG_ID_MVPLY_OSD_CNTL_PLAY_P:
case IMG_ID_MVPLY_OSD_CNTL_PLAY_G:
{
if( img_index == (button_state+IMG_ID_MVPLY_OSD_CNTL_PLAY))
{
ret = TRUE;
}
}
break;
case IMG_ID_MVPLY_OSD_CNTL_PAUSE:
case IMG_ID_MVPLY_OSD_CNTL_PAUSE_P:
case IMG_ID_MVPLY_OSD_CNTL_PAUSE_G:
{
if( img_index == (button_state+IMG_ID_MVPLY_OSD_CNTL_PAUSE))
{
ret = TRUE;
}
}
break;
case IMG_ID_MVPLY_OSD_CNTL_STOP:
case IMG_ID_MVPLY_OSD_CNTL_STOP_P:
case IMG_ID_MVPLY_OSD_CNTL_STOP_G:
{
if( img_index == (button_state+IMG_ID_MVPLY_OSD_CNTL_STOP))
{
ret = TRUE;
}
}
break;
case IMG_ID_MVPLY_OSD_CNTL_PREVIOUS:
case IMG_ID_MVPLY_OSD_CNTL_PREVIOUS_P:
case IMG_ID_MVPLY_OSD_CNTL_PREVIOUS_G:
{
if( img_index == (button_state+IMG_ID_MVPLY_OSD_CNTL_PREVIOUS))
{
ret = TRUE;
}
}
break;
case IMG_ID_MVPLY_OSD_CNTL_NEXT:
case IMG_ID_MVPLY_OSD_CNTL_NEXT_P:
case IMG_ID_MVPLY_OSD_CNTL_NEXT_G:
{
if( img_index == (button_state+IMG_ID_MVPLY_OSD_CNTL_NEXT))
{
ret = TRUE;
}
}
break;
case IMG_ID_MVPLY_OSD_CNTL_ZOOM:
case IMG_ID_MVPLY_OSD_CNTL_ZOOM_P:
case IMG_ID_MVPLY_OSD_CNTL_ZOOM_G:
{
if( img_index == (button_state+IMG_ID_MVPLY_OSD_CNTL_ZOOM))
{
ret = TRUE;
}
}
break;
case IMG_ID_MVPLY_OSD_CNTL_BOOK:
case IMG_ID_MVPLY_OSD_CNTL_BOOK_P:
case IMG_ID_MVPLY_OSD_CNTL_BOOK_G:
{
if( img_index == (button_state+IMG_ID_MVPLY_OSD_CNTL_BOOK))
{
ret = TRUE;
}
}
break;
case IMG_ID_MVPLY_OSD_CNTL_AUDIO:
case IMG_ID_MVPLY_OSD_CNTL_AUDIO_P:
case IMG_ID_MVPLY_OSD_CNTL_AUDIO_G:
{
if( img_index == (button_state+IMG_ID_MVPLY_OSD_CNTL_AUDIO))
{
ret = TRUE;
}
}
break;
case IMG_ID_MVPLY_OSD_CNTL_PROPERT:
case IMG_ID_MVPLY_OSD_CNTL_PROPERT_P:
case IMG_ID_MVPLY_OSD_CNTL_PROPERT_G:
{
if( img_index == (button_state+IMG_ID_MVPLY_OSD_CNTL_PROPERT))
{
ret = TRUE;
}
}
break;
default:
{
ret = FALSE;
}
break;
}
return ret;
}
/*-----------------------------------------------------------
* FUNCTION NAME: show_jpg_gif
* DESCRIPTION:
* show jpg or gif file
* ARGUMENTS:
* CPaintDC *dc:设备环境对象
* CString file_path:要显示的图片路径
* x,y:要显示的位置
* Return:
*
* Note:
*
*------------------------------------------------------------*/
BOOL CMv_skinDlg::show_jpg_gif(CPaintDC *dc,CString file_path, int x, int y, int w, int h)
{
dc->SetBkMode( TRANSPARENT );
CFile mFile;
LONG nLength;
//1 打开文件并获得文件的真实大小
if ( mFile.Open( file_path,CFile::modeRead )&&( ( nLength = mFile.GetLength() ) > 0 ) )
{
//2 从堆中分配指定数量字节的一整块,这时系统无法提供零零碎碎的局部或全局的堆
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, nLength );
LPVOID pvData = NULL;
if ( hGlobal != NULL )
{
//3 锁定全局内存对象并返回它的首地址
if ( ( pvData = GlobalLock(hGlobal) ) != NULL )
{
//4 把文件内容读进全局内存对象的地址空间中
mFile.Read( pvData, nLength );
mFile.Close();
//5 GlobalUnlock函数把以GMEM_MOVEABLE方式分配的内存对象的锁定计数器减1
GlobalUnlock( hGlobal );
//6 从全局内存中创建stream对象,第二个参数指定当stream释放时是否自动释放全局内存
IStream *pStm;
CreateStreamOnHGlobal( hGlobal, TRUE, &pStm) ;
//7 创建一个新的picture对象并用stream对象中的内容初始化
IPicture *pPic;
if( SUCCEEDED( OleLoadPicture( pStm, nLength, TRUE, IID_IPicture, (LPVOID*)&pPic ) ) )
{
//8 释放不要的stream对象并清空stream指针
pStm->Release();
pStm=NULL;
OLE_XSIZE_HIMETRIC mWidth;
OLE_YSIZE_HIMETRIC mHeight;
//9 得到picture对象中图片的宽和高
pPic->get_Width( &mWidth );
pPic->get_Height( &mHeight );
CRect rc;
GetClientRect( &rc );
double fX,fY;
//10 GetDeviceCaps(HORZRES)得到屏幕的宽度(单位:像素)
// GetDeviceCaps(HORZSIZE)得到屏幕的宽度(单位:毫米)
double h_tmp1,h_tmp2;
double v_tmp1,v_tmp2;
h_tmp1 = (double)dc->GetDeviceCaps(HORZRES);
h_tmp2 = (double)dc->GetDeviceCaps( HORZSIZE );
v_tmp1 = (double)dc->GetDeviceCaps(VERTRES);
v_tmp2 = (double)dc->GetDeviceCaps( VERTSIZE );
fX = (double)dc->GetDeviceCaps(HORZRES) * (double)mWidth / ( (double)dc->GetDeviceCaps( HORZSIZE ) * 100.0 );
fY = (double)dc->GetDeviceCaps(VERTRES) * (double)mHeight / ( (double)dc->GetDeviceCaps( VERTSIZE ) *100.0 );
//11 把图像显示在dc中
if( FAILED( pPic->Render( dc->GetSafeHdc(), x, y, (DWORD)w , (DWORD)h , 0, mHeight, mWidth, -mHeight, NULL ) ) )
{
AfxMessageBox( _T("渲染图片失败") );
return FALSE;
}
/*根据背景大小缩放图片
CRect rcClient;
GetClientRect( &rcClient );
BOOL bWidth = rcClient.Width() / fX > rcClient.Height() / fY;
if ( bWidth )
{
if( FAILED( pPic->Render( dc.GetSafeHdc(), 0, 0, (DWORD)rcClient.Width() , (DWORD)rcClient.Width() * fY / fX , 0, mHeight, mWidth, -mHeight, NULL ) ) )
AfxMessageBox( _T("渲染图片失败") );
}
else
{
if( FAILED( pPic->Render( dc.GetSafeHdc(), 0, 0, (DWORD)rcClient.Height() * fX/ fY, (DWORD)rcClient.Height() , 0, mHeight, mWidth, -mHeight, NULL ) ) )
AfxMessageBox( _T("渲染图片失败") );
}
*/
//12 释放不要的picture对象,并把指针清空
pPic->Release();
pPic=NULL;
//13 释放不要的全局内存对象,这个千万别忘了(32位程序不需要这行,系统会自动释放;16位程序一定要)
FreeResource(hGlobal);
}
else
{
AfxMessageBox( _T("渲染图片失败") );
return FALSE;
}
}
}
else
{
AfxMessageBox( _T("渲染图片失败") );
return FALSE;
}
}
else
{
AfxMessageBox( _T("渲染图片失败") );
return FALSE;
}
return true;
}
void CMv_skinDlg::set_update_area(void)
{
RECT controlRect;
GetDlgItem(IDC_STATIC_LCD_SIZE)->GetWindowRect(&controlRect);
controlRect.left = 0;//222;
controlRect.top = 80;//195;
controlRect.right = 450;//542;
controlRect.bottom = 338;//435;
InvalidateRect(&controlRect);
//Invalidate();
}
BOOL CMv_skinDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return CDialog::OnEraseBkgnd(pDC);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -