Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

snapshot up through 'Clean up a few compile warnings

  • Loading branch information...
commit 3b20499a108be765f02779cf4801c2083f0496bb 0 parents
@rdp authored
Showing with 42,151 additions and 0 deletions.
  1. +19 −0 .hgignore
  2. +9 −0 .hgtags
  3. +53 −0 CamStudio/Bugs.txt
  4. +504 −0 CamStudio/CamLib/CBitmapEx.cpp
  5. +42 −0 CamStudio/CamLib/CBitmapEx.h
  6. +23 −0 CamStudio/CamLib/CStudioLib.h
  7. +78 −0 CamStudio/CamLib/CStudiolib.cpp
  8. +106 −0 CamStudio/CamLib/CamError.cpp
  9. +9 −0 CamStudio/CamLib/CamError.h
  10. +139 −0 CamStudio/CamLib/CamFile.cpp
  11. +20 −0 CamStudio/CamLib/CamFile.h
  12. +84 −0 CamStudio/CamLib/CamImage.cpp
  13. +14 −0 CamStudio/CamLib/CamImage.h
  14. +285 −0 CamStudio/CamLib/CamLib.vcproj
  15. +175 −0 CamStudio/CamLib/CamLib.vcxproj
  16. +98 −0 CamStudio/CamLib/CamLib.vcxproj.filters
  17. +3 −0  CamStudio/CamLib/CamLib.vcxproj.user
  18. +72 −0 CamStudio/CamLib/CamRect.cpp
  19. +13 −0 CamStudio/CamLib/CamRect.h
  20. +43 −0 CamStudio/CamLib/CamSys.cpp
  21. +12 −0 CamStudio/CamLib/CamSys.h
  22. +60 −0 CamStudio/CamLib/CamWindow.cpp
  23. +13 −0 CamStudio/CamLib/CamWindow.h
  24. +784 −0 CamStudio/CamLib/Picture.cpp
  25. +52 −0 CamStudio/CamLib/Picture.h
  26. +221 −0 CamStudio/CamLib/TrayIcon.cpp
  27. +49 −0 CamStudio/CamLib/TrayIcon.h
  28. +8 −0 CamStudio/CamLib/stdafx.cpp
  29. +20 −0 CamStudio/CamLib/stdafx.h
  30. +24 −0 CamStudio/CamLib/targetver.h
  31. +250 −0 CamStudio/CamStudio.cfg
  32. +370 −0 CamStudio/CamStudio.sln
  33. +996 −0 CamStudio/Codec/camcodec.cpp
  34. +4 −0 CamStudio/Codec/camcodec.def
  35. +80 −0 CamStudio/Codec/camcodec.h
  36. BIN  CamStudio/Codec/camcodec.ncb
  37. +167 −0 CamStudio/Codec/camcodec.rc
  38. +619 −0 CamStudio/Codec/camcodec.vcproj
  39. +307 −0 CamStudio/Codec/camcodec.vcxproj
  40. +3 −0  CamStudio/Codec/camcodec.vcxproj.user
  41. +256 −0 CamStudio/Codec/drvproc.cpp
  42. +339 −0 CamStudio/Codec/minilzo/COPYING
  43. +113 −0 CamStudio/Codec/minilzo/Makefile
  44. +124 −0 CamStudio/Codec/minilzo/README.LZO
  45. +446 −0 CamStudio/Codec/minilzo/lzoconf.h
  46. +1,852 −0 CamStudio/Codec/minilzo/lzodefs.h
  47. +4,562 −0 CamStudio/Codec/minilzo/minilzo.c
  48. +109 −0 CamStudio/Codec/minilzo/minilzo.h
  49. +171 −0 CamStudio/Codec/minilzo/testmini.c
  50. +28 −0 CamStudio/Codec/resource.h
  51. +27 −0 CamStudio/Commandline/CamStudioCommandLine.vcxproj.filters
  52. +26 −0 CamStudio/Commandline/CamStudioCommandline.sln
  53. +211 −0 CamStudio/Commandline/CamStudioCommandline.vcproj
  54. +192 −0 CamStudio/Commandline/CamStudioCommandline.vcxproj
  55. +3 −0  CamStudio/Commandline/CamStudioCommandline.vcxproj.user
  56. +1,400 −0 CamStudio/Commandline/Commandline.cpp
  57. +37 −0 CamStudio/Commandline/Commandline.hpp
  58. +179 −0 CamStudio/CxImage/Console.dsw
  59. +126 −0 CamStudio/CxImage/Console.sln
  60. +38 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImage.sln
  61. +13 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImageCrtDll.cpp
  62. +423 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImageCrtDll.dsp
  63. +123 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImageCrtDll.rc
  64. +3,465 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImageCrtDll.vcproj
  65. +1,143 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImageCrtDll.vcxproj
  66. +194 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImageCrtDll.vcxproj.filters
  67. +3 −0  CamStudio/CxImage/CxImage/CxImageDLL/CxImageCrtDll.vcxproj.user
  68. +38 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImageCrtDll_wince.sln
  69. +2,405 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImageCrtDll_wince.vcproj
  70. +152 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImageDll.dsw
  71. +194 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImageDll_wince.sln
  72. BIN  CamStudio/CxImage/CxImage/CxImageDLL/CxImageMfcDll.aps
  73. +16 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImageMfcDll.clw
  74. +62 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImageMfcDll.cpp
  75. +45 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImageMfcDll.h
  76. +123 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImageMfcDll.rc
  77. +38 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImageMfcDll_wince.sln
  78. +2,565 −0 CamStudio/CxImage/CxImage/CxImageDLL/CxImageMfcDll_wince.vcproj
  79. +8 −0 CamStudio/CxImage/CxImage/CxImageDLL/StdAfx.cpp
  80. +50 −0 CamStudio/CxImage/CxImage/CxImageDLL/StdAfx.h
  81. +28 −0 CamStudio/CxImage/CxImage/CxImageDLL/StdCrt.h
  82. +400 −0 CamStudio/CxImage/CxImage/CxImageDLL/cximagemfcdll.dsp
  83. +3,566 −0 CamStudio/CxImage/CxImage/CxImageDLL/cximagemfcdll.vcproj
  84. +1,193 −0 CamStudio/CxImage/CxImage/CxImageDLL/cximagemfcdll.vcxproj
  85. +197 −0 CamStudio/CxImage/CxImage/CxImageDLL/cximagemfcdll.vcxproj.filters
  86. +15 −0 CamStudio/CxImage/CxImage/CxImageDLL/resource.h
  87. +15 −0 CamStudio/CxImage/CxImage/CxImageDLL/resrc1.h
  88. +248 −0 CamStudio/CxImage/CxImage/Doxyfile.txt
  89. +655 −0 CamStudio/CxImage/CxImage/cximage.dev
  90. +376 −0 CamStudio/CxImage/CxImage/cximage.dsp
  91. +29 −0 CamStudio/CxImage/CxImage/cximage.dsw
  92. +3,169 −0 CamStudio/CxImage/CxImage/cximage.vcproj
  93. +1,015 −0 CamStudio/CxImage/CxImage/cximage.vcxproj
  94. +188 −0 CamStudio/CxImage/CxImage/cximage.vcxproj.filters
  95. +38 −0 CamStudio/CxImage/CxImage/cximage_wince.sln
  96. +2,499 −0 CamStudio/CxImage/CxImage/cximage_wince.vcproj
  97. +48 −0 CamStudio/CxImage/CxImage/license.txt
  98. +249 −0 CamStudio/CxImage/CxImage/stdint.h
  99. +221 −0 CamStudio/CxImage/CxImage/tif_xfile.cpp
  100. +79 −0 CamStudio/CxImage/CxImage/xfile.h
  101. +448 −0 CamStudio/CxImage/CxImage/ximabmp.cpp
  102. +79 −0 CamStudio/CxImage/CxImage/ximabmp.h
  103. +59 −0 CamStudio/CxImage/CxImage/ximacfg.h
  104. +210 −0 CamStudio/CxImage/CxImage/ximadef.h
