📄 mv_skindlg.cpp
字号:
return 1;
switch(lParam)
{
case WM_RBUTTONUP://右键起来时弹出快捷菜单,这里只有一个“关闭”
{
LPPOINT lpoint=new tagPOINT;
::GetCursorPos(lpoint);//得到鼠标位置
CMenu menu;
menu.CreatePopupMenu();//声明一个弹出式菜单
//增加菜单项“关闭”,点击则发送消息WM_DESTROY给主窗口(已
//隐藏),将程序结束。
menu.AppendMenu(MF_STRING,WM_DESTROY,"退出");
//确定弹出式菜单的位置
menu.TrackPopupMenu(TPM_LEFTALIGN,lpoint->x,lpoint->y,this);
//* /*/资源回收
HMENU hmenu=menu.Detach();
menu.DestroyMenu();
delete lpoint;
}
break;
case WM_LBUTTONDBLCLK://双击左键的处理
{
this->ShowWindow(SW_SHOW);//简单的显示主窗口完事儿
}
break;
}
return 0;
}
/*-----------------------------------------------------------
* FUNCTION NAME: process_button
* DESCRIPTION:
* when press button,process it
* ARGUMENTS:
*
* Return:
* void
* Note:
*
*------------------------------------------------------------*/
void CMv_skinDlg::process_button(int edit_index, int img_index)
{
int img_w,img_h,file_type;
char buf[SAVE_PATH_LENGTH+1] = {0};
if ( TRUE == select_file(m_dir_path, buf, img_index, &img_w, &img_h, &file_type) )
{
strcpy(m_file_attr[img_index].name, buf);
m_file_attr[img_index].width = img_w;
m_file_attr[img_index].height = img_h;
m_file_attr[img_index].file_type = file_type;
GetDlgItem(edit_index)->SetWindowText(buf);
}
}
/*-----------------------------------------------------------
* FUNCTION NAME: select_paths
* DESCRIPTION:
* get picture directory path
* ARGUMENTS:
* char *p_path:the dir path
* Return:
* 0:not find ,other is find
* Note:
*
*------------------------------------------------------------*/
int CMv_skinDlg::select_paths(char *p_path)
{
char *title = "请选择目录...";
BROWSEINFO bi;
ITEMIDLIST *pidl;
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = p_path;
bi.lpszTitle = title;
bi.ulFlags = BIF_EDITBOX;
bi.lpfn = NULL;
bi.lParam = 0;
bi.iImage = 0;
pidl = SHBrowseForFolder(&bi);
return (pidl && SHGetPathFromIDList(pidl, p_path));
}
/*-----------------------------------------------------------
* FUNCTION NAME: select_paths
* DESCRIPTION:
* get picture directory path
* ARGUMENTS:
* char *path:the dir path
* Return:
* 0:find file err,1:find file OK
* Note:
*
*------------------------------------------------------------*/
BOOL CMv_skinDlg::select_file(char *p_path, char *p_file_name, int img_index, int *img_w, int *img_h, int *type)
{
LPCTSTR p_path_name,p_get_file_name,p_file_ext;
CString path_name,file_name,file_ext;
int get_img_w,get_img_h,mtk_file_type;
char file_type[5]={0};
char select_path[SAVE_PATH_LENGTH]={0};
char get_path[SAVE_PATH_LENGTH]={0};
FILE *fp_image_file;
BOOL ret=FALSE;
//CString sFilter="所有文件 (*.*) |*.*|图片文件(*.bmp)(*.gif)(*.png)|*.bmp;*.gif;*.png||";
CString sFilter="所有文件 (*.*) |*.*|图片文件(*.bmp)(*.gif)|*.bmp;*.gif||";
strcpy(select_path, p_path);
strcat(select_path, "\\*.*");
CFileDialog DlgFiledialog(TRUE,
NULL,
select_path,
OFN_HIDEREADONLY,
sFilter);
if (DlgFiledialog.DoModal() != IDOK)
{
return FALSE;
}
file_ext = DlgFiledialog.GetFileExt();
p_file_ext = file_ext;
file_ext_convert_down(file_type, p_file_ext);
if((0 != strcmp(file_type, "bmp")) && (0 != strcmp(file_type, "gif")) && (0 != strcmp(file_type, "png")))
{
MessageBox("请选择bmp或gif或png图片", "图片不支持", MB_ICONWARNING);
return FALSE;
}
path_name = DlgFiledialog.GetPathName();
p_path_name = path_name;
strcpy(get_path, p_path_name);//total path
file_name = DlgFiledialog.GetFileName();
p_get_file_name = file_name;
strcpy(select_path, p_path);
strcat(select_path, "\\");
strcat(select_path, p_get_file_name);//total path
if( 0 != strcmp(select_path, p_path_name) )
{
MessageBox("路径错误", NULL, MB_ICONWARNING);
return FALSE;
}
fp_image_file = fopen(get_path,"rb");
if ( NULL == fp_image_file )
{
MessageBox("找不到文件", NULL, MB_ICONWARNING);
fclose(fp_image_file);
return FALSE;
}
if( 0 == strcmp(file_type, "bmp") )
{
mtk_file_type = BMP_FILE;
ret = bmp_file_parse(fp_image_file, img_index, &get_img_w, &get_img_h);
}
else if( 0 == strcmp(file_type, "gif") )
{
mtk_file_type = GIF_FILE;
ret = gif_file_parse(fp_image_file, img_index, &get_img_w, &get_img_h);
}
else if( 0 == strcmp(file_type, "png") )
{
mtk_file_type = PNG_FILE;
ret = png_file_parse(fp_image_file, img_index, &get_img_w, &get_img_h);
}
fclose(fp_image_file);
if( TRUE == ret )
{
*type = mtk_file_type;
strcpy(p_file_name, p_get_file_name);
}
*img_w = get_img_w;
*img_h = get_img_h;
return ret;
}
/*-----------------------------------------------------------
* FUNCTION NAME: file_ext_convert_down
* DESCRIPTION:
* ABC=>abc,AbC=>abc,abC=>abc
* ARGUMENTS:
*
* Return:
*
* Note:
*
*------------------------------------------------------------*/
void CMv_skinDlg::file_ext_convert_down(char *p_des, const char *p_src)
{
unsigned int i;
for( i = 0; 0 != p_src[i]; i++ )
{
if(p_src[i]>='A' && p_src[i] <='Z')
{
p_des[i] = p_src[i] + 0x20;
}
else
{
p_des[i] = p_src[i];
}
}
}
/*-----------------------------------------------------------
* FUNCTION NAME: file_ext_convert_up
* DESCRIPTION:
* abc=>ABC,AbC=>ABC,abC=>ABC
* ARGUMENTS:
*
* Return:
*
* Note:
*
*------------------------------------------------------------*/
void CMv_skinDlg::file_ext_convert_up(char *p_des, const char *p_src)
{
unsigned int i;
for( i = 0; 0 != p_src[i]; i++ )
{
if(p_src[i]>='a' && p_src[i] <='z')
{
p_des[i] = p_src[i] - 0x20;
}
else
{
p_des[i] = p_src[i];
}
}
}
BOOL CMv_skinDlg::bmp_file_parse(FILE *p_file, int img_index, int *img_w, int *img_h)
{
bmp_file_header_t f_h;
bmp_info_header_t b_h;
int bmp_w, bmp_h, bmp_bc;
int tb_size,image_size;
unsigned int total_size;
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 FALSE;
}
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 FALSE;
}
bmp_w = b_h.bi_width;
bmp_h = b_h.bi_height;
bmp_bc = b_h.bi_bitcount;
if( (bmp_w != mv_img_file_size[lcd_size][img_index].width)
|| (bmp_h != mv_img_file_size[lcd_size][img_index].height)
|| ( img_index != mv_img_file_size[lcd_size][img_index].index) )
{
char str[250]={0};
sprintf(str, "请选择:宽(%d)×高(%d)的图片", mv_img_file_size[lcd_size][img_index].width, mv_img_file_size[lcd_size][img_index].height);
MessageBox(str, "尺寸错误", MB_ICONWARNING);
return FALSE;
}
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 FALSE;
}
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 FALSE;
}
fread(color_tb, tb_size, 1, p_file); //get color table
}
image_size = ((((bmp_w*bmp_bc) + 31) & ~31) / 8) * bmp_h;
*img_w = bmp_w;
*img_h = bmp_h;
return TRUE;
}
BOOL CMv_skinDlg::gif_file_parse(FILE *p_file, int img_index, int *img_w, int *img_h )
{
gif_file_header_t gif_f_h;
unsigned char gif_f_tail;
int gif_w, gif_h;
unsigned int total_size;
fread(&gif_f_h, sizeof(gif_f_h), 1, p_file); //get file header
if( 'G'!=gif_f_h.gf_type_g || 'I'!=gif_f_h.gf_type_i || 'F'!=gif_f_h.gf_type_f )
{
MessageBox("文件格式错误", NULL, MB_ICONWARNING);
return FALSE;
}
gif_w = gif_f_h.gf_width;
gif_h = gif_f_h.gf_height;
rewind(p_file);
fseek(p_file, 0, SEEK_END); //定位到文件末
total_size = ftell(p_file); //文件长度
rewind(p_file);
fseek(p_file, total_size-1, SEEK_CUR);
fread(&gif_f_tail, 1, 1, p_file); //get file tail
if( 0X3B != gif_f_tail )
{
MessageBox("文件格式错误", NULL, MB_ICONWARNING);
return FALSE;
}
if( (gif_w != mv_img_file_size[lcd_size][img_index].width)
|| (gif_h != mv_img_file_size[lcd_size][img_index].height)
|| ( img_index != mv_img_file_size[lcd_size][img_index].index) )
{
char str[250]={0};
sprintf(str, "请选择:宽(%d)×高(%d)的图片", mv_img_file_size[lcd_size][img_index].width, mv_img_file_size[lcd_size][img_index].height);
MessageBox(str, "尺寸错误", MB_ICONWARNING);
return FALSE;
}
*img_w = gif_w;
*img_h = gif_h;
return TRUE;
}
BOOL CMv_skinDlg::png_file_parse(FILE *p_file, int img_index, int *img_w, int *img_h )
{
png_file_header_t png_f_h;
int png_w, png_h;
fread(&png_f_h, sizeof(png_f_h), 1, p_file); //get file header
if( 0X89 != png_f_h.pf_area0 || 'P' != png_f_h.pf_area1 || 'N' != png_f_h.pf_area2 || 'G' != png_f_h.pf_area3
|| 0X0D != png_f_h.pf_area4 || 0X0A != png_f_h.pf_area5 || 0X1A != png_f_h.pf_area6 || 0X0A != png_f_h.pf_area7)
{
MessageBox("文件格式错误", NULL, MB_ICONWARNING);
return FALSE;
}
png_w = png_f_h.pf_width;
png_h = png_f_h.pf_height;
if( (png_w != mv_img_file_size[lcd_size][img_index].width)
|| (png_h != mv_img_file_size[lcd_size][img_index].height)
|| ( img_index != mv_img_file_size[lcd_size][img_index].index) )
{
char str[250]={0};
sprintf(str, "请选择:宽(%d)×高(%d)的图片", mv_img_file_size[lcd_size][img_index].width, mv_img_file_size[lcd_size][img_index].height);
MessageBox(str, "尺寸错误", MB_ICONWARNING);
return FALSE;
}
*img_w = png_w;
*img_h = png_h;
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -