strcat(szFilter, Filter);
strcpy(Filter,FreeImage_GetFIFExtensionList((FREE_IMAGE_FORMAT)i));
token = strtok(Filter, ",");
while(token != NULL) {
strcat(szFilter, "*.");strcat(szFilter, token);
strcat(szFilter, ";");token=strtok(NULL, ",");
}
szFilter[strlen(szFilter)-1] = '|'; iCount++;
}
strcat(szFilter, "All Files (*.*)|*.*|");
strcat(szFilter, "|");
return iCount;
}
在文档类中重载OnFileOpen,调用GetFilterString创建文件类型过滤字符串,调用LoadDIB加载位图。
void CDIPDoc::OnFileOpen()
{
FIBITMAP* pFI = NULL;
char szFilter[2048];
GetFilterString(szFilter);
CFileDialog dlg(TRUE,NULL,NULL,
OFN_HIDEREADONLY, szFilter);
if(dlg.DoModal() == IDOK){
CString strPath = dlg.GetPathName();
pFI = LoadDIB(strPath, 0);
if(pFI){
FreeDIB();//释放以前的位图
m_pFI = pFI;//指向新位图
UpdateAllViews (NULL);
}
}
}
|