To display bitmaps, you should use GDI + inside the bitmap class or the image class, which all two classes provide a way to open files from a file on the hard disk, creating the corresponding in-memory bitmap object work. You can then use the DrawImage method of the graphics class to draw the bitmap.
The following code initializes GDI +, displays an open file dialog box and creates a bitmap object that displays the bitmap:
Gdiplusstartupinput input; Ulong_ptr Gdiplustoken;if (Gdiplusstartup (&gdiplustoken,&input,null)!=ok) {return-1;} Char filename[200];openfilename openstruct;memset (&openstruct,0,sizeof (openfilename)); openStruct.lStructSize =sizeof (openfilename); openstruct.flags=ofn_explorer;openstruct.lpstrfilter= "Jpeg files (*.jpg) \0*.jpg\0\0"; o Penstruct.lpstrfile=filename;openstruct.nmaxfile=200;if (GetOpenFileName (&openstruct)) {imageFileName= FileName;} HDC Hdc=getdc (Hpicwnd), if (hdc==null) {MessageBox (NULL, "", "", MB_OK);} Graphics *g=new Graphics (HDC); WCHAR tmpfilename[100];size_t numofchars;if (/*mbstowcs_s (&numofchars,tmpfilename,100,filename,199) */ MultiByteToWideChar (Cp_acp,mb_composite,imagefilename.c_str (), 200,tmpfilename,100)/*==-1*/) {MessageBox (NULL, " Error occured in string convertion! "," error! ", MB_OK); return WParam;} HWND Hpicwnd;rect RC; GetWindowRect (HPICWND,&RC); RECTF DrawRect (rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top); Bitmap *bmp=new Bitmap (tmpfilename); bmpmain=bmp; G->drawimage (Bmp,drawrect);d elete G; ReleaseDC (HWND,HDC); Gdiplusshutdown (Gdiplustoken);
Reprint Address: http://www.cppblog.com/dingding/archive/2008/06/27/54796.html