Sorry, we could not display the entire diff because too many files (1,468) changed.
19 .hgignore
@@ -0,0 +1,19 @@
+syntax: glob
+.vcxproj.user
+.suo
+.sdf
+ResolveAssemblyReference.cache
+CamStudio/CamStudio.sdf
+CamStudio/CamStudio.suo
+CamStudio/CxImage/CxImage/cximage.vcxproj.user
+CamStudio/CxImage/jasper/jasper.vcxproj.user
+CamStudio/CxImage/jbig/jbig.vcxproj.user
+CamStudio/CxImage/jpeg/Jpeg.vcxproj.user
+CamStudio/CxImage/libpsd/libpsd.vcxproj.user
+CamStudio/CxImage/mng/mng.vcxproj.user
+CamStudio/CxImage/raw/libdcr.vcxproj.user
+CamStudio/CxImage/png/png.vcxproj.user
+CamStudio/CxImage/tiff/Tiff.vcxproj.user
+CamStudio/CxImage/zlib/zlib.vcxproj.user
+CamStudio/Recorder/Recorder.aps
+CamStudio/CamStudio.opensdf
9 .hgtags
@@ -0,0 +1,9 @@
+56d25b91a3dd447843f803653f29546979766f96 CamStudio-2.6b3
+b7fcc22bd28f7edec75cdcb288517966d8e73800 CamStudio-2.6b2
+edbae2723ba697c8635489ea2ace6e096b301e8f CamStudio-2.6b1
+aee0f45e2119b5459f9c1e09e61b1669dc62b3b9 CamStudio-2.5b1
+b23d1095232bca1315f03cf99b6c8af5c72e75e7 CamStudio-2.0
+
+612a4b4152599ddcc1a6d1f5665d455093600ccb CamStudio-2.6.c
+89b064ea40a816905f6d7aee73bb9f2a5c6d013c CamStudio-3.1a1
+0000000000000000000000000000000000000000 CamStudio-3.1a1
53 CamStudio/Bugs.txt
@@ -0,0 +1,53 @@
+Bugs.txt
+=======================================
+
+- Recorder:
+ 4/26/2010
+ o clean up files: remove extraneous whitespace
+ o ScreenAnnotationDlg ctor now initializes cursor handles to null and loads them
+ in OnInitDialog.
+
+ 2/20/09
+** o Recorder shortcuts completely block the keys from being heard by another application
+ This is a big problem since the default F7-F10 are extremely useful when debugging with
+ VS. Also, it doesn't let you save multiple shortcuts as NONE. Also the GUI for shortcuts
+ is pretty terrible, look at the shortcuts menu in VS for a better concept.
+ o audio/video sync problems when recording long videos -- theories on how to fix this?
+ o On some systems CamStudio doesn't correctly detect all installed codecs -- replicate?
+
+ 1/1/09
+** o Options-Record audio from speakers causes WaveoutgetSelectedContron (Vista) **
+ o Under audio options dialog device names are truncated. (Vista)
+
+ 10/19/08
+ o Video Options - Compressor: Codec 1.5 - Configure GZZP partially visible.
+ o All settings not saved restored; Selected compressor reverts to MS Video 1
+ (or first compressor list item?)
+ o Audio is choppy with no interleave on all compressors other than MCI.
+ - Microsoft's MP3 codec
+ - The latest LAME ACM 3.98
+ - Microsoft's ADPCM codec
+ - PCM (no compression)
+ o Keyboard shortcuts are saved but not restored.
+ o Recorder didn't switch to German language when configured.
+
+ 10/25/08
+ o The CSyncDlg if causing a non-fatal exception during initalization in wincore.
+
+
+- Installation:
+ 1/20/09
+ o The codec doesn't install properly during the studio installation. The user has to
+ manually install with right-click on the INF.
+
+Resolved Issues:
+ o (fixed 2/22/09 - Jason) Record window capture mode seems to be broken.
+ o (fixed 2/20/09 - Jason) menu "Help" on second row.
+ o (fixed 2/18/09 - Jason) From Windows Explorer:
+ Right Button + "Open With..." + select Player Classic or PlayerPlus will not
+ play video; must use the player File-Open.
+ o (fixed ? - ?) the global ScreenAnnotationDlg (sad) ctor attempts to access the
+ instance handle from the AFX lib too early. The handle is now taken from
+ the system and then the varibles are reinitialized during the InitDialog
+ member function
+ o (fixed ? - ?) Vista blocks install to "Program Files" and "system32" folders
504 CamStudio/CamLib/CBitmapEx.cpp
@@ -0,0 +1,504 @@
+// CBITMAPEX.CPP
+// CBitmap extention
+//
+// (c) Vadim Gorbatenko, 1997-99
+// gvv@mail.tomsknet.ru
+// All rights reserved
+//
+//___________________________________________________________________________________________
+
+#include "stdafx.h"
+#include "afxdlgs.h"
+#include "CBitmapEx.h"
+
+#define WIDTHBYTES(iBits) (((iBits) + 31) / 32 * 4)
+#define PALETTESIZE(lpbi) (_DIBNumColors((LPBITMAPINFOHEADER) lpbi)* sizeof (RGBQUAD))
+#define DIBCOLORS(lpbi) ((LPRGBQUAD)((LPBYTE)(lpbi) + (int)(lpbi)->biSize))
+#define DIBPTR(lpbi) (LPBYTE)(DIBCOLORS((LPBITMAPINFOHEADER)lpbi) + (UINT)((LPBITMAPINFOHEADER)lpbi)->biClrUsed)
+
+HANDLE _dibFromBitmap(HBITMAP hBitmap);
+BOOL _writeDib(HANDLE hdib, LPCSTR filename);
+INT _DIBNumColors (LPBITMAPINFOHEADER lpbi);
+
+CBitmapEx::CBitmapEx():CBitmap()
+{
+ _modBMP= NULL;
+
+}
+
+CBitmapEx::~CBitmapEx()
+{
+ EndModify();//just in case:)
+}
+
+HANDLE CBitmapEx::DibFromBitmap()
+{return _dibFromBitmap((HBITMAP)GetSafeHandle());}
+
+HANDLE CBitmapEx::DibFromBitmap(HBITMAP hb)
+{return _dibFromBitmap(hb);}
+
+BOOL CBitmapEx::CreateFromDib(LPBITMAPINFO lpBi)
+{
+ if (!lpBi || _modBMP) return FALSE;
+ if (((LPBITMAPINFOHEADER)lpBi)->biCompression != BI_RGB)
+ return FALSE;
+
+ if (GetSafeHandle( ))
+ {
+
+ //check existing size
+ BITMAP bmp;
+ GetObject(sizeof BITMAP, &bmp);
+ CSize sz = GetSize();
+
+ if (bmp.bmWidth == ((LPBITMAPINFOHEADER)lpBi)->biWidth &&
+ bmp.bmHeight == ((LPBITMAPINFOHEADER)lpBi)->biHeight)
+ {
+ // special case: we don't need to destroy existing
+ // DDB, just rewrite iBits.
+ // Note: we must be sure, the color resolution is
+ // not changed, so, let's test it:
+ HDC hdc = ::GetDC(NULL);
+ int hdc_bits = GetDeviceCaps(hdc,BITSPIXEL);
+ if (hdc_bits == bmp.bmBitsPixel)
+ {
+ //ok to set new iBits
+ BOOL ret = ::SetDIBits(
+ hdc, // handle to device context
+ (HBITMAP)GetSafeHandle( ), // handle to bitmap
+ 0, // starting scan line
+ bmp.bmHeight, // number of scan lines
+ DIBPTR(lpBi), // array of bitmap iBits
+ lpBi, // address of structure with bitmap data
+ DIB_RGB_COLORS // type of color indexes to use
+ ) == bmp.bmHeight;
+
+ ::ReleaseDC(NULL,hdc);
+ return ret;
+ }
+ else
+ ::ReleaseDC(NULL,hdc);
+ }
+ //delete existing bitmap:(
+ DeleteObject();
+ }
+ //create a new DDB
+ HDC hdc;
+ HBITMAP hbm;
+
+ //Create DDB
+ hdc = ::GetDC(NULL);
+ hbm = CreateDIBitmap(hdc, (LPBITMAPINFOHEADER)lpBi,(LONG)CBM_INIT,
+ DIBPTR(lpBi), lpBi, DIB_RGB_COLORS );
+
+ ::ReleaseDC(NULL,hdc);
+ if (!hbm) return FALSE;
+
+ DeleteObject();//delete attached bitmap
+
+ if (!Attach( (HGDIOBJ) hbm ))
+ {::DeleteObject((HGDIOBJ)hbm); return FALSE;}
+
+ return TRUE;
+
+}
+
+#define sfiltr "Image files (*.BMP)|*.BMP||"
+#define sext "BMP"
+#define smask NULL
+
+BOOL CBitmapEx::Open(LPCSTR filename, LPCSTR DialogTitle)
+{
+ if (GetSafeHandle())
+ return FALSE;
+
+ CString Path(filename);
+ if (!filename) {
+ CFileDialog openAs( TRUE,sext, smask, OFN_NOCHANGEDIR|OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, sfiltr);
+
+ //substitude dialog title
+ if (DialogTitle) {
+ openAs.m_ofn.lpstrTitle = DialogTitle;
+ }
+
+ if (IDOK != openAs.DoModal()) {
+ return FALSE;
+ }
+ Path = openAs.GetPathName();
+ }
+
+ CFile file;
+ if (!file.Open(Path,CFile::modeRead|CFile::typeBinary))
+ return FALSE;
+
+ // get length of DIB in bytes for use when reading
+ // DWORD dwBitsSize = file.GetLength(); -> Cause C4244 warning
+
+ // Prevent dwBitsSize C4244 warning and take some predictions for unwanted truncations
+ ULONGLONG tmpUlongSize = file.GetLength();
+ if ( tmpUlongSize != static_cast<WORD>(tmpUlongSize) ) {
+ TRACE("Error: dwBitsSize, Casted value [%i] is not the same as original [%l] ..!\n", static_cast<WORD>(tmpUlongSize),tmpUlongSize);
+ }
+ // Now assigned tested casted value to dest value (Functional nothing is changed but we have a marker in the tracelog if truncated)
+ DWORD dwBitsSize = static_cast<WORD>(tmpUlongSize);
+
+ BITMAPFILEHEADER bmfHeader;
+ BOOL ret = TRUE;
+ TRY
+ {
+ if (file.Read(&bmfHeader, sizeof (BITMAPFILEHEADER)) != sizeof (BITMAPFILEHEADER)
+ || bmfHeader.bfType != ((WORD) ('M' << 8) | 'B'))
+ ret = FALSE;
+ }
+ CATCH (CFileException, e)
+ {
+ ret = FALSE;
+ }
+ END_CATCH
+
+ if (!ret)
+ return FALSE;
+
+ // Allocate memory for DIB
+ dwBitsSize -= sizeof(BITMAPFILEHEADER);
+
+ HANDLE hDIB = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, dwBitsSize);
+ if (!hDIB)
+ return FALSE;
+
+ LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB);
+ TRY
+ {
+ //if (file.ReadHuge((LPVOID)lpbi, dwBitsSize)!=dwBitsSize)
+ if (file.Read((LPVOID)lpbi, dwBitsSize) != dwBitsSize)
+ ret = FALSE;
+ }
+ CATCH (CFileException, e)
+ {
+ ret = FALSE;
+ }
+ END_CATCH
+
+ file.Close();
+
+ if (!ret) {
+ GlobalUnlock (hDIB);
+ GlobalFree (hDIB);
+ return FALSE;
+ }
+
+ //Create DDB
+ HDC hdc = ::GetDC(NULL);
+ HBITMAP hbm = CreateDIBitmap(hdc, (LPBITMAPINFOHEADER)lpbi,(LONG)CBM_INIT, DIBPTR(lpbi),(LPBITMAPINFO)lpbi,DIB_RGB_COLORS);
+ ::ReleaseDC(NULL,hdc);
+
+ GlobalUnlock (hDIB);
+ GlobalFree (hDIB);
+
+ if (!hbm) {
+ return FALSE;
+ }
+
+ if (GetSafeHandle()) {
+ DeleteObject();
+ }
+
+ if (!Attach( (HGDIOBJ) hbm )) {
+ ::DeleteObject((HGDIOBJ)hbm);
+ return FALSE;
+ }
+
+ return ret;
+}
+
+BOOL CBitmapEx::Save(LPCSTR filename, LPCSTR DialogTitle)
+{
+ if (!GetSafeHandle( ))
+ return FALSE;
+
+ CString Path(filename);
+ if (!filename) {
+ CFileDialog saveAs(FALSE, sext, smask, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, sfiltr);
+ if (DialogTitle)
+ saveAs.m_ofn.lpstrTitle = DialogTitle;
+
+ if (IDOK != saveAs.DoModal())
+ return FALSE;
+
+ Path = saveAs.GetPathName();
+ }
+
+ CFile file;
+ if (!file.Open((LPCSTR)Path,CFile::modeCreate|CFile::modeWrite|CFile::typeBinary))
+ return FALSE;
+
+ HANDLE hdib = _dibFromBitmap((HBITMAP)GetSafeHandle());
+ if (!hdib)
+ return FALSE;
+
+ LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)::GlobalLock (hdib);
+
+ // Fill in the fields of the file header
+ BITMAPFILEHEADER hdr;
+ hdr.bfType = ((WORD) ('M' << 8) | 'B'); // "BM"
+ hdr.bfSize = GlobalSize (hdib) + sizeof (BITMAPFILEHEADER);
+ hdr.bfReserved1 = 0;
+ hdr.bfReserved2 = 0;
+ hdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + lpbi->biSize + PALETTESIZE((LPSTR)lpbi);
+
+ BOOL ret = TRUE;
+ TRY
+ {
+ file.Write((LPSTR)&hdr, sizeof (BITMAPFILEHEADER));
+ //file.WriteHuge((LPSTR)lpbi, GlobalSize (hdib));
+ file.Write((LPSTR)lpbi, GlobalSize (hdib));
+ }
+ CATCH (CFileException, e)
+ {
+ ret = FALSE;
+ }
+ END_CATCH
+
+ file.Close();
+ GlobalUnlock (hdib);
+ GlobalFree (hdib);
+
+ return ret;
+}
+
+// Get DC for "in-memory" drawing
+CDC *CBitmapEx::BegingModify()
+{
+ CWnd* dtw = CWnd::GetDesktopWindow( );
+ CDC *dc = dtw->GetDC();
+
+ if (_modDC.m_hDC)
+ _modDC.DeleteDC( );
+
+ _modDC.CreateCompatibleDC(dc);
+
+ _modBMP = _modDC.SelectObject(this);
+
+ dtw->ReleaseDC(dc);
+ return &_modDC;
+}
+
+void CBitmapEx::EndModify()
+{
+ if (_modDC.m_hDC && _modBMP)
+ _modDC.SelectObject(_modBMP);
+ if (_modDC.m_hDC)
+ _modDC.DeleteDC( );
+ _modBMP = NULL;
+}
+
+// Create color bitmap
+BOOL CBitmapEx::CreateColor(int dx, int dy)
+{
+ if (GetSafeHandle()) return FALSE;
+ HDC hScrDC = ::GetDC(NULL);
+ HDC hMemDC = ::CreateCompatibleDC(hScrDC);
+
+ BOOL r = CreateCompatibleBitmap(CDC::FromHandle(hScrDC), dx, dy);
+
+ ::DeleteDC(hMemDC);
+ ::ReleaseDC(NULL,hScrDC);
+ return r;
+}
+
+// Create monocolor bitmap
+BOOL CBitmapEx::CreateMono(int dx, int dy)
+{
+ if (GetSafeHandle()) return FALSE;
+ CDC mDC;
+ mDC.CreateCompatibleDC(NULL); //for mono!
+
+ BOOL r = CreateCompatibleBitmap( &mDC, dx, dy );
+
+ mDC.DeleteDC( );
+ return r;
+}
+
+// This was the first extention i've done! :)))
+CSize CBitmapEx::GetSize()
+{
+ BITMAP bmp;
+ if (!GetSafeHandle()) return CSize(0,0);
+ GetObject(sizeof BITMAP, &bmp);
+ return CSize(bmp.bmWidth,bmp.bmHeight);
+}
+
+void CBitmapEx::BitBlt(CDC *dc_to, POINT at, DWORD rop)
+{
+ CSize sz=GetSize();
+
+ dc_to->BitBlt(at.x,at.y, sz.cx, sz.cy,
+ BegingModify(),//source context
+ 0,0, rop);
+ EndModify();
+}
+
+void CBitmapEx::StretchBlt(CDC *dc_to, CRect to, DWORD rop)
+{
+ CSize sz = GetSize();
+ dc_to->StretchBlt(to.left, to.top, to.Width(), to.Height(), BegingModify(), 0, 0, sz.cx, sz.cy, rop);
+ EndModify();
+}
+
+//Copy the other bitmap to this
+BOOL CBitmapEx::CopyRect(CBitmap& bmp, CRect& rc)
+{
+ CWnd* dtw = CWnd::GetDesktopWindow();
+ CDC *dc = dtw->GetDC();
+
+ CDC cdc;
+ CDC cdc2;
+ cdc2.CreateCompatibleDC(dc);
+ cdc.CreateCompatibleDC(dc);
+
+ bmp.CreateCompatibleBitmap( dc, rc.Width(), rc.Height());
+
+ CBitmap *ob2 = cdc2.SelectObject(&bmp);
+ CBitmap *ob = cdc.SelectObject(this);
+
+ cdc2.BitBlt( 0, 0, rc.Width(), rc.Height(), &cdc, rc.left, rc.top, SRCCOPY );
+ cdc2.SelectObject(ob2);
+ cdc.SelectObject(ob);
+
+ dtw->ReleaseDC(dc);
+ return TRUE;
+}
+
+DWORD CBitmapEx::DibImageSize(HANDLE hDIB)
+{
+ if (!hDIB) return 0;
+ LPBITMAPINFOHEADER lpbmInfoHdr=(LPBITMAPINFOHEADER) GlobalLock (hDIB);
+ DWORD sz=sizeof (BITMAPINFOHEADER)+PALETTESIZE ((LPSTR) lpbmInfoHdr) + lpbmInfoHdr->biSizeImage;
+ GlobalUnlock(hDIB);
+ return sz;
+}
+
+/////////////////////////////////////////////////
+// DDB->DIB
+HANDLE _dibFromBitmap(HBITMAP hBitmap)
+{
+ if (!hBitmap)
+ return NULL;
+
+ BITMAP bm;
+ ::GetObject (hBitmap, sizeof (bm), (LPSTR)&bm);
+
+ WORD wBits = bm.bmBitsPixel;
+
+ BITMAPINFOHEADER bi;
+ bi.biSize = sizeof (BITMAPINFOHEADER);
+ bi.biWidth = bm.bmWidth;
+ bi.biHeight = bm.bmHeight;
+ bi.biPlanes = 1;
+ bi.biBitCount = wBits;
+ bi.biCompression = BI_RGB;
+ bi.biSizeImage = 0;
+ bi.biXPelsPerMeter = 0;
+ bi.biYPelsPerMeter = 0;
+ bi.biClrUsed = 0;
+ bi.biClrImportant = 0;
+
+ DWORD dwLen = bi.biSize + PALETTESIZE ((LPSTR) &bi);
+ HANDLE hDIB = ::GlobalAlloc(GMEM_DDESHARE|GMEM_MOVEABLE,dwLen);
+ if (!hDIB) {
+ return NULL;
+ }
+
+ BITMAPINFOHEADER *lpbi = (LPBITMAPINFOHEADER)::GlobalLock(hDIB);
+ *lpbi = bi;
+
+ HDC hDC = 0;
+ HPALETTE hPal = NULL;
+ HWND hWnd = GetFocus();
+ if (!hWnd) {
+ //load default system palette
+ hPal = (HPALETTE)GetStockObject (DEFAULT_PALETTE);
+ hDC = GetDC (NULL);
+ hPal = SelectPalette (hDC, hPal, FALSE);
+ RealizePalette(hDC);
+ } else {
+ //or get palette from focused window
+ HDC hDCw = GetDC (hWnd);
+ hPal = SelectPalette (hDCw, (HPALETTE)GetStockObject (DEFAULT_PALETTE), FALSE);
+ hDC = GetDC (NULL);
+ hPal = SelectPalette (hDC, hPal, FALSE);
+ RealizePalette(hDC);
+ SelectPalette (hDCw, hPal, FALSE);
+ ReleaseDC(hWnd,hDCw);
+ }
+
+ // calculate the biSizeImage
+ GetDIBits (hDC, hBitmap, 0, (WORD) bi.biHeight, NULL, (LPBITMAPINFO) lpbi, DIB_RGB_COLORS);
+ bi = *lpbi;
+ GlobalUnlock(hDIB);
+
+ // If the driver did not fill in the biSizeImage field,
+ // make one up
+
+ if (bi.biSizeImage == 0) {
+ bi.biSizeImage = WIDTHBYTES((DWORD)bm.bmWidth * wBits) * bm.bmHeight;
+
+ if (bi.biCompression != BI_RGB)
+ bi.biSizeImage = (bi.biSizeImage * 3) / 2;
+ }
+
+ DWORD sl = dwLen;
+ HGLOBAL hPtr = hDIB;
+ dwLen = bi.biSize + PALETTESIZE((LPSTR)&bi) + bi.biSizeImage;
+
+ // if you have plans to use DDE or clipboard, you have
+ // to allocate memory with GMEM_DDESHARE flag
+ hDIB = GlobalAlloc(GMEM_DDESHARE|GMEM_MOVEABLE,dwLen);
+ if (!hDIB) {
+ SelectPalette(hDC,hPal,FALSE);
+ ReleaseDC(NULL,hDC);
+ GlobalFree(hPtr);
+ return NULL;
+ }
+
+ lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB);
+ LPBITMAPINFOHEADER lpS=(LPBITMAPINFOHEADER)GlobalLock(hPtr);
+
+ CopyMemory(lpbi,lpS,sl);
+ GlobalUnlock(hPtr);
+ GlobalFree(hPtr);
+
+ // actually fill lpBits
+ if (GetDIBits(hDC, hBitmap, 0, (WORD) bi.biHeight, (LPSTR) lpbi + (WORD) lpbi->biSize + PALETTESIZE((LPSTR) lpbi), (LPBITMAPINFO) lpbi, DIB_RGB_COLORS) == 0) {
+ GlobalUnlock (hDIB);
+ hDIB = NULL;
+ SelectPalette (hDC, hPal, FALSE);
+ ReleaseDC (NULL, hDC);
+ return NULL;
+ }
+
+ bi = *lpbi;
+ GlobalUnlock (hDIB);
+ SelectPalette (hDC, hPal, FALSE);
+ ReleaseDC (NULL, hDC);
+ //OK
+ return hDIB;
+}
+
+int _DIBNumColors (LPBITMAPINFOHEADER lpbi)
+{
+ if (lpbi->biClrUsed)
+ return (int)lpbi->biClrUsed;
+
+ switch (lpbi->biBitCount)
+ {
+ case 1:
+ return 2;
+ case 4:
+ return 16;
+ case 8:
+ return 256;
+ default:
+ return 0; //16,24,32 iBits bitmap has no color table
+ }
+}
42 CamStudio/CamLib/CBitmapEx.h
@@ -0,0 +1,42 @@
+// CBITMAPEX.H
+// CBitmap extention
+//
+//
+//___________________________________________________________________________________________
+
+#ifndef _CBITMAPEX_INCL
+#define _CBITMAPEX_INCL
+
+class CBitmapEx : public CBitmap
+{
+public:
+ CBitmapEx();
+ ~CBitmapEx();
+
+ //load&save DDB
+ BOOL Open(LPCSTR filename, LPCSTR DialogTitle=NULL);
+ BOOL Save(LPCSTR filename, LPCSTR DialogTitle=NULL);
+
+ void BitBlt(CDC *dc_to, POINT at, DWORD rop=SRCCOPY);
+ void StretchBlt(CDC *dc_to, CRect to, DWORD rop=SRCCOPY);
+ CSize GetSize();
+
+ BOOL CreateMono(int dx, int dy);
+ BOOL CreateColor(int dx, int dy);
+ BOOL CreateFromDib(LPBITMAPINFO lpBi);
+
+ BOOL CopyRect(CBitmap& bmp, CRect& rc);
+ HANDLE DibFromBitmap();
+
+ CDC *BegingModify();
+ void EndModify();
+
+ static HANDLE DibFromBitmap(HBITMAP);
+ static DWORD DibImageSize(HANDLE hDIB);
+
+protected:
+ CDC _modDC;
+ CBitmap *_modBMP;
+};
+
+#endif //_RBITMAP_INCL
23 CamStudio/CamLib/CStudioLib.h
@@ -0,0 +1,23 @@
+// CStudioLib.h - include file for CamStudio Library
+/////////////////////////////////////////////////////////////////////////////
+#ifndef CSTUDIOLIB_H
+#define CSTUDIOLIB_H
+
+#pragma once
+
+#include "CamRect.h" // generic rectangle
+#include "CamWindow.h" // generic window
+#include "CamFile.h" // generic file
+#include "CamSys.h" // generic system
+#include "CamImage.h" // generic image
+#include "Picture.h"
+#include "CBitmapEx.h"
+
+// numeric
+long rounddouble(double dVal);
+
+// keyboard
+// TODO: matchSpecial unreferenced
+int matchSpecial(int keyCtrl, int keyShift, int keyAlt, int ctrlDown, int shiftDown, int altDown);
+
+#endif // CSTUDIOLIB_H
78 CamStudio/CamLib/CStudiolib.cpp
@@ -0,0 +1,78 @@
+// CStudioLib.cpp - implementation file for CamStudio Library
+/////////////////////////////////////////////////////////////////////////////
+#include "stdafx.h"
+#include "CStudioLib.h"
+
+// todo: unreferenced
+int matchSpecial(int keyCtrl, int keyShift, int keyAlt, int ctrlDown, int shiftDown, int altDown)
+{
+ int ret = 1;
+
+ if ((keyCtrl) && (!ctrlDown))
+ ret = 0;
+
+ if ((keyShift) && (!shiftDown))
+ ret = 0;
+
+ if ((keyAlt) && (!altDown))
+ ret = 0;
+
+ if ((!keyCtrl) && (ctrlDown))
+ ret = 0;
+
+ if ((!keyShift) && (shiftDown))
+ ret = 0;
+
+ if ((!keyAlt) && (altDown))
+ ret = 0;
+
+ //if ((keyCtrl) && (ctrlDown)) {
+ // if ((keyShift) && (shiftDown)) {
+ // if ((keyAlt) && (altDown)) {
+ // } else if ((!keyAlt) && (!altDown)) {
+ // } else if (keyAlt) {
+ // ret = 0;
+ // }
+ // } else if ((!keyShift) && (!shiftDown)) {
+ // if ((keyAlt) && (altDown)) {
+ // } else if ((!keyAlt) && (!altDown)) {
+ // } else if (keyAlt) {
+ // ret = 0;
+ // }
+ // } else if (keyShift) {
+ // ret = 0;
+ // }
+ //} else if ((!keyCtrl) && (!ctrlDown)) {
+ // if ((keyShift) && (shiftDown)) {
+ // if ((keyAlt) && (altDown)) {
+ // } else if ((!keyAlt) && (!altDown)) {
+ // } else if (keyAlt) {
+ // ret = 0;
+ // }
+ // } else if ((!keyShift) && (!shiftDown)) {
+ // if ((keyAlt) && (altDown)) {
+ // } else if ((!keyAlt) && (!altDown)) {
+ // } else if (keyAlt) {
+ // ret = 0;
+ // }
+ // } else if (keyShift) {
+ // ret = 0;
+ // }
+ //} else if (keyCtrl) {
+ // ret = 0;
+ //}
+
+ return ret;
+}
+
+//Round positive numbers
+long rounddouble(double dVal)
+{
+ long num = (long) dVal;
+ double diff = dVal - (double) num;
+ if (0.5 <= diff)
+ num++;
+
+ return num;
+}
+
106 CamStudio/CamLib/CamError.cpp
@@ -0,0 +1,106 @@
+#include "StdAfx.h"
+#include "CamError.h"
+#include <strsafe.h> // for StringCchPrintf
+
+/////////////////////////////////////////////////////////////////////////////
+// OnError
+// Windows Error handler
+// Gets the last windows error and then resets the error; gets the string
+// associated with the error and displays a messagebox of the error
+/////////////////////////////////////////////////////////////////////////////
+void OnError(LPCSTR lpszFunction)
+{
+ // Retrieve the system error message for the last-error code
+ DWORD dwError = ::GetLastError();
+ if (ERROR_SUCCESS == dwError) {
+ return;
+ }
+ TRACE(_T("OnError: %s: %u\n"), lpszFunction, dwError);
+ ::SetLastError(ERROR_SUCCESS); // reset the error
+
+ LPVOID lpMsgBuf = 0;
+ DWORD dwLen = ::FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER
+ | FORMAT_MESSAGE_FROM_SYSTEM
+ | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ dwError,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) &lpMsgBuf,
+ 0, NULL );
+
+ if (0 == dwLen) {
+ TRACE(_T("OnError: FormatMessage error: %ud\n"), ::GetLastError());
+ ::SetLastError(ERROR_SUCCESS); // reset the error
+ return;
+ }
+ // Display the error message and exit the process
+ LPVOID lpDisplayBuf = (LPVOID)::LocalAlloc(LMEM_ZEROINIT, (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR));
+ if (!lpDisplayBuf) {
+ TRACE(_T("OnError: LocalAlloc error: %ud\n"), ::GetLastError());
+ ::SetLastError(ERROR_SUCCESS); // reset the error
+ ::LocalFree(lpMsgBuf);
+ return;
+ }
+ HRESULT hr = StringCchPrintf((LPTSTR)lpDisplayBuf, ::LocalSize(lpDisplayBuf) / sizeof(TCHAR), TEXT("%s failed with error %d: %s"), lpszFunction, dwError, lpMsgBuf);
+ if (SUCCEEDED(hr)) {
+ //::MessageBox(0, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
+ TRACE(_T("OnError: : %s\n"), lpDisplayBuf);
+ } else {
+ TRACE(_T("OnError: StringCchPrintf error: %ud\n"), ::GetLastError());
+ ::SetLastError(ERROR_SUCCESS); // reset the error
+ }
+
+ ::LocalFree(lpMsgBuf);
+ ::LocalFree(lpDisplayBuf);
+}
+
+void ErrMsg(char frmt[], ...)
+{
+ DWORD written;
+ char buf[5000];
+ va_list val;
+
+ va_start(val, frmt);
+ // wvsprintf(buf, frmt, val); // C4995 warning, function marked as deprecated once
+ _vstprintf_s(buf, frmt, val); // Save replacement
+
+ const COORD _80x50 = {80,50};
+ static BOOL startup = (AllocConsole(), SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), _80x50));
+ WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), buf, lstrlen(buf), &written, 0);
+}
+
+int MessageOut(HWND hWnd,long strMsg, long strTitle, UINT mbstatus)
+{
+ CString tstr("");
+ CString mstr("");
+ VERIFY(tstr.LoadString(strTitle));
+ VERIFY(mstr.LoadString(strMsg));
+
+ return ::MessageBox(hWnd,mstr,tstr,mbstatus);
+}
+
+int MessageOut(HWND hWnd, long strMsg, long strTitle, UINT mbstatus, long val)
+{
+ CString tstr("");
+ CString mstr("");
+ CString fstr("");
+ VERIFY(tstr.LoadString(strTitle));
+ VERIFY(mstr.LoadString(strMsg));
+ fstr.Format(mstr,val);
+
+ return ::MessageBox(hWnd,fstr,tstr,mbstatus);
+}
+
+int MessageOut(HWND hWnd, long strMsg, long strTitle, UINT mbstatus, long val1, long val2)
+{
+ CString tstr("");
+ CString mstr("");
+ CString fstr("");
+ VERIFY(tstr.LoadString(strTitle));
+ VERIFY(mstr.LoadString(strMsg));
+ fstr.Format(mstr,val1,val2);
+
+ return ::MessageBox(hWnd,fstr,tstr,mbstatus);
+}
+
9 CamStudio/CamLib/CamError.h
@@ -0,0 +1,9 @@
+#pragma once
+
+// general error handler
+void OnError(LPCSTR lpszFunction);
+extern void ErrMsg(char format[], ...);
+extern int MessageOut(HWND hWnd,long strMsg, long strTitle, UINT mbstatus);
+extern int MessageOut(HWND hWnd,long strMsg, long strTitle, UINT mbstatus,long val);
+extern int MessageOut(HWND hWnd,long strMsg, long strTitle, UINT mbstatus,long val1,long val2);
+
139 CamStudio/CamLib/CamFile.cpp
@@ -0,0 +1,139 @@
+// CamFile.cpp - CamStudio Library file functions
+/////////////////////////////////////////////////////////////////////////////
+#include "StdAfx.h"
+#include "CamFile.h"
+#include "shlobj.h"
+
+/////////////////////////////////////////////////////////////////////////////
+// GetTempPath
+// n.b. Overloads DWORD GetTempPath(DWORD nBufferLength, LPTSTR lpBuffer)
+// There is a conversion from LPTSTR to CString
+// TODO: Rename; this is needlessly dangerous
+// TODO GetTempFolder does not contain the temp folder but returns the udf target folder. Hence the function name is not correct..!
+/////////////////////////////////////////////////////////////////////////////
+CString GetTempFolder(int iAccess, const CString strFolder)
+{
+ if (iAccess == USE_USER_SPECIFIED_DIR) {
+ CString tempdir = strFolder;
+
+ //Verify the chosen temp path is valid
+ WIN32_FIND_DATA wfd;
+ ::ZeroMemory(&wfd, sizeof (wfd));
+ HANDLE hdir = ::FindFirstFile(LPCTSTR(tempdir), &wfd);
+ if (!hdir) {
+ return GetProgPath();
+ }
+ ::FindClose(hdir);
+
+ //If valid directory, return Windows\temp as temp directory
+ if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+ return tempdir;
+ }
+ }
+
+ char tempPath[_MAX_PATH+1] = { '\0' };
+ if (GetTempPath(_MAX_PATH, tempPath))
+ {
+ CString tempdir;
+ tempdir = tempPath;
+ if (0 < tempdir.ReverseFind('\\'))
+ tempdir = tempdir.Left(tempdir.ReverseFind('\\'));
+ return tempdir;
+ }
+
+ //This code looks for an old style temp directory. NOT standard windows.
+ TCHAR dirx[_MAX_PATH];
+ ::GetWindowsDirectory(dirx, _MAX_PATH);
+ CString tempdir;
+ tempdir.Format(_T("%s\\temp"), dirx);
+
+ // Verify the chosen temp path is valid
+
+ WIN32_FIND_DATA wfd;
+ ::ZeroMemory(&wfd, sizeof (wfd));
+ HANDLE hdir = ::FindFirstFile(LPCTSTR(tempdir), &wfd);
+ if (!hdir) {
+ return GetProgPath();
+ }
+ ::FindClose(hdir);
+
+ // If valid directory, return Windows\temp as temp directory
+ if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+ return tempdir;
+ }
+
+ //else return program path as temp directory
+ //iAccess = USE_INSTALLED_DIR; // TODO: nonsense; iAccess is NOT an output
+ return GetProgPath();
+
+}
+
+CString GetProgPath()
+{
+ // get root of Camstudio application
+ TCHAR szTemp[300];
+ ::GetModuleFileName(NULL, szTemp, 300);
+ CString path = szTemp;
+ if (0 < path.ReverseFind('\\')) {
+ path = path.Left(path.ReverseFind('\\'));
+ }
+ return path;
+}
+
+#ifndef CSIDL_MYVIDEO
+#define CSIDL_MYVIDEO 0x000e // "My Videos" folder
+#endif
+
+CString GetMyVideoPath()
+{
+ //Get the user's video path
+ int folder = CSIDL_MYVIDEO;
+
+ char szPath[MAX_PATH+100]; szPath[0]=0;
+ CString path = szPath;
+
+ if (SUCCEEDED(SHGetFolderPath(NULL, folder, 0, 0, szPath)))
+ {
+ path = szPath;
+ }
+ else if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, 0, 0, szPath)))
+ {
+ path = szPath;
+ }
+ return path;
+}
+
+CString GetAppDataPath()
+ {
+ int folder = CSIDL_APPDATA;
+
+ char szPath[MAX_PATH+100]; szPath[0]=0;
+ CString path = szPath;
+
+ if (SUCCEEDED(SHGetFolderPath(NULL, folder, 0, 0, szPath)))
+ {
+ path = szPath;
+ }
+ else if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, 0, 0, szPath)))
+ {
+ path = szPath;
+ }
+ return path;
+ }
+
+bool DoesFileExist(const CString& name)
+ {
+ return (GetFileAttributes(name.GetString()) == 0xffffffff) ? false : true;
+ }
+
+
+CString FindExtension(const CString& name)
+{
+ int len = name.GetLength();
+ for (int i = len-1; i >= 0; i--) {
+ if (name[i] == '.') {
+ return name.Mid(i+1);
+ }
+ }
+ return "";
+}
20 CamStudio/CamLib/CamFile.h
@@ -0,0 +1,20 @@
+// CamFile.h - include file for CamStudio Library file api's
+/////////////////////////////////////////////////////////////////////////////
+#ifndef CAMFILE_H
+#define CAMFILE_H
+
+#pragma once
+
+// CamFile.cpp
+const int USE_WINDOWS_TEMP_DIR = 0;
+const int USE_INSTALLED_DIR = 1;
+const int USE_USER_SPECIFIED_DIR = 2;
+
+CString GetTempFolder(int iAccess, const CString strFolder = _T(""));
+CString GetProgPath();
+CString FindExtension(const CString& name);
+CString GetMyVideoPath();
+CString GetAppDataPath();
+bool DoesFileExist(const CString& name);
+
+#endif // CAMFILE_H
84 CamStudio/CamLib/CamImage.cpp
@@ -0,0 +1,84 @@
+// CamImage.cpp - CamStudio Library image functions
+/////////////////////////////////////////////////////////////////////////////
+#include "StdAfx.h"
+#include "CamImage.h"
+
+HANDLE Bitmap2Dib(HBITMAP hbitmap, UINT bits)
+{
+ BITMAP bitmap;
+ ::GetObject(hbitmap, sizeof(BITMAP), &bitmap);
+
+ // DWORD align the width of the DIB
+ // Figure out the size of the colour table
+ // Calculate the size of the DIB
+ UINT wLineLen = (bitmap.bmWidth * bits + 31)/32 * 4;
+ DWORD wColSize = sizeof(RGBQUAD) * ((bits <= 8) ? 1 << bits : 0);
+ DWORD dwSize = sizeof(BITMAPINFOHEADER)
+ + wColSize
+ + (DWORD)(UINT)wLineLen * (DWORD)(UINT)bitmap.bmHeight;
+
+ // Allocate room for a DIB and set the LPBI fields
+ HANDLE hdib = ::GlobalAlloc(GHND, dwSize);
+ if (!hdib)
+ return hdib;
+
+ LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)GlobalLock(hdib);
+ lpbi->biSize = sizeof(BITMAPINFOHEADER);
+ lpbi->biWidth = bitmap.bmWidth;
+ lpbi->biHeight = bitmap.bmHeight;
+ lpbi->biPlanes = 1;
+ lpbi->biBitCount = (WORD) bits;
+ lpbi->biCompression = BI_RGB;
+ lpbi->biSizeImage = dwSize - sizeof(BITMAPINFOHEADER) - wColSize;
+ lpbi->biXPelsPerMeter = 0;
+ lpbi->biYPelsPerMeter = 0;
+ lpbi->biClrUsed = (bits <= 8) ? 1<<bits : 0;
+ lpbi->biClrImportant = 0;
+
+ // Get the bits from the bitmap and stuff them after the LPBI
+ LPBYTE lpBits = (LPBYTE)(lpbi + 1) + wColSize;
+
+ HDC hdc = ::CreateCompatibleDC(NULL);
+
+ ::GetDIBits(hdc, hbitmap, 0, bitmap.bmHeight, lpBits, (LPBITMAPINFO)lpbi, DIB_RGB_COLORS);
+ lpbi->biClrUsed = (bits <= 8) ? (1 << bits) : 0;
+
+ ::DeleteDC(hdc);
+ ::GlobalUnlock(hdib);
+
+ return hdib;
+}
+
+void SaveBitmapCopy(HBITMAP& hBitmap, HDC hdc, HDC hdcbits, int x, int y, int sx, int sy)
+{
+ if (hBitmap) {
+ ::DeleteObject(hBitmap);
+ }
+ hBitmap = (HBITMAP) ::CreateCompatibleBitmap(hdc, sx, sy);
+ HBITMAP oldbitmap = (HBITMAP) ::SelectObject(hdcbits, hBitmap);
+ ::BitBlt(hdcbits, 0, 0, sx, sy, hdc, x, y, SRCCOPY);
+
+ ::SelectObject(hdcbits, oldbitmap);
+}
+
+void SaveBitmapCopy(HBITMAP& hBitmap, HDC hdc, HDC hdcbits, const RECT& rect)
+{
+ SaveBitmapCopy(hBitmap, hdc, hdcbits, rect.left, rect.top, (rect.right-rect.left), (rect.bottom-rect.top));
+}
+
+void RestoreBitmapCopy(HBITMAP& hBitmap, HDC hdc, HDC hdcbits, int x, int y, int sx, int sy)
+{
+ if (!hBitmap) {
+ return;
+ }
+ HBITMAP oldbitmap = (HBITMAP) ::SelectObject(hdcbits, hBitmap);
+ ::BitBlt(hdc, x, y, sx, sy, hdcbits, 0, 0, SRCCOPY);
+ ::SelectObject(hdcbits, oldbitmap);
+ ::DeleteObject(hBitmap);
+ hBitmap = 0;
+}
+
+void RestoreBitmapCopy(HBITMAP& hBitmap, HDC hdc, HDC hdcbits, const RECT& rect)
+{
+ RestoreBitmapCopy(hBitmap, hdc, hdcbits, rect.left, rect.top, (rect.right-rect.left), (rect.bottom-rect.top));
+}
14 CamStudio/CamLib/CamImage.h
@@ -0,0 +1,14 @@
+// CamImage.h - include file for CamStudio Library image api's
+/////////////////////////////////////////////////////////////////////////////
+#ifndef CAMIMAGE_H
+#define CAMIMAGE_H
+
+#pragma once
+
+HANDLE Bitmap2Dib(HBITMAP hbitmap, UINT bits);
+void SaveBitmapCopy(HBITMAP& hBitmap, HDC hdc, HDC hdcbits, const RECT& rect);
+void SaveBitmapCopy(HBITMAP& hBitmap, HDC hdc, HDC hdcbits, int x, int y, int sx, int sy);
+void RestoreBitmapCopy(HBITMAP& hBitmap, HDC hdc, HDC hdcbits, const RECT& rect);
+void RestoreBitmapCopy(HBITMAP& hBitmap, HDC hdc, HDC hdcbits, int x, int y, int sx, int sy);
+
+#endif // CAMIMAGE_H
285 CamStudio/CamLib/CamLib.vcproj
@@ -0,0 +1,285 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="CamLib"
+ ProjectGUID="{90BC3E7C-3D9B-4D95-9A6A-18DE32AE0208}"
+ RootNamespace="CamLib"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="4"
+ UseOfMFC="2"
+ CharacterSet="0"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
+ MinimalRebuild="false"
+ BasicRuntimeChecks="1"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="2"
+ WarningLevel="4"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="4"
+ UseOfMFC="2"
+ CharacterSet="0"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="2"
+ WarningLevel="4"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\CamError.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\CamFile.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\CamImage.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\CamRect.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\CamSys.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\CamWindow.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\CBitmapEx.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\CStudiolib.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\Recorder\FrameGrabber.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\Picture.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\stdafx.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="1"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="1"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\TrayIcon.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath=".\CamError.h"
+ >
+ </File>
+ <File
+ RelativePath=".\CamFile.h"
+ >
+ </File>
+ <File
+ RelativePath=".\CamImage.h"
+ >
+ </File>
+ <File
+ RelativePath=".\CamRect.h"
+ >
+ </File>
+ <File
+ RelativePath=".\CamSys.h"
+ >
+ </File>
+ <File
+ RelativePath=".\CamWindow.h"
+ >
+ </File>
+ <File
+ RelativePath=".\CBitmapEx.h"
+ >
+ </File>
+ <File
+ RelativePath=".\CStudioLib.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Picture.h"
+ >
+ </File>
+ <File
+ RelativePath=".\stdafx.h"
+ >
+ </File>
+ <File
+ RelativePath=".\targetver.h"
+ >
+ </File>
+ <File
+ RelativePath=".\TrayIcon.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ <File
+ RelativePath="..\hook\hook.rc"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
175 CamStudio/CamLib/CamLib.vcxproj
@@ -0,0 +1,175 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{90BC3E7C-3D9B-4D95-9A6A-18DE32AE0208}</ProjectGuid>
+ <RootNamespace>CamLib</RootNamespace>
+ <Keyword>Win32Proj</Keyword>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseOfMfc>Dynamic</UseOfMfc>
+ <CharacterSet>NotSet</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseOfMfc>Dynamic</UseOfMfc>
+ <CharacterSet>NotSet</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseOfMfc>Dynamic</UseOfMfc>
+ <CharacterSet>NotSet</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseOfMfc>Dynamic</UseOfMfc>
+ <CharacterSet>NotSet</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup>
+ <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Configuration)\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Configuration)\</IntDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Configuration)\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Configuration)\</IntDir>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <MinimalRebuild>false</MinimalRebuild>
+ <BasicRuntimeChecks>StackFrameRuntimeCheck</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <WarningLevel>Level4</WarningLevel>
+ <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+ </ClCompile>
+ <Lib>
+ <TargetMachine>MachineX86</TargetMachine>
+ </Lib>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <MinimalRebuild>false</MinimalRebuild>
+ <BasicRuntimeChecks>StackFrameRuntimeCheck</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <WarningLevel>Level4</WarningLevel>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ </ClCompile>
+ <Lib>
+ <TargetMachine>MachineX64</TargetMachine>
+ </Lib>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <Optimization>MaxSpeed</Optimization>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <WarningLevel>Level4</WarningLevel>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ </ClCompile>
+ <Lib>
+ <TargetMachine>MachineX86</TargetMachine>
+ </Lib>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <Optimization>MaxSpeed</Optimization>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <WarningLevel>Level4</WarningLevel>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ </ClCompile>
+ <Lib>
+ <TargetMachine>MachineX64</TargetMachine>
+ </Lib>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="CamError.cpp" />
+ <ClCompile Include="CamFile.cpp" />
+ <ClCompile Include="CamImage.cpp" />
+ <ClCompile Include="CamRect.cpp" />
+ <ClCompile Include="CamSys.cpp" />
+ <ClCompile Include="CamWindow.cpp" />
+ <ClCompile Include="CBitmapEx.cpp" />
+ <ClCompile Include="CStudiolib.cpp" />
+ <ClCompile Include="..\Recorder\FrameGrabber.cpp" />
+ <ClCompile Include="Picture.cpp" />
+ <ClCompile Include="stdafx.cpp">
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
+ </ClCompile>
+ <ClCompile Include="TrayIcon.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="CamError.h" />
+ <ClInclude Include="CamFile.h" />
+ <ClInclude Include="CamImage.h" />
+ <ClInclude Include="CamRect.h" />
+ <ClInclude Include="CamSys.h" />
+ <ClInclude Include="CamWindow.h" />
+ <ClInclude Include="CBitmapEx.h" />
+ <ClInclude Include="CStudioLib.h" />
+ <ClInclude Include="Picture.h" />
+ <ClInclude Include="stdafx.h" />
+ <ClInclude Include="targetver.h" />
+ <ClInclude Include="TrayIcon.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="..\hook\hook.rc" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
98 CamStudio/CamLib/CamLib.vcxproj.filters
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Source Files">
+ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+ <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+ </Filter>
+ <Filter Include="Header Files">
+ <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+ <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+ </Filter>
+ <Filter Include="Resource Files">
+ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+ <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="CamError.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="CamFile.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="CamImage.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="CamRect.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="CamSys.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="CamWindow.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="CBitmapEx.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="CStudiolib.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\Recorder\FrameGrabber.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Picture.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="stdafx.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="TrayIcon.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="CamError.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="CamFile.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="CamImage.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="CamRect.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="CamSys.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="CamWindow.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="CBitmapEx.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="CStudioLib.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Picture.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="stdafx.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="targetver.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="TrayIcon.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="..\hook\hook.rc">
+ <Filter>Resource Files</Filter>
+ </ResourceCompile>
+ </ItemGroup>
+</Project>
3  CamStudio/CamLib/CamLib.vcxproj.user
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+</Project>
72 CamStudio/CamLib/CamRect.cpp
@@ -0,0 +1,72 @@
+// recatangle.cpp - CamStudio Library rectangle functions
+/////////////////////////////////////////////////////////////////////////////
+#include "StdAfx.h"
+#include "CamRect.h"
+
+BOOL isRectEqual(RECT a, RECT b)
+{
+ CRect rectA(a);
+ return rectA == b;
+
+ //if ((a.left == b.left)
+ // && (a.right == b.right)
+ // && (a.top == b.top)
+ // && (a.bottom == b.bottom))
+ // return TRUE;
+ //else
+ // return FALSE;
+}
+
+// The rectangle is normalized for fourth-quadrant positioning, which Windows typically uses for coordinates.
+// this is dubious
+void NormalizeRect(LPRECT prc)
+{
+ CRect rectSrc(*prc);
+ rectSrc.NormalizeRect();
+ ::CopyRect(prc, rectSrc);
+}
+
+void FixRectSizePos(LPRECT prc, int maxxScreen, int maxyScreen, int minxScreen, int minyScreen)
+{
+ // TRACE( _T("## FixRectSizePos # PRE # prc: top=%d bottom=%d left=%d right=%d\n"), prc->top, prc->bottom, prc->left, prc->right );
+ NormalizeRect(prc);
+
+ int width = prc->right - prc->left + 1;
+ int height = prc->bottom - prc->top + 1;
+ // TRACE( _T("## FixRectSizePos # # prc: width=%d height=%d \n"), width, height );
+
+ //check that rectangle isn't too wide
+ if (width > abs(maxxScreen-minxScreen)) {
+ prc->left = minxScreen;
+ prc->right = maxxScreen - 1;
+ }
+ else
+ {
+ //adjust left and right to make sure its on the screen
+ // First position on screen is mostly zero not one
+ if (prc->left < minxScreen) {
+ prc->left = minxScreen;
+ }
+ // Last position on screen is not screenwidth but one less because firts is zero
+ if (prc->right > maxxScreen - 1) {
+ prc->right = maxxScreen - 1;
+ }
+ }
+
+ //check that rectangle isn't too tall
+ if (height > abs(maxyScreen-minyScreen)) {
+ prc->top = minyScreen;
+ prc->bottom = maxyScreen - 1;
+ }
+ else
+ {
+ //adjust top and bottom to make sure its on the screen
+ if (prc->top < minyScreen) {
+ prc->top = minyScreen;
+ }
+ if (prc->bottom > maxyScreen - 1) {
+ prc->bottom = maxyScreen - 1;
+ }
+ }
+ //TRACE( _T("## FixRectSizePos # POST # prc: top=%d bottom=%d left=%d right=%d\n"), prc->top, prc->bottom, prc->left, prc->right );
+}
13 CamStudio/CamLib/CamRect.h
@@ -0,0 +1,13 @@
+// CamRect.h - include file for CamStudio Library rectangle api's
+/////////////////////////////////////////////////////////////////////////////
+#ifndef CAMRECT_H
+#define CAMRECT_H
+
+#pragma once
+
+// CamRect.cpp
+BOOL isRectEqual(RECT a, RECT b);
+void NormalizeRect(LPRECT prc);
+void FixRectSizePos(LPRECT prc,int maxxScreen, int maxyScreen, int minxScreen, int minyScreen);
+
+#endif // CAMRECT_H
43 CamStudio/CamLib/CamSys.cpp
@@ -0,0 +1,43 @@
+// CamSys.cpp - CamStudio Library file functions
+/////////////////////////////////////////////////////////////////////////////
+#include "StdAfx.h"
+#include "CamSys.h"
+
+int GetOperatingSystem()
+{
+ OSVERSIONINFO osv;
+ ::ZeroMemory(&osv, sizeof (OSVERSIONINFO));
+ osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ return (::GetVersionEx(&osv)) ? osv.dwMajorVersion : 0;
+}
+
+// message processing loop to allow thread to yield to other threads
+BOOL WinYield()
+{
+ //Process 3 messages, then return false
+ MSG msg;
+ for (int i = 0; i < 3; i++) {
+ if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+ ::TranslateMessage(&msg);
+ ::DispatchMessage(&msg);
+ }
+ }
+
+ return FALSE;
+}
+
+LONG GetRegKey (HKEY key, LPCTSTR subkey, LPTSTR retdata)
+{
+ HKEY hkey;
+ LONG retval = ::RegOpenKeyEx (key, subkey, 0, KEY_QUERY_VALUE, &hkey);
+ if (retval == ERROR_SUCCESS)
+ {
+ long datasize = MAX_PATH;
+ TCHAR data[MAX_PATH];
+ ::RegQueryValue (hkey, NULL, data, &datasize);
+ // _tcscpy (retdata, data); // Cause C4996 warning, marked as deprecation candidate
+ strcpy_s(retdata, sizeof(retdata), data ); // Safe replacement
+ ::RegCloseKey (hkey);
+ }
+ return retval;
+}
12 CamStudio/CamLib/CamSys.h
@@ -0,0 +1,12 @@
+// CamSys.h - include file for CamStudio Library system api's
+/////////////////////////////////////////////////////////////////////////////
+#ifndef CAMSYS_H
+#define CAMSYS_H
+
+#pragma once
+
+int GetOperatingSystem();
+BOOL WinYield();
+LONG GetRegKey (HKEY key, LPCTSTR subkey, LPTSTR retdata);
+
+#endif // CAMSYS_H
60 CamStudio/CamLib/CamWindow.cpp
@@ -0,0 +1,60 @@
+// CamWindow.cpp - CamStudio Library window functions
+/////////////////////////////////////////////////////////////////////////////
+#include "StdAfx.h"
+#include "CamWindow.h"
+
+// TODO: should be in mainframe class
+#pragma message("SetTitleBar depreciated; use MainFrame class")
+void SetTitleBar(CString title)
+{
+ CWinApp* app = AfxGetApp();
+ if (app) {
+ HWND mainwnd = app->m_pMainWnd->m_hWnd;
+ if (mainwnd) {
+ ::SetWindowText(mainwnd, LPCTSTR(title));
+ }
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// FrameWindow()
+// Highlight the window frame
+/////////////////////////////////////////////////////////////////////////////
+#pragma message("FrameWindow obsolete")
+RECT FrameWindow(HWND hWnd, int maxxScreen, int maxyScreen, RECT rcClip)
+{
+ RECT rectWin;
+ rectWin.left = 0;
+ rectWin.top = 0;
+ rectWin.right = maxxScreen - 1;
+ rectWin.bottom = maxyScreen - 1;
+
+ if (!IsWindow(hWnd)) {
+ return rectWin;
+ }
+
+ HDC hdc = ::GetWindowDC(hWnd);
+ ::GetWindowRect(hWnd, &rectWin);
+
+ RECT rectFrame = rectWin;
+ ::OffsetRect(&rectFrame, -rectFrame.left, -rectFrame.top);
+
+ if (!IsRectEmpty(&rectFrame)) {
+ HBRUSH newbrush = (HBRUSH) ::CreateHatchBrush(HS_BDIAGONAL, RGB(0, 0, 100));
+ HBRUSH oldbrush = (HBRUSH) ::SelectObject(hdc, newbrush);
+
+ const int DINV = 3;
+ ::PatBlt(hdc, rcClip.left, rcClip.top, rcClip.right - rcClip.left, DINV, PATINVERT);
+ ::PatBlt(hdc, rcClip.left, rcClip.bottom - DINV, DINV, -(rcClip.bottom - rcClip.top -2 * DINV), PATINVERT);
+ ::PatBlt(hdc, rcClip.right - DINV, rcClip.top + DINV, DINV, rcClip.bottom - rcClip.top - 2 * DINV, PATINVERT);
+ ::PatBlt(hdc, rcClip.right, rcClip.bottom - DINV, -(rcClip.right - rcClip.left), DINV, PATINVERT);
+
+ ::SelectObject(hdc,oldbrush);
+ ::DeleteObject(newbrush);
+ }
+
+ ::ReleaseDC(hWnd, hdc);
+
+ return rectWin;
+}
+
13 CamStudio/CamLib/CamWindow.h
@@ -0,0 +1,13 @@
+// CamWindow.h - include file for CamStudio Library window api's
+/////////////////////////////////////////////////////////////////////////////
+#ifndef CAMWINDOW_H
+#define CAMWINDOW_H
+
+#pragma once
+
+// CamWindow.cpp
+// Window
+void SetTitleBar(CString title);
+RECT FrameWindow(HWND hWnd, int maxxScreen, int maxyScreen, RECT rcClip);
+
+#endif // CAMWINDOW_H
784 CamStudio/CamLib/Picture.cpp
@@ -0,0 +1,784 @@
+//-----------------------------------------------------------------------------
+// Picture (Implementations) Version 1.00
+//
+// Routins 4 Showing Picture Files... (.BMP .DIB .EMF .GIF .ICO .JPG .WMF)
+//
+// Author: Dr. Yovav Gad, EMail: Sources@SuperMain.com ,Web: www.SuperMain.com
+//=============================================================================
+//
+// Full Story:
+// ~~~~~~~~~~~
+// There R Many Libraries To Handle Image Files, Anyway Most Of Them Do Not
+// Include Source Files Or Just Very Complicated To Implement / Understand,
+//
+// After Many Days Of Searching (And Not Finding) a Way To Load a JPG From a
+// Resource And Show It On a *Dialog Based* Application, I Decided 2 Take Steps
+//
+// So I Created What I Call a Very *Simple* & Useful Class,
+// It Can Easily Implemented By Adding It To a Project, And U Do Not Have To
+// Be a Real JPEG Freak - And Invent All Header Reading From The Beginning
+// (It Uses The IPicture Interface - Same Way As Internet Explorer Does)
+//
+// I Would Like To Thank Mr.Peter Hendrix For His Wonderful Work
+// That I Found On: http://www.thecodeproject.com/bitmap/cpicture.asp
+// Which I Was Inspired And Got The IPicture Interface Idea From...
+//
+// Guess U Will Find It Useful,
+// Appreciate If U Can Mention My Name On Your Final Code,
+// Please Feel Free To Send Me Any Improvements Or SaveAsJPG() Functions:
+//
+// (This Program Has No Bugs - Only Undocumented Solutions)
+//
+// Author: Dr. Yovav Gad, EMail: Sources@SuperMain.com ,Web: www.SuperMain.com
+//
+//--------------------------Example & Usage 4 Dummies--------------------------
+//
+// U Need 2 Add "CPicture.CPP" and "CPicture.H" Into Your Project (From FileView)
+// So U Will Get Control Over The Functions In This Class,
+// Then U Can Create a Picture Object And Show It On a Device Context
+//
+// CPicture m_Picture; // Create a Picture Object (An Instance Of This Class)
+// #include "Picture.h" // Make Sure U Include This Where U Gonna Create The Object...
+//
+// Load Picture Data Into The IPicture Interface (.BMP .DIB .EMF .GIF .ICO .JPG .WMF)
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// m_Picture.Load("Test.JPG"); // Load From a File - Just Load It (Show Later)
+// m_Picture.Load(IDR_TEST, "JPG"); // Load From a Resource - Just Load It (Show Later)
+// (U Must Include IDR_TEST In Your Resources Under a Custom Name, 4 Example - "JPG")
+//
+// When Using DC Object On a *Dialog Based* Application (CPaintDC dc(this);)
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// Get Picture Dimentions In Pixels
+// m_Picture.UpdateSizeOnDC(&dc);
+//
+// m_Picture.Show(&dc, CPoint(0,0), CPoint(m_Picture.m_Width, m_Picture.m_Height), 0,0);
+//
+// Change Original Dimentions
+// m_Picture.Show(&dc, CRect(0,0,100,100));
+//
+// Show Bitmap Resource
+// m_Picture.ShowBitmapResource(&dc, IDB_TEST, CPoint(0,0));
+//
+// OR When Using a Pointer On a "Regular" MFC Application (CDC* pDC)
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// m_Picture.UpdateSizeOnDC(pDC); // Get Picture Dimentions In Pixels
+// m_Picture.Show(pDC, CPoint(0,0), CPoint(m_Picture.m_Width, m_Picture.m_Height), 0,0);
+// m_Picture.Show(pDC, CRect(0,0,100,100)); // Change Original Dimentions
+// m_Picture.ShowBitmapResource(pDC, IDB_TEST, CPoint(0,0)); // Show Bitmap Resource
+//
+// Show Picture Information
+// ~~~~~~~~~~~~~~~~~~~~~~~~
+// CString S;
+// S.Format("Size = %4d\nWidth = %4d\nHeight = %4d\nWeight = %4d\n",
+// m_Picture.m_Weight, m_Picture.m_Width, m_Picture.m_Height, m_Picture.m_Weight);
+// AfxMessageBox(S);
+//
+//----------------------------Cut The Bullshit Here----------------------------
+
+#include "stdafx.h"
+#include "Picture.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+#define HIMETRIC_INCH 2540
+#define ERROR_TITLE TEXT("CPicture Error") // Error Title (Related To This Class)...
+
+//-----------------------------------------------------------------------------
+// Does: Constructor - Create a New CPicture Object To Hold Picture Data
+// ~~~~
+//
+//-----------------------------------------------------------------------------
+//=============================================================================
+CPicture::CPicture()
+: m_IPicture(0)
+, m_Height(0)
+, m_Weight(0)
+, m_Width(0)
+{
+}
+
+//-----------------------------------------------------------------------------
+// Does: Destructor - Free Data And Information From The CPicture Object
+// ~~~~
+//
+//-----------------------------------------------------------------------------
+//=============================================================================
+CPicture::~CPicture()
+{
+ FreePictureData(); // Important - Avoid Leaks...
+}
+
+//-----------------------------------------------------------------------------
+// Does: Free The Allocated Memory That Holdes The IPicture Interface Data
+// ~~~~ And Clear Picture Information
+//
+// Note: This Might Also Be Useful If U Only Need To Show The Picture Once
+// ~~~~~ Or If U Copy The Picture To The Device Context, So It Can Still
+// Remain On Screen - But IPicture Data Is Not Needed No More
+//
+//-----------------------------------------------------------------------------
+//=============================================================================
+void CPicture::FreePictureData()
+{
+ if (m_IPicture != NULL) {
+ m_IPicture->Release();
+ m_IPicture = NULL;
+ m_Height = 0;
+ m_Weight = 0;
+ m_Width = 0;
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Does: Open a Resource And Load It Into IPicture (Interface)
+// ~~~~ (.BMP .DIB .EMF .GIF .ICO .JPG .WMF)
+//
+// Note: When Adding a Bitmap Resource It Would Automatically Show On "Bitmap"
+// ~~~~ This NOT Good Coz We Need To Load It From a Custom Resource "BMP"
+// To Add a Custom Rresource: Import Resource -> Open As -> Custom
+// (Both .BMP And .DIB Should Be Found Under "BMP")
+//
+// InPut: ResourceName - As a UINT Defined (Example: IDR_PICTURE_RESOURCE)
+// ~~~~~ ResourceType - Type Name (Example: "JPG")
+//
+// OutPut: TRUE If Succeeded...
+// ~~~~~~
+//-----------------------------------------------------------------------------
+//=============================================================================
+BOOL CPicture::Load(UINT ResourceName, LPCTSTR ResourceType)
+{
+ BOOL bResult = FALSE;
+
+ HGLOBAL hGlobal = NULL;
+ HRSRC hSource = NULL;
+ LPVOID lpVoid = NULL;
+ int nSize = 0;
+
+ if (m_IPicture != NULL)
+ FreePictureData(); // Important - Avoid Leaks...
+
+ hSource = FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE(ResourceName), ResourceType);
+
+ if (hSource == NULL) {
+ HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
+ MessageBoxEx(hWnd, TEXT("FindResource() Failed\t"), ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
+ return(FALSE);
+ }
+
+ hGlobal = LoadResource(AfxGetResourceHandle(), hSource);
+ if (hGlobal == NULL) {
+ HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
+ MessageBoxEx(hWnd, TEXT("LoadResource() Failed\t"), ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
+ return(FALSE);
+ }
+
+ lpVoid = LockResource(hGlobal);
+ if (lpVoid == NULL) {
+ HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
+ MessageBoxEx(hWnd, TEXT("LockResource() Failed\t"), ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
+ return(FALSE);
+ }
+
+ nSize = (UINT)SizeofResource(AfxGetResourceHandle(), hSource);
+ if (LoadPictureData((BYTE*)hGlobal, nSize))
+ bResult = TRUE;
+
+ UnlockResource(hGlobal); // 16Bit Windows Needs This
+ FreeResource(hGlobal); // 16Bit Windows Needs This (32Bit - Automatic Release)
+
+ m_Weight = nSize; // Update Picture Size Info...
+
+ // Do Not Try To Read From Memory That Is Not Exist...
+ if (m_IPicture != NULL) {
+ m_IPicture->get_Height(&m_Height);
+ m_IPicture->get_Width(&m_Width);
+ // Calculate Its Size On a "Standard" (96 DPI) Device Context
+ m_Height = MulDiv(m_Height, 96, HIMETRIC_INCH);
+ m_Width = MulDiv(m_Width, 96, HIMETRIC_INCH);
+ } else {
+ // Picture Data Is Not a Known Picture Type
+ m_Height = 0;
+ m_Width = 0;
+ bResult = FALSE;
+ }
+
+ return(bResult);
+}
+
+//-----------------------------------------------------------------------------
+// Does: Open a File And Load It Into IPicture (Interface)
+// ~~~~ (.BMP .DIB .EMF .GIF .ICO .JPG .WMF)
+//
+// InPut: sFilePathName - Path And FileName Target To Save
+// ~~~~~
+//
+// OutPut: TRUE If Succeeded...
+// ~~~~~~
+//-----------------------------------------------------------------------------
+//=============================================================================
+BOOL CPicture::Load(CString sFilePathName)
+{
+ BOOL bResult = FALSE;
+ CFile PictureFile;
+ CFileException e;
+ int nSize = 0;
+
+ if (m_IPicture != NULL)
+ FreePictureData(); // Important - Avoid Leaks...
+
+ if (PictureFile.Open(sFilePathName, CFile::modeRead | CFile::typeBinary, &e)) {
+
+ // Prevent C4244 warning and take some predictions for unwanted truncations
+ // nSize = PictureFile.GetLength(); -> Cause C4244 warning
+ ULONGLONG tmpUlongSize = PictureFile.GetLength();
+ if ( tmpUlongSize != static_cast<int>(tmpUlongSize) ) {
+ TRACE("Error: nSize, Casted value [%i] is not the same as uncasted [%l] ..!\n", static_cast<int>(tmpUlongSize),tmpUlongSize);
+ }
+ // Now assigned tested casted value to dest value (Functional nothing is changed but we have a marker in the tracelog if truncated)
+ nSize = static_cast<int>(tmpUlongSize);
+
+ BYTE* pBuffer = new BYTE[nSize];
+
+ if (PictureFile.Read(pBuffer, nSize) > 0) {
+ if (LoadPictureData(pBuffer, nSize)) bResult = TRUE;
+ }
+
+ PictureFile.Close();
+ delete [] pBuffer;
+ } else {
+ // Open Failed...
+ TCHAR szCause[255];
+ e.GetErrorMessage(szCause, 255, NULL);
+ HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
+ MessageBoxEx(hWnd, szCause, ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
+ bResult = FALSE;
+ }
+
+ m_Weight = nSize; // Update Picture Size Info...
+
+ // Do Not Try To Read From Memory That Is Not Exist...
+ if (m_IPicture != NULL) {
+ m_IPicture->get_Height(&m_Height);
+ m_IPicture->get_Width(&m_Width);
+ // Calculate Its Size On a "Standard" (96 DPI) Device Context
+ m_Height = MulDiv(m_Height, 96, HIMETRIC_INCH);
+ m_Width = MulDiv(m_Width, 96, HIMETRIC_INCH);
+ } else {
+ // Picture Data Is Not a Known Picture Type
+ m_Height = 0;
+ m_Width = 0;
+ bResult = FALSE;
+ }
+
+ return(bResult);
+}
+
+//-----------------------------------------------------------------------------
+// Does: Read The Picture Data From a Source (File / Resource)
+// ~~~~ And Load It Into The Current IPicture Object In Use
+//
+// InPut: Buffer Of Data Source (File / Resource) And Its Size
+// ~~~~~
+//
+// OutPut: Feed The IPicture Object With The Picture Data
+// ~~~~~~ (Use Draw Functions To Show It On a Device Context)
+// TRUE If Succeeded...
+//-----------------------------------------------------------------------------
+//=============================================================================
+BOOL CPicture::LoadPictureData(BYTE *pBuffer, int nSize)
+{
+ BOOL bResult = FALSE;
+
+ HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, nSize);
+
+ if (hGlobal == NULL) {
+ HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
+ MessageBoxEx(hWnd, TEXT("Can not allocate enough memory\t"), ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
+ return(FALSE);
+ }
+
+ void* pData = GlobalLock(hGlobal);
+ memcpy(pData, pBuffer, nSize);
+ GlobalUnlock(hGlobal);
+
+ IStream* pStream = NULL;
+
+ if (CreateStreamOnHGlobal(hGlobal, TRUE, &pStream) == S_OK) {
+ HRESULT hr;
+ if ((hr = OleLoadPicture(pStream, nSize, FALSE, IID_IPicture, (LPVOID *)&m_IPicture)) == E_NOINTERFACE) {
+ HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
+ MessageBoxEx(hWnd, TEXT("IPicture interface is not supported\t"), ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
+ return(FALSE);
+ } else {
+ // S_OK
+ pStream->Release();
+ pStream = NULL;
+ bResult = TRUE;
+ }
+ }
+
+ FreeResource(hGlobal); // 16Bit Windows Needs This (32Bit - Automatic Release)
+
+ return(bResult);
+}
+
+//-----------------------------------------------------------------------------
+// Does: Draw The Loaded Picture Direct To The Client DC
+// ~~~~
+//
+// Note: Bigger OR Smaller Dimentions Than The Original Picture Size
+// ~~~~ Will Draw The Picture Streached To Its New Given NEW Dimentions...
+//
+// InPut: pDC - Given DC To Draw On
+// ~~~~~ DrawRect - Dimentions Of The Picture To Draw (As a Rectangle)
+//
+// OutPut: TRUE If Succeeded...
+// ~~~~~~
+//-----------------------------------------------------------------------------
+//=============================================================================
+BOOL CPicture::Show(CDC *pDC, CRect DrawRect)
+{
+ if (pDC == NULL || m_IPicture == NULL)
+ return FALSE;
+
+ long Width = 0;
+ long Height = 0;
+ m_IPicture->get_Width(&Width);
+ m_IPicture->get_Height(&Height);
+
+ HRESULT hrP = m_IPicture->Render(pDC->m_hDC
+ , DrawRect.left
+ , DrawRect.top
+ , DrawRect.right - DrawRect.left
+ , DrawRect.bottom - DrawRect.top
+ , 0
+ , Height
+ , Width
+ , -Height
+ , &DrawRect);
+ if (SUCCEEDED(hrP))
+ return(TRUE);
+
+ HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
+ MessageBoxEx(hWnd, TEXT("Can not allocate enough memory\t"), ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
+ return(FALSE);
+}
+
+//-----------------------------------------------------------------------------
+// Does: Draw The Loaded Picture Direct To The Client DC
+// ~~~~
+//
+// Note: Bigger OR Smaller Dimentions Than The Original Picture Size
+// ~~~~ Will Draw The Picture Streached To Its New Given Dimentions...
+//
+// InPut: pDC - Given DC To Draw On
+// ~~~~~ LeftTop - Opening Point To Start Drawing (Left,Top)
+// WidthHeight - Dimentions Of The Picture To Draw (Width,Height)
+// MagnifyX - Magnify Pixel Width, 0 = Default (No Magnify)
+// MagnifyY - Magnify Pixel Height, 0 = Default (No Magnify)
+//
+// OutPut: TRUE If Succeeded...
+// ~~~~~~
+//-----------------------------------------------------------------------------
+//=============================================================================
+BOOL CPicture::Show(CDC *pDC, CPoint LeftTop, CPoint WidthHeight, int MagnifyX, int MagnifyY)
+{
+ if (pDC == NULL || m_IPicture == NULL)
+ return FALSE;
+
+ long Width = 0;
+ long Height = 0;
+ m_IPicture->get_Width(&Width);
+ m_IPicture->get_Height(&Height);
+ if (MagnifyX == NULL)
+ MagnifyX = 0;
+ if (MagnifyY == NULL)
+ MagnifyY = 0;
+ MagnifyX = int(MulDiv(Width, pDC->GetDeviceCaps(LOGPIXELSX), HIMETRIC_INCH) * MagnifyX);
+ MagnifyY = int(MulDiv(Height,pDC->GetDeviceCaps(LOGPIXELSY), HIMETRIC_INCH) * MagnifyY);
+
+ CRect DrawRect(LeftTop.x, LeftTop.y, MagnifyX, MagnifyY);
+
+ HRESULT hrP = m_IPicture->Render(pDC->m_hDC
+ , LeftTop.x
+ , LeftTop.y
+ , WidthHeight.x + MagnifyX
+ , WidthHeight.y + MagnifyY
+ , 0
+ , Height
+ , Width
+ , -Height
+ , &DrawRect);
+
+ if (SUCCEEDED(hrP))
+ return(TRUE);
+
+ HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
+ MessageBoxEx(hWnd, TEXT("Can not allocate enough memory\t"), ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
+ return(FALSE);
+}
+
+//-----------------------------------------------------------------------------
+// Does: Saves The Picture That Is Stored In The IPicture Object As a Bitmap
+// ~~~~ (Converts From Any Known Picture Type To a Bitmap / Icon File)
+//
+// InPut: sFilePathName - Path And FileName Target To Save
+// ~~~~~
+//
+// OutPut: TRUE If Succeeded...
+// ~~~~~~
+//-----------------------------------------------------------------------------
+//=============================================================================
+BOOL CPicture::SaveAsBitmap(CString sFilePathName)
+{
+ BOOL bResult = FALSE;
+ ILockBytes *Buffer = 0;
+ IStorage *pStorage = 0;
+ IStream *FileStream = 0;
+ BYTE *BufferBytes = 0;
+ STATSTG BytesStatistics;
+ DWORD OutData = 0;
+ long OutStream = 0L;
+ CFile BitmapFile; CFileException e;
+ double SkipFloat = 0;
+ DWORD ByteSkip = 0;
+ _ULARGE_INTEGER RealData;
+
+ CreateILockBytesOnHGlobal(NULL, TRUE, &Buffer); // Create ILockBytes Buffer
+
+ HRESULT hr = ::StgCreateDocfileOnILockBytes(Buffer, STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE, 0, &pStorage);
+ hr = pStorage->CreateStream(L"PICTURE", STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE, 0, 0, &FileStream);
+
+ m_IPicture->SaveAsFile(FileStream, TRUE, &OutStream); // Copy Data Stream
+ FileStream->Release();
+ pStorage->Release();
+ Buffer->Flush();
+
+ // Get Statistics For Final Size Of Byte Array
+ Buffer->Stat(&BytesStatistics, STATFLAG_NONAME);
+
+ // Cut UnNeeded Data Coming From SaveAsFile() (Leave Only "Pure" Picture Data)
+ SkipFloat = (double(OutStream) / 512); // Must Be In a 512 Blocks...
+ if (SkipFloat > DWORD(SkipFloat))
+ ByteSkip = (DWORD)SkipFloat + 1;
+ else
+ ByteSkip = (DWORD)SkipFloat;
+ ByteSkip = ByteSkip * 512; // Must Be In a 512 Blocks...
+
+ // Find Difference Between The Two Values
+ ByteSkip = (DWORD)(BytesStatistics.cbSize.QuadPart - ByteSkip);
+
+ // Allocate Only The "Pure" Picture Data
+ RealData.LowPart = 0;
+ RealData.HighPart = 0;
+ RealData.QuadPart = ByteSkip;
+ BufferBytes = (BYTE*)malloc(OutStream);
+ if (BufferBytes == NULL) {
+ Buffer->Release();
+ HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
+ MessageBoxEx(hWnd, TEXT("Can not allocate enough memory\t"), ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
+ }
+
+ Buffer->ReadAt(RealData, BufferBytes, OutStream, &OutData);
+
+ if (BitmapFile.Open(sFilePathName, CFile::typeBinary | CFile::modeCreate | CFile::modeWrite, &e)) {
+ BitmapFile.Write(BufferBytes, OutData);
+ BitmapFile.Close();
+ bResult = TRUE;
+ } else {
+ // Write File Failed...
+ TCHAR szCause[255];
+ e.GetErrorMessage(szCause, 255, NULL);
+ HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
+ MessageBoxEx(hWnd, szCause, ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
+ bResult = FALSE;
+ }
+
+ Buffer->Release();
+ free(BufferBytes);
+
+ return(bResult);
+}
+
+//-----------------------------------------------------------------------------
+// Does: Draw a Bitmap Resource To The Client DC (Using Bitblt())
+// ~~~~ It Will Use The Bitmap Resource Original Size (Width And Height)
+// (.BMP .DIB)
+//
+// Note: This Function Is Just Another Simple Way Of Displaying a Bitmap Resource,
+// ~~~~ It Is Not Connected With The IPicture Interface And Can Be Used
+// As a StandAlone On Any Device Context (Directly)
+//
+// InPut: BMPResource - Resource Name As Defined In The Resources
+// ~~~~~ pDC - Given DC To Draw On
+// LeftTop - Opening Point To Start Drawing (Left,Top)
+//
+// OutPut: TRUE If Succeeded...
+// ~~~~~~
+//-----------------------------------------------------------------------------
+//=============================================================================
+BOOL CPicture::ShowBitmapResource(CDC *pDC, const int BMPResource, CPoint LeftTop)
+{
+ if (pDC == NULL)
+ return(FALSE);
+
+ CBitmap BMP;
+ if (BMP.LoadBitmap(BMPResource)) {
+ // Get Bitmap Details
+ BITMAP BMPInfo;
+ BMP.GetBitmap(&BMPInfo);
+
+ // Create An In-Memory DC Compatible With The Display DC We R Gonna Paint On
+ CDC DCMemory;
+ DCMemory.CreateCompatibleDC(pDC);
+
+ // Select The Bitmap Into The In-Memory DC
+ CBitmap* pOldBitmap = DCMemory.SelectObject(&BMP);
+
+ // Copy Bits From The In-Memory DC Into The On-Screen DC
+ pDC->BitBlt(LeftTop.x, LeftTop.y, BMPInfo.bmWidth, BMPInfo.bmHeight, &DCMemory, 0, 0, SRCCOPY);
+
+ DCMemory.SelectObject(pOldBitmap); // (As Shown In MSDN Example...)
+ } else {
+ TRACE("ERROR: Can Not Find The Bitmap Resource\n");
+ return(FALSE);
+ }
+
+ return(TRUE);
+}
+
+//-----------------------------------------------------------------------------
+// Does: Get The Original Picture Pixel Size (Ignor What Current DC Is Using)
+// ~~~~ Pointer To a Device Context Is Needed For Pixel Calculation,
+//
+// Also Updates The Class's Height And Width Properties,
+// (Coz Till Now We Had No Device Context To Work With...96 DPI Assumed)
+//
+// InPut: The Client DC (Needed To Check The Size Of The Pixels)
+// ~~~~~
+//
+// OutPut: TRUE If Succeeded...
+// ~~~~~~
+//-----------------------------------------------------------------------------
+//=============================================================================
+BOOL CPicture::UpdateSizeOnDC(CDC *pDC)
+{
+ if (pDC == NULL || m_IPicture == NULL)
+ {
+ m_Height = 0;
+ m_Width = 0;
+ return(FALSE);
+ };
+
+ m_IPicture->get_Height(&m_Height);
+ m_IPicture->get_Width(&m_Width);
+
+ // Get Current DPI - Dot Per Inch
+ int CurrentDPI_X = pDC->GetDeviceCaps(LOGPIXELSX);
+ int CurrentDPI_Y = pDC->GetDeviceCaps(LOGPIXELSY);
+
+ // Use a "Standard" Print (When Printing)
+ if (pDC->IsPrinting()) {
+ CurrentDPI_X = 96;
+ CurrentDPI_Y = 96;
+ }
+
+ m_Height = MulDiv(m_Height, CurrentDPI_Y, HIMETRIC_INCH);
+ m_Width = MulDiv(m_Width, CurrentDPI_X, HIMETRIC_INCH);
+
+ return(TRUE);
+}
+
+//=============================================================================
+BOOL CPicture::CopyToPicture(CPicture* dstPic,CString exchangeFile)
+{
+
+ if (m_IPicture==NULL)
+ return TRUE;
+
+ if (!SaveAsBitmap(exchangeFile))
+ return FALSE;
+ if (!dstPic->Load(exchangeFile))
+ return FALSE;
+
+ /* // Crash!
+ BOOL bResult = FALSE;
+ ILockBytes *Buffer = 0;
+ IStorage *pStorage = 0;
+ IStream *FileStream = 0;