Browse Source

added option to save bitmaps to .bmp, .png, jpeg

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@818 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 10 years ago
parent
commit
9a5b45a2f1
2 changed files with 31 additions and 31 deletions
  1. 29 29
      Misc.cpp
  2. 2 2
      QPasteWnd.cpp

+ 29 - 29
Misc.cpp

@@ -573,7 +573,7 @@ int GetScreenWidth(void)
 	}
 	else
 	{
-		return(GetSystemMetrics(SM_CXSCREEN));
+		return(GetSystemMetrics(SM_CXVIRTUALSCREEN));
 	}
 }
 
@@ -622,7 +622,7 @@ int GetScreenHeight(void)
 	}
 	else
 	{
-		return(GetSystemMetrics(SM_CYSCREEN));
+		return(GetSystemMetrics(SM_CYVIRTUALSCREEN));
 	}
 }
 
@@ -1198,39 +1198,39 @@ CString InternetEncode(CString text)
 bool WriteCF_DIBToFile(CString csPath, LPVOID data, ULONG size)
 {
 	bool bRet = false;
-	CFile file;
-	CFileException ex;
-	if (file.Open(csPath, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary, &ex))
-	{
-		BITMAPINFO *lpBI = (BITMAPINFO *) data;
+	
+	BITMAPINFO *lpBI = (BITMAPINFO *) data;		
 
-		int nPaletteEntries = 1 << lpBI->bmiHeader.biBitCount;
-		if (lpBI->bmiHeader.biBitCount > 8)
-			nPaletteEntries = 0;
-		else if (lpBI->bmiHeader.biClrUsed != 0)
-			nPaletteEntries = lpBI->bmiHeader.biClrUsed;
+	int nPaletteEntries = 1 << lpBI->bmiHeader.biBitCount;
+	if (lpBI->bmiHeader.biBitCount > 8)
+		nPaletteEntries = 0;
+	else if (lpBI->bmiHeader.biClrUsed != 0)
+		nPaletteEntries = lpBI->bmiHeader.biClrUsed;
 
-		BITMAPFILEHEADER BFH;
-		memset(&BFH, 0, sizeof(BITMAPFILEHEADER));
-		BFH.bfType = 'MB';
-		BFH.bfSize = sizeof(BITMAPFILEHEADER) + size;
-		BFH.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + nPaletteEntries * sizeof(RGBQUAD);
+	BITMAPFILEHEADER BFH;
+	memset(&BFH, 0, sizeof(BITMAPFILEHEADER));
+	BFH.bfType = 'MB';
+	BFH.bfSize = sizeof(BITMAPFILEHEADER) + size;
+	BFH.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + nPaletteEntries * sizeof(RGBQUAD);
 
-		file.Write(&BFH, sizeof(BITMAPFILEHEADER));
-		file.Write(data, size);
+	// Create stream with 0 size
+	IStream* pIStream = NULL;
+	if (CreateStreamOnHGlobal(NULL, TRUE, (LPSTREAM*) &pIStream) != S_OK)
+	{
+		TRACE("Failed to create stream on global memory!\n");
+		return FALSE;
+	}
+
+	//write the file to the stream object
+	pIStream->Write(&BFH, sizeof(BITMAPFILEHEADER), NULL);
+	pIStream->Write(data, size, NULL);
 
-		file.Close();
+	CImage i;
+	i.Load(pIStream);
 
-		bRet = true;
-	}
-	else
+	if(i.Save(csPath) == S_OK)
 	{
-		CString csError;
-		TCHAR exError[250];
-		ex.GetErrorMessage(exError, sizeof(exError));
-
-		csError.Format(_T("OutLookExpress Addin - Failed to write CF_DIB to file: %s, Error: %s"), csPath, exError);
-		OutputDebugString(csPath);
+		bRet = true;
 	}
 
 	return bRet;

+ 2 - 2
QPasteWnd.cpp

@@ -3730,12 +3730,12 @@ bool CQPasteWnd::DoExportToBitMapFile()
 	ofn.hwndOwner = m_hWnd;
 	ofn.lpstrFile = szFile;
 	ofn.nMaxFile = sizeof(szFile);
-	ofn.lpstrFilter = _T("Exported Ditto Clips (.bmp)\0*.bmp\0\0");
+	ofn.lpstrFilter = _T("BMP (*.bmp)\0*.bmp\0PNG (*.png)\0*.png\0JPEG (*.jpeg)\0*.jpeg");
 	ofn.nFilterIndex = 1;
 	ofn.lpstrFileTitle = NULL;
 	ofn.nMaxFileTitle = 0;
 	ofn.lpstrInitialDir = szDir;
-	ofn.lpstrDefExt = _T("txt");
+	ofn.lpstrDefExt = _T(".bmp");
 	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_OVERWRITEPROMPT;
 
 	m_bHideWnd = false;