Available in the LEADTOOLS Imaging toolkit. |
ShowMagGlass example for C++ 4.0 and later
BOOL CSampleDlg::OnInitDialog()
{
.
.
.
bLeftButton = false;
m_Lead1.SetEnableMethodErrors(false);
m_Lead1.Load ("Sample1.cmp", 0, 1, 1);
m_Lead2.Load("Sample2.cmp", 0, 1, 1);
m_Lead1.SetMagGlassFlags(MAGGLASS_MANUAL_UPDATE);
// Starting the Magnifying Glass
m_Lead1.StartMagGlass(100, 100, 400, RGB(255, 0, 0), RGB(128, 128, 128), false, 1, false, CROSSHAIR_FINE, true, true);
// Updating the Magnifying Glass bitmap of 1st control with bitmap of the
// 2nd control that has the same width and height.
m_Lead1.UpdateMagGlassFromHandle(m_Lead2.GetBitmap(), true);
hMagGlassCursor = LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_MAGGLASS_CURSOR));
.
.
.
}
void CSampleDlg::OnMagGlassCursorLeadctrl1()
{
// Check if the left button is not down and the Magnifying Glass is started
if (!(bLeftButton) && (m_Lead1.GetHasMagGlass ()))
::SetCursor(hMagGlassCursor);
}
void CSampleDlg::OnMouseDownLeadctrl1(short Button, short Shift, long x, long y)
{
int nRet;
CString szMsg;
// Check if this is a left button and the Magnifying Glass is started
if (Button != 1 || !(m_Lead1.GetHasMagGlass()))
return;
// Move the Magnifying Glass to the hit position
nRet = m_Lead1.SetMagGlassPos((float) x, (float) y);
if (nRet != 0)
{
szMsg.Format("Error while displaying Magnifying Glass, Error: %d", nRet);
AfxMessageBox(szMsg);
return;
}
// Show the Magnifying Glass
nRet = m_Lead1.ShowMagGlass(true);
if (nRet != 0)
{
szMsg.Format("Error while displaying Magnifying Glass, Error: %d", nRet);
AfxMessageBox(szMsg);
return;
}
// Left button is currently pressed
bLeftButton = true;
// Hide the cursor
::ShowCursor(false);
}
void CSampleDlg::OnMouseMoveLeadctrl1(short Button, short Shift, long x, long y)
{
int nRet;
CString szMsg;
// Check if this is a left button and the Magnifying Glass is started
if (Button != 1 || !(m_Lead1.GetHasMagGlass()))
return;
// Move the Magnifying Glass to the mouse position
nRet = m_Lead1.SetMagGlassPos((float) x, (float) y);
if (nRet != 0)
{
szMsg.Format("Error while Moving Magnifying Glass, Error: %d", nRet);
AfxMessageBox(szMsg);
}
}
void CSampleDlg::OnMouseUpLeadctrl1(short Button, short Shift, long x, long y)
{
int nRet;
CString szMsg;
// Check if this is a left button and the Magnifying Glass is started
if (Button != 1 || !(m_Lead1.GetHasMagGlass()))
return;
// Show the Magnifying Glass
nRet = m_Lead1.ShowMagGlass(false);
if (nRet != 0)
{
szMsg.Format("Error while Hiding Magnifying Glass, Error: %d", nRet);
AfxMessageBox(szMsg);
}
// Left button is released
bLeftButton = true;
// Show the cursor
::ShowCursor(true);
}