这是一个通用对话框函数打开一个对话框返回一个TCHAR指针,就是你需要的那个文件名;
TCHAR *OPEN(HWND hWnd)
{
OPENFILENAME ofn;
static TCHAR szFilter[] = TEXT ("Common Dialog Files (*.jpg)\0*.jpg\0");//打开的路径名
static TCHAR szFile[100];
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = szFilter ;
ofn.nFilterIndex = 1;
ofn.lpstrFile = szFile;
ofn.nMaxFile = MAX_PATH ;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn) == TRUE)
{
strcpy(szFile, ofn.lpstrFile );
InvalidateRect(hWnd,NULL,true);
}
return szFile;
}
这是一个把TCHAR转换为WCHAR的函数
WCHAR *ToWchar(char *str)
{
static WCHAR buffer[1027];
wcsset(buffer,0);
MultiByteToWideChar(CP_ACP,0,str,strlen(str),buffer,1027);
return buffer;
}
把显示中的代码写成
Graphics imgraphics(hdc);
Image image(你转换完的文件名一个WCHAR指针);
imgraphics.DrawImage(&image,0,0);
以上是显示一幅jpg或tif或png等格式的图片用到了GDI+
如果你只想显示bmp图片那第一步就足够了.但以上只能一次打开一个位图,并在窗口中显示.