Code Block
// samplecontrol.h : Declaration of the Csamplecontrol
#pragma once
#include <atlctl.h>
#include "ATLAXcontrol.h"
#include "comm.h"
#include "std_readwrite.h"
#include "stdafx.h"
#include "resourceppc.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
// Csamplecontrol
class ATL_NO_VTABLE Csamplecontrol :
public CComObjectRootEx<CComSingleThreadModel>,
public IDispatchImpl<Isamplecontrol, &IID_Isamplecontrol, &LIBID_ATLAXcontrolLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
public IPersistStreamInitImpl<Csamplecontrol>,
public IOleControlImpl<Csamplecontrol>,
public IOleObjectImpl<Csamplecontrol>,
public IOleInPlaceActiveObjectImpl<Csamplecontrol>,
public IViewObjectExImpl<Csamplecontrol>,
public IOleInPlaceObjectWindowlessImpl<Csamplecontrol>,
public ISupportErrorInfo,
public IPersistStorageImpl<Csamplecontrol>,
public ISpecifyPropertyPagesImpl<Csamplecontrol>,
public IQuickActivateImpl<Csamplecontrol>,
#ifndef _WIN32_WCE
public IDataObjectImpl<Csamplecontrol>,
#endif
public IProvideClassInfo2Impl<&CLSID_samplecontrol, NULL, &LIBID_ATLAXcontrolLib>,
#ifdef _WIN32_WCE // IObjectSafety is required on Windows CE for the control to be loaded correctly
public IObjectSafetyImpl<Csamplecontrol, INTERFACESAFE_FOR_UNTRUSTED_CALLER>,
#endif
public CComCoClass<Csamplecontrol, &CLSID_samplecontrol>,
public CComControl<Csamplecontrol>
{
public:
char* prova;
Csamplecontrol()
{
}
DECLARE_OLEMISC_STATUS(OLEMISC_RECOMPOSEONRESIZE |
OLEMISC_CANTLINKINSIDE |
OLEMISC_INSIDEOUT |
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST
)
#ifndef _CE_DCOM
DECLARE_REGISTRY_RESOURCEID(IDR_SAMPLECONTROL)
#endif
BEGIN_COM_MAP(Csamplecontrol)
COM_INTERFACE_ENTRY(Isamplecontrol)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(IViewObjectEx)
COM_INTERFACE_ENTRY(IViewObject2)
COM_INTERFACE_ENTRY(IViewObject)
COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
COM_INTERFACE_ENTRY(IOleInPlaceObject)
COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
COM_INTERFACE_ENTRY(IOleControl)
COM_INTERFACE_ENTRY(IOleObject)
COM_INTERFACE_ENTRY(IPersistStreamInit)
COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
COM_INTERFACE_ENTRY(IQuickActivate)
COM_INTERFACE_ENTRY(IPersistStorage)
#ifndef _WIN32_WCE
COM_INTERFACE_ENTRY(IDataObject)
#endif
COM_INTERFACE_ENTRY(IProvideClassInfo)
COM_INTERFACE_ENTRY(IProvideClassInfo2)
#ifdef _WIN32_WCE // IObjectSafety is required on Windows CE for the control to be loaded correctly
COM_INTERFACE_ENTRY_IID(IID_IObjectSafety, IObjectSafety)
#endif
END_COM_MAP()
BEGIN_PROP_MAP(Csamplecontrol)
PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
// Example entries
// PROP_ENTRY("Property Description", dispid, clsid)
// PROP_PAGE(CLSID_StockColorPage)
END_PROP_MAP()
BEGIN_MSG_MAP(Csamplecontrol)
CHAIN_MSG_MAP(CComControl<Csamplecontrol>)
DEFAULT_REFLECTION_HANDLER()
END_MSG_MAP()
// Handler prototypes:
// LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
// LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
// LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid)
{
static const IID* arr[] =
{
&IID_Isamplecontrol,
};
for (int i=0; i<sizeof(arr)/sizeof(arr[0]); i++)
{
if (InlineIsEqualGUID(*arr[i], riid))
return S_OK;
}
return S_FALSE;
}
// IViewObjectEx
DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)
// Isamplecontrol
public:
HRESULT OnDraw(ATL_DRAWINFO& di)
{
RECT& rc = *(RECT*)di.prcBounds;
// Set Clip region to the rectangle specified by di.prcBounds
HRGN hRgnOld = NULL;
if (GetClipRgn(di.hdcDraw, hRgnOld) != 1)
hRgnOld = NULL;
bool bSelectOldRgn = false;
HRGN hRgnNew = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
if (hRgnNew != NULL)
{
bSelectOldRgn = (SelectClipRgn(di.hdcDraw, hRgnNew) != ERROR);
}
Rectangle(di.hdcDraw, rc.left, rc.top, rc.right, rc.bottom);
SetTextAlign(di.hdcDraw, TA_CENTER|TA_BASELINE);
char* bufferID;
if (OpenComm()) // OpenComm is in Comm.cpp
printf("\n\n OpenComm OK da samplecontrol.h !");
else
printf("\n\n OpenComm FALLITA da samplecontrol.h !");
bufferID = DoASCIIReadWrite(); // this is in another cpp file and shoud return a char
CloseComm(); // it is in Comm.cpp
printf("\n\n LETTURA TAG OK! (s%)",bufferID); // here it doesn't display the bufferID, but only " (s) " Don't know why!
LPCTSTR pszText = _T("Ciao mondo"); // the first test :-)
#ifndef _WIN32_WCE
TextOut(di.hdcDraw,
(rc.left + rc.right) / 2,
(rc.top + rc.bottom) / 2,
pszText,
lstrlen(pszText));
#else
ExtTextOut(di.hdcDraw,
(rc.left + rc.right) / 2,
(rc.top + rc.bottom) / 2,
ETO_OPAQUE,
NULL,
pszText,
ATL::lstrlen(pszText),
NULL);
#endif
if (bSelectOldRgn)
SelectClipRgn(di.hdcDraw, hRgnOld);
prova = "Prova";
return S_OK;
}
char* provaChiamata()
{
return "Ciao";
}
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct()
{
return S_OK;
}
void FinalRelease()
{
}
};
OBJECT_ENTRY_AUTO(__uuidof(samplecontrol), Csamplecontrol)