hDocCleanRgn example for C++ 5.0 and later
void CTutorDlg::OnHolepunch()
{
//HolePunch Remove
//This example updates a windows region with all removed hole punches
//For the example, a windows region is updated and then converted to a LEAD region
//but in practice it would easier and faster to just update a LEAD region
//The HOLEPUNCH_USE_DPI flag instructs the API to determine the size of the hole punches
//based on the image DPI
//The image is modified
//The HolePunch Event is used to display information about each hole punch removed
//
//NOTE: This is not a complete example for handing events, some steps have been omitted.
//For a complete example of how to handle events, refer to the example
//Updating a Gauge and Detecting a User Interrupt.
//The following is declared and created in in the CTutorDlg class constructor
// ILEADRasterProcess *m_pRasterProc=NULL;
// hr = CoCreateInstance(
// CLSID_LEADRasterProcess,
// NULL,
// CLSCTX_ALL,
// IID_ILEADRasterProcess,
// (void**)&m_pRasterProc);
int nRet;
m_LEADRasterView1.GetRaster().UnlockSupport(L_SUPPORT_DOCUMENT, L_KEY_DOCUMENT);
m_pRasterProc->EnableMethodErrors = FALSE;
//Enable the doc clean event
m_pRasterProc->EnableDocCleanEvents = TRUE;
nRet = m_pRasterProc->HolePunchRemove(
m_LEADRasterView1.GetRaster(),
(HolePunchRemoveFlags)(HOLEPUNCH_SINGLE_REGION | HOLEPUNCH_USE_DPI | HOLEPUNCH_USE_COUNT | HOLEPUNCH_USE_LOCATION),
2, 4, 0, 0, 0, 0, HOLEPUNCH_LEFT);
if (nRet == 0)
{
m_LEADRasterView1.GetRaster().FreeRgn();
m_LEADRasterView1.GetRaster().SetRgnHandle(m_pRasterProc->hDocCleanRgn, 0, 0, L_RGN_SET);
m_pRasterProc->hDocCleanRgn= 0; //no longer need rgn
if (nRet == 0)
{
m_LEADRasterView1.SetRgnFrameType(RGNFRAME_COLOR);
}
}
}
void CRasterProcSink::OnHolePunchRemove(
long hRgn,
float fBoundingRectLeft,
float fBoundingRectTop,
float fBoundingRectWidth,
float fBoundingRectHeight,
long iHoleIndex,
long iHoleTotalCount,
long iWhiteCount,
long iBlackCount)
{
CString strMsg;
strMsg.Format(TEXT("HolePunch at [Left,Top,Width,Height][%0.0f, %0.0f, %0.0f, %0.0f] HoleIndex[%d] TotalCount[%d] WhiteCount[%d] BlackCount[%d]\n"),
fBoundingRectLeft,
fBoundingRectTop,
fBoundingRectWidth,
fBoundingRectHeight,
iHoleIndex,
iHoleTotalCount,
iWhiteCount,
iBlackCount);
OutputDebugString(strMsg);
}