svn path=/Slnkdwf/trunk/; revision=12503
This commit is contained in:
233
SlnkDWFCom/Barcode.cpp
Normal file
233
SlnkDWFCom/Barcode.cpp
Normal file
@@ -0,0 +1,233 @@
|
||||
// Barcode.cpp : Implementation of CSLNKBarcode
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "Barcode.h"
|
||||
#include "..\Barcode\code39.h"
|
||||
|
||||
// CSLNKBarcode
|
||||
|
||||
STDMETHODIMP CSLNKBarcode::InterfaceSupportsErrorInfo(REFIID riid)
|
||||
{
|
||||
static const IID* arr[] =
|
||||
{
|
||||
&IID_IBarcode
|
||||
};
|
||||
|
||||
for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
|
||||
{
|
||||
if (InlineIsEqualGUID(*arr[i],riid))
|
||||
return S_OK;
|
||||
}
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSLNKBarcode::get_Text(BSTR* pVal)
|
||||
{
|
||||
// TODO: Add your implementation code here
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSLNKBarcode::put_Text(BSTR newVal)
|
||||
{
|
||||
m_text = CString(newVal);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSLNKBarcode::get_Height(ULONG* pVal)
|
||||
{
|
||||
*pVal = m_height;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSLNKBarcode::put_Height(ULONG newVal)
|
||||
{
|
||||
m_height = newVal;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSLNKBarcode::StreamPNG(CxImage &img, VARIANT *ImageData, BOOL bPNG)
|
||||
{
|
||||
SAFEARRAY *psaData; BYTE *pData;
|
||||
SAFEARRAYBOUND rgsabound[1];
|
||||
|
||||
long size=0;
|
||||
BYTE* pBuffer=0;
|
||||
{
|
||||
{
|
||||
CmyTimer timer("CBarcode::StreamPNG/de PNG encoden");
|
||||
if (!img.Encode(pBuffer,size, bPNG?CXIMAGE_FORMAT_PNG:CXIMAGE_FORMAT_GIF))
|
||||
return myAtlReportError (GetObjectCLSID(), "\nStreamPNG encode failed: %s", img.GetLastError());
|
||||
}
|
||||
|
||||
// TODO: Echt netjes zou zijn om hier een IStream op te leveren?
|
||||
// create safe array and copy image data
|
||||
rgsabound[0].lLbound = 0; rgsabound[0].cElements = size;
|
||||
psaData = SafeArrayCreate(VT_UI1, 1, rgsabound);
|
||||
SafeArrayAccessData(psaData, (void **)&pData);
|
||||
memcpy(pData,pBuffer,size);
|
||||
SafeArrayUnaccessData(psaData);
|
||||
img.FreeMemory (pBuffer);
|
||||
// put data in variant
|
||||
ImageData->vt = (VT_ARRAY | VT_UI1);
|
||||
ImageData->parray = psaData;
|
||||
}
|
||||
myDoTRACE("\nCBarcode::StreamPNG done, sending %d bytes", size);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
bool CSLNKBarcode::CreateCxImage(CxImage *img)
|
||||
{
|
||||
CCode39 oBarcode;
|
||||
|
||||
if (m_height < 0)
|
||||
m_height = 200;
|
||||
if (m_narrow < 0)
|
||||
{
|
||||
if (m_wide > 0)
|
||||
m_narrow = myRound((double)m_wide / 3);
|
||||
else
|
||||
m_narrow = m_height / 50;
|
||||
}
|
||||
if (m_wide < 0)
|
||||
m_wide = m_narrow * 3;
|
||||
|
||||
//----
|
||||
HDC pDC = ::GetDC(0);
|
||||
HDC myDC = CreateCompatibleDC(pDC);
|
||||
|
||||
oBarcode.LoadData(myDC, m_text, m_height, m_narrow, m_wide);
|
||||
m_width = oBarcode.GetBarcodePixelWidth();
|
||||
|
||||
BITMAPINFO bmInfo;
|
||||
memset(&bmInfo.bmiHeader,0,sizeof(BITMAPINFOHEADER));
|
||||
bmInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
|
||||
bmInfo.bmiHeader.biWidth=m_width;
|
||||
bmInfo.bmiHeader.biHeight=m_height;
|
||||
bmInfo.bmiHeader.biPlanes=1;
|
||||
bmInfo.bmiHeader.biCompression=BI_RGB; // Geen compressie
|
||||
bmInfo.bmiHeader.biBitCount=24;
|
||||
|
||||
//create a new bitmap and select it in the memory dc
|
||||
BYTE *pbase;
|
||||
HBITMAP TmpBmp = CreateDIBSection(pDC, &bmInfo,DIB_RGB_COLORS,(void**)&pbase,0,0);
|
||||
//----
|
||||
|
||||
if (!TmpBmp)
|
||||
{
|
||||
myDoTRACE("\nTmpBmp==NULL when creating (%d, %d)??", m_width, m_height);
|
||||
return false;
|
||||
}
|
||||
|
||||
HGDIOBJ TmpObj=SelectObject(myDC,TmpBmp);
|
||||
|
||||
oBarcode.DrawBitmap();
|
||||
|
||||
if (!img->CreateFromHBITMAP(TmpBmp))
|
||||
{
|
||||
myDoTRACE("CreateFromHBITMAP faalt??");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_rotation%360 == 90 || m_rotation%360 == -270)
|
||||
img->RotateLeft();
|
||||
|
||||
if (m_rotation%360 == -90 || m_rotation%360 == 270)
|
||||
img->RotateRight();
|
||||
|
||||
if (m_rotation == -180 || m_rotation == 180)
|
||||
img->Rotate180();
|
||||
|
||||
//img->Rotate(m_lRotation);
|
||||
|
||||
DeleteObject(TmpBmp);
|
||||
DeleteDC(myDC);
|
||||
ReleaseDC( NULL, pDC ); //Do not forget!
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSLNKBarcode::GetAsPNG(VARIANT* pVal)
|
||||
{
|
||||
try
|
||||
{
|
||||
myDoTRACE("\nCBarcode::GetAsPNG()");
|
||||
|
||||
CxImage img;
|
||||
BOOL res = CreateCxImage(&img);
|
||||
if (!res)
|
||||
{
|
||||
CString err; err.Format("Could not CreateCxImage: %s", img.GetLastError());
|
||||
throw err;
|
||||
}
|
||||
|
||||
return StreamPNG(img, pVal, true /*bPNG*/);
|
||||
}
|
||||
catch (DWFException& ex)
|
||||
{
|
||||
CString err;
|
||||
err.Format("%ls\n%ls\n%s\n%ls(%d)",ex.type(),ex.message(),ex.function(),ex.file(),ex.line());
|
||||
return myAtlReportError (GetObjectCLSID(), "\nCBarcode::GetAsPNG('%s')\n%s", m_text, err);
|
||||
}
|
||||
catch (CString& err)
|
||||
{
|
||||
return myAtlReportError (GetObjectCLSID(), "\nCBarcode::GetAsPNG('%s')\n%s", m_text, err);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CSLNKBarcode::get_Narrow(ULONG* pVal)
|
||||
{
|
||||
*pVal = m_narrow;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSLNKBarcode::put_Narrow(ULONG newVal)
|
||||
{
|
||||
m_narrow = newVal;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSLNKBarcode::get_Wide(ULONG* pVal)
|
||||
{
|
||||
*pVal = m_wide;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSLNKBarcode::put_Wide(ULONG newVal)
|
||||
{
|
||||
m_wide = newVal;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSLNKBarcode::get_Width(ULONG* pVal)
|
||||
{
|
||||
*pVal = m_width;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSLNKBarcode::get_Rotation(LONG* pVal)
|
||||
{
|
||||
*pVal = m_rotation;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CSLNKBarcode::put_Rotation(LONG newVal)
|
||||
{
|
||||
m_rotation = newVal;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
82
SlnkDWFCom/Barcode.h
Normal file
82
SlnkDWFCom/Barcode.h
Normal file
@@ -0,0 +1,82 @@
|
||||
// Barcode.h : Declaration of the CSLNKBarcode
|
||||
|
||||
#pragma once
|
||||
#include "resource.h" // main symbols
|
||||
|
||||
#include "SLNKDWF.h"
|
||||
#include "CxImage\CxImage\ximage.h"
|
||||
|
||||
|
||||
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
|
||||
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
|
||||
#endif
|
||||
|
||||
// CSLNKBarcode
|
||||
|
||||
class ATL_NO_VTABLE CSLNKBarcode :
|
||||
public CComObjectRootEx<CComSingleThreadModel>,
|
||||
public CComCoClass<CSLNKBarcode, &CLSID_Barcode>,
|
||||
public ISupportErrorInfo,
|
||||
public IDispatchImpl<IBarcode, &IID_IBarcode, &LIBID_SLNKDWFLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
|
||||
{
|
||||
public:
|
||||
CSLNKBarcode()
|
||||
{
|
||||
m_height = -1;
|
||||
m_narrow = -1;
|
||||
m_wide = -1;
|
||||
m_width = -1;
|
||||
m_rotation = 0;
|
||||
}
|
||||
|
||||
DECLARE_REGISTRY_RESOURCEID(IDR_BARCODE)
|
||||
|
||||
|
||||
BEGIN_COM_MAP(CSLNKBarcode)
|
||||
COM_INTERFACE_ENTRY(IBarcode)
|
||||
COM_INTERFACE_ENTRY(IDispatch)
|
||||
COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
||||
END_COM_MAP()
|
||||
|
||||
// ISupportsErrorInfo
|
||||
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
|
||||
|
||||
|
||||
DECLARE_PROTECT_FINAL_CONSTRUCT()
|
||||
|
||||
HRESULT FinalConstruct()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void FinalRelease()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
CString m_text;
|
||||
int m_height;
|
||||
int m_narrow;
|
||||
int m_wide;
|
||||
int m_width;
|
||||
int m_rotation;
|
||||
bool CreateCxImage(CxImage* img);
|
||||
HRESULT StreamPNG(CxImage &img, VARIANT *ImageData, BOOL bPNG);
|
||||
|
||||
public:
|
||||
|
||||
STDMETHOD(get_Text)(BSTR* pVal);
|
||||
STDMETHOD(put_Text)(BSTR newVal);
|
||||
STDMETHOD(get_Height)(ULONG* pVal);
|
||||
STDMETHOD(put_Height)(ULONG newVal);
|
||||
STDMETHOD(GetAsPNG)(VARIANT* ImageData);
|
||||
STDMETHOD(get_Narrow)(ULONG* pVal);
|
||||
STDMETHOD(put_Narrow)(ULONG newVal);
|
||||
STDMETHOD(get_Wide)(ULONG* pVal);
|
||||
STDMETHOD(put_Wide)(ULONG newVal);
|
||||
STDMETHOD(get_Width)(ULONG* pVal);
|
||||
STDMETHOD(get_Rotation)(LONG* pVal);
|
||||
STDMETHOD(put_Rotation)(LONG newVal);
|
||||
};
|
||||
|
||||
OBJECT_ENTRY_AUTO(__uuidof(Barcode), CSLNKBarcode)
|
||||
26
SlnkDWFCom/Barcode.rgs
Normal file
26
SlnkDWFCom/Barcode.rgs
Normal file
@@ -0,0 +1,26 @@
|
||||
HKCR
|
||||
{
|
||||
SLNKDWF.Barcode.1 = s 'Barcode Class'
|
||||
{
|
||||
CLSID = s '{8F88E68B-0554-417B-B77E-A7EB55FEC302}'
|
||||
}
|
||||
SLNKDWF.Barcode = s 'Barcode Class'
|
||||
{
|
||||
CLSID = s '{8F88E68B-0554-417B-B77E-A7EB55FEC302}'
|
||||
CurVer = s 'SLNKDWF.Barcode.1'
|
||||
}
|
||||
NoRemove CLSID
|
||||
{
|
||||
ForceRemove {8F88E68B-0554-417B-B77E-A7EB55FEC302} = s 'Barcode Class'
|
||||
{
|
||||
ProgID = s 'SLNKDWF.Barcode.1'
|
||||
VersionIndependentProgID = s 'SLNKDWF.Barcode'
|
||||
ForceRemove 'Programmable'
|
||||
InprocServer32 = s '%MODULE%'
|
||||
{
|
||||
val ThreadingModel = s 'Apartment'
|
||||
}
|
||||
'TypeLib' = s '{B6FCDE6E-141C-4601-B3AC-4DF4D5F25DF8}'
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user