Beispiel #1
0
//保存到一副Bmp 文件
void BinImg::OnSaveToBmp() 
{
    static char BASED_CODE szFilter[] = "Bmp File (*.bmp)|*.bmp|";

	CStatic *pImg = (CStatic *)GetDlgItem(IDC_BINIMG);
    HBITMAP   hbm   =   pImg->GetBitmap(); 
    if (hbm == NULL) return;

	CFileDialog dlgSave(
						FALSE,
						"*.bmp",
						"",
						OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
						szFilter,
						NULL
						); 

	dlgSave.DoModal();   
	CString sFileName;
    sFileName = dlgSave.GetFileName();
    if (sFileName.IsEmpty())
    {
		return;
    }

	/*
	OPENFILENAME   ofn;               //   common   dialog   box   structure   
	char   szFile[260];               //   buffer   for   file   name   
	HWND   hwnd;                             //   owner   window   
	HANDLE   hf;                             //   file   handle   
    
	  //   Initialize   OPENFILENAME   
	  ZeroMemory(&ofn,   sizeof(ofn));   
	  ofn.lStructSize   =   sizeof(ofn);   
	  ofn.hwndOwner   =   hwnd;   
	  ofn.lpstrFile   =   szFile;   
	  //   
	  //   Set   lpstrFile[0]   to   '\0'   so   that   GetOpenFileName   does   not     
	  //   use   the   contents   of   szFile   to   initialize   itself.   
	  //   
	  ofn.lpstrFile[0]   =   '\0';   
	  ofn.nMaxFile   =   sizeof(szFile);   
	  ofn.lpstrFilter   =   "All\0*.*\0Text\0*.TXT\0";   
	  ofn.nFilterIndex   =   1;   
	  ofn.lpstrFileTitle   =   NULL;   
	  ofn.nMaxFileTitle   =   0;   
	  ofn.lpstrInitialDir   =   NULL;   
	  ofn.Flags   =   OFN_PATHMUSTEXIST   |   OFN_FILEMUSTEXIST;   
	  
		//   Display   the   Save   dialog   box.     
		
		  GetSaveFileName(&ofn);     
		  
			//   ofn.lpstrFile   Store   the   Filename.   
			MessageBox(NULL,ofn.lpstrFile,NULL,MB_OK);   
			
	*/
	SaveToFile(hbm,sFileName);   //保存到文件

		
}