home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / leadtools / ocx32.lt / Mfcdevw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-03  |  70.4 KB  |  2,375 lines

  1. // mfcdeVw.cpp : implementation of the CMfcdemoView class
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. #include "mfcdemo.h"
  7. #include "mfcdedoc.h"
  8. #include "mfcdevw.h"
  9. #include "maindemo.h"
  10. #include "listdlg.h"
  11. #include "rangedlg.h"
  12. #include "resizedl.h"
  13. #include "colorres.h"
  14. #include "underlay.h"
  15. #include "LeadDlg.h"
  16. #include "..\..\..\..\include\ltdlgocx.h"
  17.  
  18.  
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. extern CMfcdemoApp theApp;
  26.  
  27. #define SZ_COMPASS _T("North|North-East|East|South-East|South|South-West|West|North-West|")
  28. #define SZ_SHIFTDIFF _T("Diagonal|Horizontal|Vertical|")
  29. #define SZ_LINESEG _T("Horizontal|Vertical|Left to Right|Right to Left|")
  30. #define SZ_LAPLACE _T("Filter 1|Filter 2|Filter 3|Diagonal|Horizontal|Vertical|")
  31. #define SZ_HORZVERT _T("Horizontal|Vertical|");
  32. #define SZ_BINARY _T("Omnidirectional|Horizontal|Vertical|Diagonal|")
  33.  
  34. static int aGradientFlt[] = {
  35.    FLT_GRADIENT_N,
  36.    FLT_GRADIENT_NE,
  37.    FLT_GRADIENT_E,
  38.    FLT_GRADIENT_SE,
  39.    FLT_GRADIENT_S,
  40.    FLT_GRADIENT_SW,
  41.    FLT_GRADIENT_W,
  42.    FLT_GRADIENT_NW
  43. };
  44.  
  45. static int aLaplaceFlt[] = {
  46.    FLT_LAPLACE_1,
  47.    FLT_LAPLACE_2,
  48.    FLT_LAPLACE_3,
  49.    FLT_LAPLACE_DIAG,
  50.    FLT_LAPLACE_HORZ,
  51.    FLT_LAPLACE_VERT,
  52. };
  53.  
  54. static int aSobelFlt[] = {
  55.    FLT_SOBEL_HORZ,
  56.    FLT_SOBEL_VERT,
  57. };
  58.  
  59.  
  60. static int aPrewittFlt[] = {
  61.    FLT_PREWITT_HORZ,
  62.    FLT_PREWITT_VERT,
  63. };
  64.  
  65. static int aShiftDiffFlt[] = {
  66.    FLT_SHIFTDIFF_DIAG,
  67.    FLT_SHIFTDIFF_HORZ,
  68.    FLT_SHIFTDIFF_VERT,
  69. };
  70.  
  71. static int aLineSegFlt[] = {
  72.    FLT_LINESEG_HORZ,
  73.    FLT_LINESEG_VERT,
  74.    FLT_LINESEG_LTOR,
  75.    FLT_LINESEG_RTOL,
  76. };
  77.  
  78. static int aErosionFlt[] = {
  79.    BFLT_EROSION_OMNI,
  80.    BFLT_EROSION_HORZ,
  81.    BFLT_EROSION_VERT,
  82.    BFLT_EROSION_DIAG,
  83. };
  84.  
  85. static int aDilationFlt[] = {
  86.    BFLT_DILATION_OMNI,
  87.    BFLT_DILATION_HORZ,
  88.    BFLT_DILATION_VERT,
  89.    BFLT_DILATION_DIAG,
  90. };
  91.  
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CMfcdemoView
  94.  
  95. IMPLEMENT_DYNCREATE(CMfcdemoView, CFormView)
  96.  
  97. BEGIN_MESSAGE_MAP(CMfcdemoView, CFormView)
  98.     //{{AFX_MSG_MAP(CMfcdemoView)
  99.     ON_MESSAGE(WM_DOREALIZE, OnDoRealize)
  100.     ON_COMMAND(ID_IMAGE_FLIP, OnImageFlip)
  101.     ON_COMMAND(ID_IMAGE_REVERSE, OnImageReverse)
  102.     ON_COMMAND(ID_IMAGE_ROTATE_180CLOCKWISE, OnImageRotate180clockwise)
  103.     ON_COMMAND(ID_IMAGE_ROTATE_270CLOCKWISE, OnImageRotate270clockwise)
  104.     ON_COMMAND(ID_IMAGE_ROTATE_90CLOCKWISE, OnImageRotate90clockwise)
  105.     ON_COMMAND(ID_COLOR_GRAYSCALE, OnColorGrayscale)
  106.     ON_COMMAND(ID_COLOR_GRAYSCALE12, OnColorGrayscale12)
  107.     ON_COMMAND(ID_COLOR_GRAYSCALE16, OnColorGrayscale16)
  108.     ON_COMMAND(ID_COLOR_HISTOGRAMEQUALIZE, OnColorHistogramequalize)
  109.     ON_COMMAND(ID_COLOR_INVERT, OnColorInvert)
  110.     ON_COMMAND(ID_COLOR_STRETCHINTENSITY, OnColorStretchintensity)
  111.     ON_COMMAND(ID_IMAGE_EFFECTS_POSTERIZE, OnImageEffectsPosterize)
  112.     ON_COMMAND(ID_COLOR_BRIGHTNESS, OnColorBrightness)
  113.     ON_COMMAND(ID_COLOR_CONTRAST, OnColorContrast)
  114.     ON_COMMAND(ID_COLOR_HISTOCONTRAST, OnColorHistocontrast)
  115.     ON_COMMAND(ID_COLOR_HUE, OnColorHue)
  116.     ON_COMMAND(ID_COLOR_SATURATION, OnColorSaturation)
  117.     ON_COMMAND(ID_IMAGE_EFFECTS_ADDNOISE, OnImageEffectsAddnoise)
  118.     ON_COMMAND(ID_IMAGE_EFFECTS_AVERAGE, OnImageEffectsAverage)
  119.     ON_COMMAND(ID_IMAGE_EFFECTS_DESPECKLE, OnImageEffectsDespeckle)
  120.     ON_COMMAND(ID_IMAGE_EFFECTS_MEDIAN, OnImageEffectsMedian)
  121.     ON_COMMAND(ID_IMAGE_EFFECTS_MOSAIC, OnImageEffectsMosaic)
  122.     ON_COMMAND(ID_IMAGE_EFFECTS_SHARPEN, OnImageEffectsSharpen)
  123.     ON_COMMAND(ID_IMAGE_BINARYFILTERS_DILATION, OnImageBinaryfiltersDilation)
  124.     ON_COMMAND(ID_IMAGE_BINARYFILTERS_EROSION, OnImageBinaryfiltersErosion)
  125.     ON_COMMAND(ID_IMAGE_SPATIALFILTERS_GRADIENT, OnImageSpatialfiltersGradient)
  126.     ON_COMMAND(ID_IMAGE_SPATIALFILTERS_LAPLACIAN, OnImageSpatialfiltersLaplacian)
  127.     ON_COMMAND(ID_IMAGE_SPATIALFILTERS_LINESEGMENT, OnImageSpatialfiltersLinesegment)
  128.     ON_COMMAND(ID_IMAGE_SPATIALFILTERS_PREWITT, OnImageSpatialfiltersPrewitt)
  129.     ON_COMMAND(ID_IMAGE_SPATIALFILTERS_SHIFTANDDIFFERENCE, OnImageSpatialfiltersShiftanddifference)
  130.     ON_COMMAND(ID_IMAGE_SPATIALFILTERS_SOBEL, OnImageSpatialfiltersSobel)
  131.     ON_COMMAND(ID_COLOR_GAMMACORRECT, OnColorGammacorrect)
  132.     ON_COMMAND(ID_COLOR_INTENSITYDETECT, OnColorIntensitydetect)
  133.     ON_COMMAND(ID_IMAGE_RESIZE, OnImageResize)
  134.     ON_COMMAND(ID_IMAGE_ROTATE_ANYANGLE, OnImageRotateAnyangle)
  135.     ON_COMMAND(ID_IMAGE_SHEAR, OnImageShear)
  136.     ON_COMMAND(ID_COLOR_COLORRESOLUTION, OnColorColorresolution)
  137.     ON_COMMAND(ID_VIEW_ZOOM, OnViewZoom)
  138.     ON_COMMAND(ID_VIEW_NORMAL, OnViewNormal)
  139.     ON_COMMAND(ID_VIEW_PAINTEFFECTS, OnViewPainteffects)
  140.     ON_COMMAND(ID_VIEW_SNAPWINDOWTOIMAGE, OnViewSnapwindowtoimage)
  141.     ON_COMMAND(ID_VIEW_FITIMAGETOWINDOW, OnViewFitimagetowindow)
  142.     ON_COMMAND(ID_IMAGE_EFFECTS_EMBOSS, OnImageEffectsEmboss)
  143.     ON_COMMAND(ID_COLOR_HALFTONE, OnColorHalftone)
  144.     ON_COMMAND(ID_COLOR_FILL, OnColorFill)
  145.     ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
  146.     ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  147.     ON_COMMAND(ID_COLOR_SEPARATION, OnColorSeparation)
  148.     ON_COMMAND(ID_IMAGE_EFFECTS_EDGEENHANCE, OnImageEffectsEdgeenhance)
  149.     ON_UPDATE_COMMAND_UI(ID_IMAGE_EFFECTS_EDGEENHANCE, OnUpdateImageEffectsEdgeenhance)
  150.     ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
  151.     ON_COMMAND(ID_IMAGE_DESKEW, OnImageDeskew)
  152.     ON_COMMAND(ID_IMAGE_EFFECTS_UNDERLAY, OnImageEffectsUnderlay)
  153.     ON_UPDATE_COMMAND_UI(ID_IMAGE_DESKEW, OnUpdateImageDeskew)
  154.     ON_UPDATE_COMMAND_UI(ID_IMAGE_BINARYFILTERS_DILATION, OnUpdateImageBinaryfiltersDilation)
  155.     ON_UPDATE_COMMAND_UI(ID_IMAGE_BINARYFILTERS_EROSION, OnUpdateImageBinaryfiltersErosion)
  156.     ON_UPDATE_COMMAND_UI(ID_IMAGE_EFFECTS_DESPECKLE, OnUpdateImageEffectsDespeckle)
  157.     ON_WM_SIZE()
  158.     ON_COMMAND(IDM_TOOLNONE, OnToolnone)
  159.     ON_UPDATE_COMMAND_UI(IDM_TOOLNONE, OnUpdateToolnone)
  160.     ON_COMMAND(IDM_TOOLELLIPSE, OnToolellipse)
  161.     ON_UPDATE_COMMAND_UI(IDM_TOOLELLIPSE, OnUpdateToolellipse)
  162.     ON_COMMAND(IDM_TOOLFREEHAND, OnToolfreehand)
  163.     ON_UPDATE_COMMAND_UI(IDM_TOOLFREEHAND, OnUpdateToolfreehand)
  164.     ON_COMMAND(IDM_TOOLRECT, OnToolrect)
  165.     ON_UPDATE_COMMAND_UI(IDM_TOOLRECT, OnUpdateToolrect)
  166.     ON_COMMAND(IDM_TOOLRNDRECT, OnToolrndrect)
  167.     ON_UPDATE_COMMAND_UI(IDM_TOOLRNDRECT, OnUpdateToolrndrect)
  168.     ON_UPDATE_COMMAND_UI(ID_IMAGE_REGIONTRANSFORMATIONS_CANCEL, OnUpdateImageRegiontransformationsCancel)
  169.     ON_COMMAND(ID_IMAGE_REGIONTRANSFORMATIONS_CANCEL, OnImageRegiontransformationsCancel)
  170.     ON_UPDATE_COMMAND_UI(ID_IMAGE_SHEAR, OnUpdateImageShear)
  171.     ON_COMMAND(ID_COLOR_WINDOWLEVEL, OnColorWindowlevel)
  172.     ON_UPDATE_COMMAND_UI(ID_COLOR_WINDOWLEVEL, OnUpdateColorWindowlevel)
  173.     //}}AFX_MSG_MAP
  174.     // Standard printing commands
  175.     ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
  176.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
  177.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
  178. END_MESSAGE_MAP()
  179.  
  180. /////////////////////////////////////////////////////////////////////////////
  181. // CMfcdemoView construction/destruction
  182.  
  183. CMfcdemoView::CMfcdemoView()
  184.     : CFormView(CMfcdemoView::IDD)
  185. {
  186.     //{{AFX_DATA_INIT(CMfcdemoView)
  187.     //}}AFX_DATA_INIT
  188.  
  189.     m_pPalette = NULL;
  190.     m_nEffect = EFX_EFFECT_NONE;
  191.     m_nRegionTool = IDM_TOOLNONE;
  192.     m_nRegionType = 0;
  193.     m_nZoom = 100;
  194.  
  195.     m_bMovingFloater = FALSE;
  196. }
  197.  
  198. CMfcdemoView::~CMfcdemoView()
  199. {
  200.     if(m_pPalette)
  201.         delete m_pPalette;
  202. }
  203.  
  204. void CMfcdemoView::DoDataExchange(CDataExchange* pDX)
  205. {
  206.     CFormView::DoDataExchange(pDX);
  207.     //{{AFX_DATA_MAP(CMfcdemoView)
  208.     DDX_Control(pDX, IDC_LEADCTRL1, m_Lead);
  209.     DDX_Control(pDX, IDC_LEADCTRL2, m_Lead3);
  210.     //}}AFX_DATA_MAP
  211. }
  212.  
  213. BOOL CMfcdemoView::PreCreateWindow(CREATESTRUCT& cs)
  214. {
  215.     // TODO: Modify the Window class or styles here by modifying
  216.     //  the CREATESTRUCT cs
  217.  
  218.     return CFormView::PreCreateWindow(cs);
  219. }
  220.  
  221. /////////////////////////////////////////////////////////////////////////////
  222. // CMfcdemoView printing
  223.  
  224. BOOL CMfcdemoView::OnPreparePrinting(CPrintInfo* pInfo)
  225. {
  226.     // default preparation
  227.     return DoPreparePrinting(pInfo);
  228. }
  229.  
  230. void CMfcdemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  231. {
  232.     // TODO: add cleanup after printing
  233. }
  234.  
  235. /////////////////////////////////////////////////////////////////////////////
  236. // CMfcdemoView diagnostics
  237.  
  238. #ifdef _DEBUG
  239. void CMfcdemoView::AssertValid() const
  240. {
  241.     CFormView::AssertValid();
  242. }
  243.  
  244. void CMfcdemoView::Dump(CDumpContext& dc) const
  245. {
  246.     CFormView::Dump(dc);
  247. }
  248.  
  249. CMfcdemoDoc* CMfcdemoView::GetDocument() // non-debug version is inline
  250. {
  251.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMfcdemoDoc)));
  252.     return (CMfcdemoDoc*)m_pDocument;
  253. }
  254. #endif //_DEBUG
  255.  
  256. /////////////////////////////////////////////////////////////////////////////
  257. // CMfcdemoView message handlers
  258.  
  259. /////////////////////////////////////////////////////////////////////////////
  260. // CMfcdemoView drawing
  261.  
  262. void CMfcdemoView::OnDraw(CDC* pDC)
  263. {
  264.     CRect rcClip;
  265.     CSize winext;
  266.     CSize viewext;
  267.     CSize paintext;
  268.  
  269.     CMfcdemoDoc* pDoc = GetDocument();
  270.     ASSERT_VALID(pDoc);
  271.  
  272.     if(pDC->IsPrinting())
  273.     {                
  274.         pDC->SaveDC();
  275.         ::GetWindowExtEx(pDC->m_hDC, &winext);
  276.         ::GetViewportExtEx(pDC->m_hDC, &viewext);
  277.         paintext.cx = MulDiv((int) m_Lead.GetBitmapWidth(), viewext.cx, winext.cx);
  278.         paintext.cy = MulDiv((int) m_Lead.GetBitmapHeight(), viewext.cy, winext.cy);
  279.         ::SetMapMode(pDC->m_hDC, MM_TEXT);                
  280.         m_Lead.Render((OLE_HANDLE) pDC->m_hDC, (float) 0, (float) 0, (float) paintext.cx, (float) paintext.cy);
  281.         pDC->RestoreDC(-1);
  282.     }
  283. }
  284.  
  285. void CMfcdemoView::BeginProcessing()
  286. {
  287.         BeginWaitCursor();
  288.         GetUndoLead()->SetBitmap(GetDocLead()->GetBitmap());
  289. }
  290.  
  291. void CMfcdemoView::EndProcessing(int nRet)
  292. {
  293.         EndWaitCursor();
  294.         theApp.DisplayLEADError(nRet);
  295. }
  296.  
  297. void CMfcdemoView::OnChanged()
  298. {
  299.     CMfcdemoDoc* pDoc = GetDocument();
  300.  
  301.     pDoc->SetModifiedFlag();
  302.     pDoc->UpdateAllViews(NULL, (LPARAM) 0);
  303. }
  304.  
  305. void CMfcdemoView::SetZoom(int nZoom) 
  306. {
  307.     CMfcdemoDoc* pDoc = GetDocument();
  308.     m_nZoom = nZoom;
  309.     OnUpdate(NULL, 0, NULL);
  310. }
  311.  
  312. CLead* CMfcdemoView::GetDocLead() 
  313. {
  314.     CMfcdemoDoc* pDoc = GetDocument();
  315.     return(&pDoc->m_Lead);
  316. }
  317.  
  318. CLead* CMfcdemoView::GetUndoLead() 
  319. {
  320.     CMfcdemoDoc* pDoc = GetDocument();
  321.     return(&pDoc->m_LeadUndo);
  322. }
  323.  
  324. void CMfcdemoView::OnInitialUpdate() 
  325. {
  326.     CFormView::OnInitialUpdate();
  327.  
  328.     int xExt = (int)m_Lead.GetBitmapWidth(),
  329.         yExt = (int)m_Lead.GetBitmapHeight();
  330.     // Make the CLead control to fit the bitmap and disable CLead's scrolling
  331.     // Make the form scroll if the window becomes smaller than the bitmap
  332.     SetScrollSizes(MM_TEXT,CSize(xExt,yExt));
  333.     // Make the window fit the image
  334.     GetParentFrame()->RecalcLayout();
  335.     ResizeParentToFit();
  336.     // now disable the scroll bars
  337.     SetScrollSizes(MM_TEXT,CSize(1,1));
  338.  
  339.     CMfcdemoDoc* pDoc = GetDocument();
  340.     SetZoom(100);
  341.  
  342.     /* this is a hidden control, used only for floater support */
  343.     m_Lead3.ShowWindow(SW_HIDE);
  344. }
  345.  
  346. LRESULT CMfcdemoView::OnDoRealize(WPARAM wParam, LPARAM lParam)
  347. {
  348.     if( !IsWindow(m_Lead.m_hWnd) )
  349.         return FALSE;
  350.     if(lParam)
  351.     {
  352.         return m_Lead.SendMessage(WM_PALETTECHANGED, wParam);
  353.     }
  354.     else
  355.     {
  356.         UINT nColorsChanged = 0;
  357.         CDC* pdc;
  358.  
  359.         pdc = theApp.m_pMainWnd->GetDC();
  360.         HPALETTE hpal = (HPALETTE)m_Lead.GetPalette((OLE_HANDLE) pdc->m_hDC);
  361.         if(hpal)
  362.         {
  363.             CPalette pal;
  364.  
  365.             pal.Attach(hpal);
  366.             CPalette* oldPalette = pdc->SelectPalette(&pal, (BOOL) lParam);
  367.             nColorsChanged = pdc->RealizePalette();
  368.             if (nColorsChanged > 0)
  369.                 m_Lead.InvalidateRect(NULL, FALSE);
  370.             pdc->SelectPalette(oldPalette, TRUE);
  371.         }
  372.         theApp.m_pMainWnd->ReleaseDC(pdc);
  373.         return ((LRESULT) (BOOL) (nColorsChanged > 0));
  374.     }
  375. }
  376.  
  377. void CMfcdemoView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
  378. {
  379.     CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
  380.     if (bActivate)
  381.     {
  382.         ASSERT(pActivateView == this);
  383.         OnDoRealize((WPARAM)theApp.m_pMainWnd->m_hWnd, (LPARAM) FALSE);   // same as SendMessage(WM_DOREALIZE);
  384.     }
  385. }
  386.  
  387. void CMfcdemoView::OnImageFlip()
  388. {
  389.     if(m_Lead.GetHasRgn())
  390.     {
  391.       OnImageRegiontransformationsFlip();
  392.     }
  393.     else
  394.     {
  395.       BeginProcessing();
  396.       int nRet = GetDocLead()->Flip();
  397.       OnChanged();
  398.       EndProcessing(nRet);
  399.     }
  400. }
  401.  
  402. void CMfcdemoView::OnImageReverse() 
  403. {
  404.     if(m_Lead.GetHasRgn())
  405.     {
  406.       OnImageRegiontransformationsReverse();
  407.     }
  408.     else
  409.     {
  410.       BeginProcessing();
  411.       int nRet = GetDocLead()->Reverse();
  412.       OnChanged();
  413.       EndProcessing(nRet);
  414.     }
  415. }
  416.  
  417. void CMfcdemoView::OnImageRotate180clockwise() 
  418. {
  419.     if(m_Lead.GetHasRgn())
  420.     {
  421.       OnImageRegiontransformationsRotate((long) 18000);
  422.     }
  423.     else
  424.     {
  425.       BeginProcessing();
  426.       int nRet = GetDocLead()->Rotate(18000, TRUE, RGB(0, 0, 0));
  427.       OnChanged();
  428.       EndProcessing(nRet);
  429.     }
  430. }
  431.  
  432. void CMfcdemoView::OnImageRotate270clockwise() 
  433. {
  434.     if(m_Lead.GetHasRgn())
  435.     {
  436.       OnImageRegiontransformationsRotate((long) 27000);
  437.     }
  438.     else
  439.     {
  440.       BeginProcessing();
  441.      int nRet = GetDocLead()->Rotate(27000, TRUE, RGB(0, 0, 0));
  442.       OnChanged();
  443.       EndProcessing(nRet);
  444.     }
  445. }
  446.  
  447. void CMfcdemoView::OnImageRotate90clockwise() 
  448. {
  449.     if(m_Lead.GetHasRgn())
  450.     {
  451.       OnImageRegiontransformationsRotate((long) 9000);
  452.     }
  453.     else
  454.     {
  455.       BeginProcessing();
  456.       int nRet = GetDocLead()->Rotate(9000, TRUE, RGB(0, 0, 0));
  457.       OnChanged();
  458.       EndProcessing(nRet);
  459.     }
  460. }
  461.  
  462.  
  463. void CMfcdemoView::OnColorGrayscale() 
  464. {
  465.     BeginProcessing();
  466.     int nRet = GetDocLead()->Grayscale(8);
  467.     OnChanged();
  468.     EndProcessing(nRet);
  469. }
  470.  
  471. void CMfcdemoView::OnColorGrayscale12() 
  472. {
  473.     BeginProcessing();
  474.     int nRet = GetDocLead()->Grayscale(12);
  475.     OnChanged();
  476.     EndProcessing(nRet);
  477. }
  478.  
  479. void CMfcdemoView::OnColorGrayscale16() 
  480. {
  481.     BeginProcessing();
  482.     int nRet = GetDocLead()->Grayscale(16);
  483.     OnChanged();
  484.     EndProcessing(nRet);
  485. }
  486.  
  487.  
  488. void CMfcdemoView::OnColorHistogramequalize() 
  489. {
  490.     BeginProcessing();
  491.     int nRet = GetDocLead()->HistoEqualize();
  492.     OnChanged();
  493.     EndProcessing(nRet);
  494. }
  495.  
  496. void CMfcdemoView::OnColorInvert() 
  497. {
  498.     BeginProcessing();
  499.     int nRet = GetDocLead()->Invert();
  500.     OnChanged();
  501.     EndProcessing(nRet);
  502. }
  503.  
  504. void CMfcdemoView::OnColorStretchintensity() 
  505. {
  506.     BeginProcessing();
  507.     int nRet = GetDocLead()->StretchIntensity();
  508.     OnChanged();
  509.     EndProcessing(nRet);
  510. }
  511.  
  512. void CMfcdemoView::OnImageEffectsPosterize() 
  513. {
  514.    CLeadDlg LTCommDlg;
  515.    RECT rcWin;
  516.    BOOL bContinue=FALSE;
  517.    int nRet;
  518.    
  519.    ::SetRect(&rcWin, 0, 0, 1, 1);
  520.  
  521.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  522.    {
  523.       LTCommDlg.SetEnableMethodErrors(FALSE);
  524.       //assign the bitmap for preview
  525.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  526.       LTCommDlg.SetUIFlags( DLG_IMG_POSTERIZE | DLG_IMG_SHOWPREVIEW );
  527. //      LTCommDlg.SetChange(2);
  528.       nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
  529.       if(nRet == 0)
  530.          bContinue = TRUE;
  531.       //release the reference
  532.       LTCommDlg.SetBitmap(0);
  533.    }
  534.    if(bContinue)
  535.    {
  536.        BeginProcessing();
  537.        int nRet = GetDocLead()->Posterize(LTCommDlg.GetChange()/*the property*/);
  538.        OnChanged();
  539.        EndProcessing(nRet);
  540.    }    
  541.    else if(nRet != ERROR_DLG_CANCELED)
  542.       theApp.DisplayLEADError(nRet);
  543.    return;
  544. }
  545.  
  546. void CMfcdemoView::OnColorBrightness() 
  547. {
  548.    CLeadDlg LTCommDlg;
  549.    RECT rcWin;
  550.    BOOL bContinue=FALSE;
  551.    int nRet;
  552.    
  553.    ::SetRect(&rcWin, 0, 0, 1, 1);
  554.  
  555.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  556.    {
  557.       LTCommDlg.SetEnableMethodErrors(FALSE);
  558.       //assign the bitmap for preview
  559.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  560.       LTCommDlg.SetUIFlags( DLG_IMG_BRIGHTNESS | DLG_IMG_SHOWPREVIEW );
  561.       nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
  562.       if(nRet == 0)
  563.          bContinue = TRUE;
  564.       //release the reference
  565.       LTCommDlg.SetBitmap(0);
  566.    }
  567.    if(bContinue)
  568.    {
  569.        BeginProcessing();
  570.        int nRet = GetDocLead()->Intensity(LTCommDlg.GetChange()/*the property*/);
  571.        OnChanged();
  572.        EndProcessing(nRet);
  573.    }    
  574.    else if(nRet != ERROR_DLG_CANCELED)
  575.       theApp.DisplayLEADError(nRet);
  576. }
  577.  
  578. void CMfcdemoView::OnColorContrast() 
  579. {
  580.    CLeadDlg LTCommDlg;
  581.    RECT rcWin;
  582.    BOOL bContinue=FALSE;
  583.    int nRet;
  584.  
  585.    ::SetRect(&rcWin, 0, 0, 1, 1);
  586.  
  587.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  588.    {
  589.       LTCommDlg.SetEnableMethodErrors(FALSE);
  590.       //assign the bitmap for preview
  591.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  592.       LTCommDlg.SetUIFlags( DLG_IMG_CONTRAST | DLG_IMG_SHOWPREVIEW );
  593.       nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
  594.       if(nRet == 0)
  595.          bContinue = TRUE;
  596.       //release the reference
  597.       LTCommDlg.SetBitmap(0);
  598.    }
  599.    if(bContinue)
  600.    {
  601.        BeginProcessing();
  602.        int nRet = GetDocLead()->Contrast(LTCommDlg.GetChange()/*the property*/);
  603.        OnChanged();
  604.        EndProcessing(nRet);
  605.    }    
  606.    else if(nRet != ERROR_DLG_CANCELED)
  607.       theApp.DisplayLEADError(nRet);
  608. }
  609.  
  610.  
  611. void CMfcdemoView::OnColorHistocontrast() 
  612. {
  613.    CLeadDlg LTCommDlg;
  614.    RECT rcWin;
  615.    BOOL bContinue=FALSE;
  616.    int nRet;
  617.    
  618.    ::SetRect(&rcWin, 0, 0, 1, 1);
  619.  
  620.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  621.    {
  622.       LTCommDlg.SetEnableMethodErrors(FALSE);
  623.          //assign the bitmap for preview
  624.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  625.       LTCommDlg.SetUIFlags( DLG_IMG_HISTOCONTRAST | DLG_IMG_SHOWPREVIEW );
  626.       nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
  627.       if(nRet == 0)
  628.          bContinue = TRUE;
  629.       //release the reference
  630.       LTCommDlg.SetBitmap(0);
  631.    }
  632.    if(bContinue)
  633.    {
  634.        BeginProcessing();
  635.        int nRet = GetDocLead()->HistoContrast(LTCommDlg.GetChange()/*the property*/);
  636.        OnChanged();
  637.        EndProcessing(nRet);
  638.    }    
  639.    else if(nRet != ERROR_DLG_CANCELED)
  640.       theApp.DisplayLEADError(nRet);
  641. }
  642.  
  643. void CMfcdemoView::OnColorHue() 
  644. {
  645.    CLeadDlg LTCommDlg;
  646.    RECT rcWin;
  647.    BOOL bContinue=FALSE;
  648.    int nRet;
  649.    
  650.    ::SetRect(&rcWin, 0, 0, 1, 1);
  651.  
  652.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  653.    {
  654.       LTCommDlg.SetEnableMethodErrors(FALSE);
  655.       //assign the bitmap for preview
  656.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  657.       LTCommDlg.SetUIFlags( DLG_IMG_HUE | DLG_IMG_SHOWPREVIEW );
  658.       nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
  659.       if(nRet == 0)
  660.          bContinue = TRUE;
  661.       //release the reference
  662.       LTCommDlg.SetBitmap(0);
  663.    }
  664.    if(bContinue)
  665.    {
  666.        BeginProcessing();
  667.        int nRet = GetDocLead()->Hue(LTCommDlg.GetChange()/*the property*/);
  668.        OnChanged();
  669.        EndProcessing(nRet);
  670.    }    
  671.    else if(nRet != ERROR_DLG_CANCELED)
  672.       theApp.DisplayLEADError(nRet);
  673. }
  674.  
  675. void CMfcdemoView::OnColorSaturation() 
  676. {
  677.    CLeadDlg LTCommDlg;
  678.    RECT rcWin;
  679.    BOOL bContinue=FALSE;
  680.    int nRet;
  681.    
  682.    ::SetRect(&rcWin, 0, 0, 1, 1);
  683.  
  684.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  685.    {
  686.       LTCommDlg.SetEnableMethodErrors(FALSE);
  687.       //assign the bitmap for preview
  688.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  689.       LTCommDlg.SetUIFlags( DLG_IMG_SATURATION | DLG_IMG_SHOWPREVIEW );
  690.       nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
  691.       if(nRet == 0)
  692.          bContinue = TRUE;
  693.       //release the reference
  694.       LTCommDlg.SetBitmap(0);
  695.    }
  696.    if(bContinue)
  697.    {
  698.        BeginProcessing();
  699.        int nRet = GetDocLead()->Saturation(LTCommDlg.GetChange()/*the property*/);
  700.        OnChanged();
  701.        EndProcessing(nRet);
  702.    }    
  703.    else if(nRet != ERROR_DLG_CANCELED)
  704.       theApp.DisplayLEADError(nRet);
  705. }
  706.  
  707. void CMfcdemoView::OnImageEffectsAddnoise() 
  708. {
  709.    CLeadDlg LTCommDlg;
  710.    RECT rcWin;
  711.    BOOL bContinue=FALSE;
  712.    int nRet;
  713.    
  714.    ::SetRect(&rcWin, 0, 0, 1, 1);
  715.  
  716.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  717.    {
  718.       LTCommDlg.SetEnableMethodErrors(FALSE);
  719.       //assign the bitmap for preview
  720.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  721.       LTCommDlg.SetUIFlags( DLG_IMG_SHOWPREVIEW );
  722.       nRet = LTCommDlg.GetNoise((long)this->m_hWnd);
  723.       if(nRet == 0)
  724.          bContinue = TRUE;
  725.       //release the reference
  726.       LTCommDlg.SetBitmap(0);
  727.    }
  728.    if(bContinue)
  729.    {
  730.        BeginProcessing();
  731.        int nRet = GetDocLead()->AddNoise( LTCommDlg.GetRange(), /* the property */
  732.                                           LTCommDlg.GetChannel() );
  733.        OnChanged();
  734.        EndProcessing(nRet);
  735.    }    
  736.    else if(nRet != ERROR_DLG_CANCELED)
  737.       theApp.DisplayLEADError(nRet);
  738. }
  739.  
  740. void CMfcdemoView::OnImageEffectsAverage() 
  741. {
  742.    CLeadDlg LTCommDlg;
  743.    RECT rcWin;
  744.    BOOL bContinue=FALSE;
  745.    int nRet;
  746.    
  747.    ::SetRect(&rcWin, 0, 0, 1, 1);
  748.  
  749.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  750.    {
  751.       LTCommDlg.SetEnableMethodErrors(FALSE);
  752.       //assign the bitmap for preview
  753.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  754.       LTCommDlg.SetUIFlags( DLG_IMG_AVERAGE | DLG_IMG_SHOWPREVIEW );
  755.       LTCommDlg.SetChange(3);
  756.       nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
  757.       if(nRet == 0)
  758.          bContinue = TRUE;
  759.       //release the reference
  760.       LTCommDlg.SetBitmap(0);
  761.    }
  762.    if(bContinue)
  763.    {
  764.        BeginProcessing();
  765.        int nRet = GetDocLead()->Average(LTCommDlg.GetChange()/*the property*/);
  766.        OnChanged();
  767.        EndProcessing(nRet);
  768.    }    
  769.    else if(nRet != ERROR_DLG_CANCELED)
  770.       theApp.DisplayLEADError(nRet);
  771. }
  772.  
  773. void CMfcdemoView::OnImageEffectsDespeckle() 
  774. {
  775.     BeginProcessing();
  776.     int nRet = GetDocLead()->Despeckle();
  777.     OnChanged();
  778.     EndProcessing(nRet);
  779. }
  780.  
  781. void CMfcdemoView::OnImageEffectsMedian() 
  782. {
  783.    CLeadDlg LTCommDlg;
  784.    RECT rcWin;
  785.    BOOL bContinue=FALSE;
  786.    int nRet;
  787.    
  788.    ::SetRect(&rcWin, 0, 0, 1, 1);
  789.  
  790.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  791.    {
  792.       LTCommDlg.SetEnableMethodErrors(FALSE);
  793.       //assign the bitmap for preview
  794.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  795.       LTCommDlg.SetUIFlags( DLG_IMG_MEDIAN | DLG_IMG_SHOWPREVIEW );
  796.       LTCommDlg.SetChange(3);
  797.       nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
  798.       if(nRet == 0)
  799.          bContinue = TRUE;
  800.       //release the reference
  801.       LTCommDlg.SetBitmap(0);
  802.    }
  803.    if(bContinue)
  804.    {
  805.        BeginProcessing();
  806.        int nRet = GetDocLead()->Median(LTCommDlg.GetChange()/*the property*/);
  807.        OnChanged();
  808.        EndProcessing(nRet);
  809.    }    
  810.    else if(nRet != ERROR_DLG_CANCELED)
  811.       theApp.DisplayLEADError(nRet);
  812. }
  813.  
  814. void CMfcdemoView::OnImageEffectsMosaic() 
  815. {
  816.    CLeadDlg LTCommDlg;
  817.    RECT rcWin;
  818.    BOOL bContinue=FALSE;
  819.    int nRet;
  820.    
  821.    ::SetRect(&rcWin, 0, 0, 1, 1);
  822.  
  823.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  824.    {
  825.       LTCommDlg.SetEnableMethodErrors(FALSE);
  826.       //assign the bitmap for preview
  827.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  828.       LTCommDlg.SetUIFlags( DLG_IMG_MOSAIC | DLG_IMG_SHOWPREVIEW );
  829.       LTCommDlg.SetChange(2);
  830.       nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
  831.       if(nRet == 0)
  832.          bContinue = TRUE;
  833.       //release the reference
  834.       LTCommDlg.SetBitmap(0);
  835.    }
  836.    if(bContinue)
  837.    {
  838.        BeginProcessing();
  839.        int nRet = GetDocLead()->Mosaic(LTCommDlg.GetChange()/*the property*/);
  840.        OnChanged();
  841.        EndProcessing(nRet);
  842.    }    
  843.    else if(nRet != ERROR_DLG_CANCELED)
  844.       theApp.DisplayLEADError(nRet);
  845. }
  846.  
  847. void CMfcdemoView::OnImageEffectsSharpen() 
  848. {
  849.    CLeadDlg LTCommDlg;
  850.    RECT rcWin;
  851.    BOOL bContinue=FALSE;
  852.    int nRet;
  853.    
  854.    ::SetRect(&rcWin, 0, 0, 1, 1);
  855.  
  856.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  857.    {
  858.       LTCommDlg.SetEnableMethodErrors(FALSE);
  859.       //assign the bitmap for preview
  860.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  861.       LTCommDlg.SetUIFlags( DLG_IMG_SHARPEN | DLG_IMG_SHOWPREVIEW );
  862.       LTCommDlg.SetChange(0);
  863.       nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
  864.       if(nRet == 0)
  865.          bContinue = TRUE;
  866.       //release the reference
  867.       LTCommDlg.SetBitmap(0);
  868.    }
  869.    if(bContinue)
  870.    {
  871.        BeginProcessing();
  872.        int nRet = GetDocLead()->Sharpen(LTCommDlg.GetChange()/*the property*/);
  873.        OnChanged();
  874.        EndProcessing(nRet);
  875.    }    
  876.    else if(nRet != ERROR_DLG_CANCELED)
  877.       theApp.DisplayLEADError(nRet);
  878. }
  879.  
  880. void CMfcdemoView::OnImageBinaryfiltersDilation() 
  881. {
  882.    CLeadDlg LTCommDlg;
  883.    RECT rcWin;
  884.    BOOL bContinue=FALSE;
  885.    int nRet;
  886.    
  887.    ::SetRect(&rcWin, 0, 0, 1, 1);
  888.  
  889.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  890.    {
  891.       LTCommDlg.SetEnableMethodErrors(FALSE);
  892.       //assign the bitmap for preview
  893.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  894.       LTCommDlg.SetUIFlags( DLG_IMG_DILATION | DLG_IMG_SHOWPREVIEW );
  895.       nRet = LTCommDlg.GetFilter((long)this->m_hWnd);
  896.       if(nRet == 0)
  897.          bContinue = TRUE;
  898.       //release the reference
  899.       LTCommDlg.SetBitmap(0);
  900.    }
  901.    if(bContinue)
  902.    {
  903.        BeginProcessing();
  904.        int nRet = GetDocLead()->BinaryFilter( LTCommDlg.GetBinaryFilterType());
  905.        OnChanged();
  906.        EndProcessing(nRet);
  907.    }    
  908.    else if(nRet != ERROR_DLG_CANCELED)
  909.       theApp.DisplayLEADError(nRet);
  910. }
  911.  
  912. void CMfcdemoView::OnImageBinaryfiltersErosion() 
  913. {
  914.    CLeadDlg LTCommDlg;
  915.    RECT rcWin;
  916.    BOOL bContinue=FALSE;
  917.    int nRet;
  918.    
  919.    ::SetRect(&rcWin, 0, 0, 1, 1);
  920.  
  921.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  922.    {
  923.       LTCommDlg.SetEnableMethodErrors(FALSE);
  924.       //assign the bitmap for preview
  925.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  926.       LTCommDlg.SetUIFlags( DLG_IMG_EROSION | DLG_IMG_SHOWPREVIEW );
  927.       nRet = LTCommDlg.GetFilter((long)this->m_hWnd);
  928.       if(nRet == 0)
  929.          bContinue = TRUE;
  930.       //release the reference
  931.       LTCommDlg.SetBitmap(0);
  932.    }
  933.    if(bContinue)
  934.    {
  935.        BeginProcessing();
  936.        int nRet = GetDocLead()->BinaryFilter( LTCommDlg.GetBinaryFilterType());
  937.        OnChanged();
  938.        EndProcessing(nRet);
  939.    }    
  940.    else if(nRet != ERROR_DLG_CANCELED)
  941.       theApp.DisplayLEADError(nRet);
  942. }
  943.  
  944. void CMfcdemoView::OnImageSpatialfiltersGradient() 
  945. {
  946.    CLeadDlg LTCommDlg;
  947.    RECT rcWin;
  948.    BOOL bContinue=FALSE;
  949.    int nRet;
  950.    
  951.    ::SetRect(&rcWin, 0, 0, 1, 1);
  952.  
  953.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  954.    {
  955.       LTCommDlg.SetEnableMethodErrors(FALSE);
  956.       //assign the bitmap for preview
  957.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  958.       LTCommDlg.SetUIFlags( DLG_IMG_GRADIENT | DLG_IMG_SHOWPREVIEW );
  959.       nRet = LTCommDlg.GetFilter((long)this->m_hWnd);
  960.       if(nRet == 0)
  961.          bContinue = TRUE;
  962.       //release the reference
  963.       LTCommDlg.SetBitmap(0);
  964.    }
  965.    if(bContinue)
  966.    {
  967.        BeginProcessing();
  968.        int nRet = GetDocLead()->SpatialFilter( LTCommDlg.GetSpatialFilterType());
  969.        OnChanged();
  970.        EndProcessing(nRet);
  971.    }    
  972.    else if(nRet != ERROR_DLG_CANCELED)
  973.       theApp.DisplayLEADError(nRet);
  974. }
  975.  
  976. void CMfcdemoView::OnImageSpatialfiltersLaplacian() 
  977. {
  978.    CLeadDlg LTCommDlg;
  979.    RECT rcWin;
  980.    BOOL bContinue=FALSE;
  981.    int nRet;
  982.    
  983.    ::SetRect(&rcWin, 0, 0, 1, 1);
  984.  
  985.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  986.    {
  987.       LTCommDlg.SetEnableMethodErrors(FALSE);
  988.       //assign the bitmap for preview
  989.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  990.       LTCommDlg.SetUIFlags( DLG_IMG_LAPLACIAN | DLG_IMG_SHOWPREVIEW );
  991.       nRet = LTCommDlg.GetFilter((long)this->m_hWnd);
  992.       if(nRet == 0)
  993.          bContinue = TRUE;
  994.       //release the reference
  995.       LTCommDlg.SetBitmap(0);
  996.    }
  997.    if(bContinue)
  998.    {
  999.        BeginProcessing();
  1000.        int nRet = GetDocLead()->SpatialFilter( LTCommDlg.GetSpatialFilterType());
  1001.        OnChanged();
  1002.        EndProcessing(nRet);
  1003.    }    
  1004.    else if(nRet != ERROR_DLG_CANCELED)
  1005.       theApp.DisplayLEADError(nRet);
  1006. }
  1007.  
  1008. void CMfcdemoView::OnImageSpatialfiltersLinesegment() 
  1009. {
  1010.    CLeadDlg LTCommDlg;
  1011.    RECT rcWin;
  1012.    BOOL bContinue=FALSE;
  1013.    int nRet;
  1014.    
  1015.    ::SetRect(&rcWin, 0, 0, 1, 1);
  1016.  
  1017.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  1018.    {
  1019.       LTCommDlg.SetEnableMethodErrors(FALSE);
  1020.       //assign the bitmap for preview
  1021.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  1022.       LTCommDlg.SetUIFlags( DLG_IMG_LINESEG | DLG_IMG_SHOWPREVIEW );
  1023.       nRet = LTCommDlg.GetFilter((long)this->m_hWnd);
  1024.       if(nRet == 0)
  1025.          bContinue = TRUE;
  1026.       //release the reference
  1027.       LTCommDlg.SetBitmap(0);
  1028.    }
  1029.    if(bContinue)
  1030.    {
  1031.        BeginProcessing();
  1032.        int nRet = GetDocLead()->SpatialFilter( LTCommDlg.GetSpatialFilterType());
  1033.        OnChanged();
  1034.        EndProcessing(nRet);
  1035.    }    
  1036.    else if(nRet != ERROR_DLG_CANCELED)
  1037.       theApp.DisplayLEADError(nRet);
  1038. }
  1039.  
  1040. void CMfcdemoView::OnImageSpatialfiltersPrewitt() 
  1041. {
  1042.    CLeadDlg LTCommDlg;
  1043.    RECT rcWin;
  1044.    BOOL bContinue=FALSE;
  1045.    int nRet;
  1046.    
  1047.    ::SetRect(&rcWin, 0, 0, 1, 1);
  1048.  
  1049.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  1050.    {
  1051.       LTCommDlg.SetEnableMethodErrors(FALSE);
  1052.       //assign the bitmap for preview
  1053.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  1054.       LTCommDlg.SetUIFlags( DLG_IMG_PREWITT | DLG_IMG_SHOWPREVIEW );
  1055.       nRet = LTCommDlg.GetFilter((long)this->m_hWnd);
  1056.       if(nRet == 0)
  1057.          bContinue = TRUE;
  1058.       //release the reference
  1059.       LTCommDlg.SetBitmap(0);
  1060.    }
  1061.    if(bContinue)
  1062.    {
  1063.        BeginProcessing();
  1064.        int nRet = GetDocLead()->SpatialFilter( LTCommDlg.GetSpatialFilterType());
  1065.        OnChanged();
  1066.        EndProcessing(nRet);
  1067.    }    
  1068.    else if(nRet != ERROR_DLG_CANCELED)
  1069.       theApp.DisplayLEADError(nRet);
  1070. }
  1071.  
  1072. void CMfcdemoView::OnImageSpatialfiltersShiftanddifference() 
  1073. {
  1074.    CLeadDlg LTCommDlg;
  1075.    RECT rcWin;
  1076.    BOOL bContinue=FALSE;
  1077.    int nRet;
  1078.    
  1079.    ::SetRect(&rcWin, 0, 0, 1, 1);
  1080.  
  1081.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  1082.    {
  1083.       LTCommDlg.SetEnableMethodErrors(FALSE);
  1084.       //assign the bitmap for preview
  1085.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  1086.       LTCommDlg.SetUIFlags( DLG_IMG_SHIFTDIFF | DLG_IMG_SHOWPREVIEW );
  1087.       nRet = LTCommDlg.GetFilter((long)this->m_hWnd);
  1088.       if(nRet == 0)
  1089.          bContinue = TRUE;
  1090.       //release the reference
  1091.       LTCommDlg.SetBitmap(0);
  1092.    }
  1093.    if(bContinue)
  1094.    {
  1095.        BeginProcessing();
  1096.        int nRet = GetDocLead()->SpatialFilter( LTCommDlg.GetSpatialFilterType());
  1097.        OnChanged();
  1098.        EndProcessing(nRet);
  1099.    }    
  1100.    else if(nRet != ERROR_DLG_CANCELED)
  1101.       theApp.DisplayLEADError(nRet);
  1102. }
  1103.  
  1104. void CMfcdemoView::OnImageSpatialfiltersSobel() 
  1105. {
  1106.    CLeadDlg LTCommDlg;
  1107.    RECT rcWin;
  1108.    BOOL bContinue=FALSE;
  1109.    int nRet;
  1110.    
  1111.    ::SetRect(&rcWin, 0, 0, 1, 1);
  1112.  
  1113.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  1114.    {
  1115.       LTCommDlg.SetEnableMethodErrors(FALSE);
  1116.       //assign the bitmap for preview
  1117.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  1118.       LTCommDlg.SetUIFlags( DLG_IMG_SOBEL | DLG_IMG_SHOWPREVIEW );
  1119.       nRet = LTCommDlg.GetFilter((long)this->m_hWnd);
  1120.       if(nRet == 0)
  1121.          bContinue = TRUE;
  1122.       //release the reference
  1123.       LTCommDlg.SetBitmap(0);
  1124.    }
  1125.    if(bContinue)
  1126.    {
  1127.        BeginProcessing();
  1128.        int nRet = GetDocLead()->SpatialFilter( LTCommDlg.GetSpatialFilterType());
  1129.        OnChanged();
  1130.        EndProcessing(nRet);
  1131.    }    
  1132.    else if(nRet != ERROR_DLG_CANCELED)
  1133.       theApp.DisplayLEADError(nRet);
  1134. }
  1135.  
  1136. void CMfcdemoView::OnColorGammacorrect() 
  1137. {
  1138.    CLeadDlg LTCommDlg;
  1139.    RECT rcWin;
  1140.    BOOL bContinue=FALSE;
  1141.    int nRet;
  1142.    
  1143.    ::SetRect(&rcWin, 0, 0, 1, 1);
  1144.  
  1145.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  1146.    {
  1147.       LTCommDlg.SetEnableMethodErrors(FALSE);
  1148.       //assign the bitmap for preview
  1149.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  1150.       LTCommDlg.SetUIFlags( DLG_IMG_SHOWPREVIEW );
  1151.       nRet = LTCommDlg.GetGamma((long)this->m_hWnd);//the method
  1152.          bContinue = TRUE;
  1153.       //release the reference
  1154.       LTCommDlg.SetBitmap(0);
  1155.    }
  1156.    if(bContinue)
  1157.    {
  1158.        BeginProcessing();
  1159.        int nRet = GetDocLead()->GammaCorrect( LTCommDlg.GetGamma() /* the property */);
  1160.        OnChanged();
  1161.        EndProcessing(nRet);
  1162.    }    
  1163.    else if(nRet != ERROR_DLG_CANCELED)
  1164.       theApp.DisplayLEADError(nRet);
  1165. }
  1166.  
  1167.  
  1168.  
  1169. void CMfcdemoView::OnImageResize() 
  1170. {
  1171.     if(m_Lead.GetHasRgn())
  1172.     {
  1173.       OnImageRegiontransformationsResize();
  1174.     }
  1175.     else
  1176.     {
  1177.       CResizeDlg dlg;
  1178.  
  1179.       dlg.m_nWidth = (int) GetDocLead()->GetBitmapWidth();
  1180.       dlg.m_nHeight = (int) GetDocLead()->GetBitmapHeight();
  1181.       if(dlg.DoModal() == IDOK)
  1182.       {
  1183.           int nRet;
  1184.   
  1185.           BeginProcessing();
  1186.           if(dlg.m_fResample)
  1187.               nRet = GetDocLead()->Size((float) dlg.m_nWidth, (float) dlg.m_nHeight, RESIZE_RESAMPLE);
  1188.           else
  1189.               nRet = GetDocLead()->Size((float) dlg.m_nWidth, (float) dlg.m_nHeight, RESIZE_NORMAL);
  1190.           OnChanged();
  1191.           EndProcessing(nRet);
  1192.       }
  1193.    }
  1194. }
  1195.  
  1196. void CMfcdemoView::OnImageRotateAnyangle() 
  1197. {
  1198.    if(m_Lead.GetHasRgn())
  1199.    {
  1200.       OnImageRegiontransformationsRotate();
  1201.    }
  1202.    else
  1203.    {
  1204.       CLeadDlg LTCommDlg;
  1205.       RECT rcWin;
  1206.       BOOL bContinue=FALSE;
  1207.       int nRet;
  1208.  
  1209.       ::SetRect(&rcWin, 0, 0, 1, 1);
  1210.  
  1211.       if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  1212.       {
  1213.          LTCommDlg.SetEnableMethodErrors(FALSE);
  1214.          //assign the bitmap for preview
  1215.          LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  1216.          LTCommDlg.SetBackColor(RGB(255,255,255));
  1217.          LTCommDlg.SetUIFlags( DLG_IMG_ROTATE | DLG_IMG_SHOWPREVIEW );
  1218.          nRet = LTCommDlg.GetAngle((long)this->m_hWnd); /* the method */
  1219.          if(nRet == 0)
  1220.             bContinue = TRUE;
  1221.          //release the reference
  1222.          LTCommDlg.SetBitmap(0);
  1223.       }
  1224.       if(bContinue)
  1225.       {
  1226.          BeginProcessing();
  1227.          int nRet = GetDocLead()->Rotate((long) LTCommDlg.GetAngle(), /* the property */
  1228.                                          LTCommDlg.GetAngleFlag(),
  1229.                                          LTCommDlg.GetBackColor() );
  1230.          OnChanged();
  1231.          EndProcessing(nRet);
  1232.       }    
  1233.       else if(nRet != ERROR_DLG_CANCELED)
  1234.          theApp.DisplayLEADError(nRet);
  1235.    }
  1236. }
  1237.  
  1238. void CMfcdemoView::OnImageShear() 
  1239. {
  1240.    if(m_Lead.GetHasRgn())
  1241.    {
  1242.       OnImageRegiontransformationsShear();
  1243.    }
  1244.    else
  1245.    {
  1246.       CLeadDlg LTCommDlg;
  1247.       RECT rcWin;
  1248.       BOOL bContinue=FALSE;
  1249.       int nRet;
  1250.  
  1251.       ::SetRect(&rcWin, 0, 0, 1, 1);
  1252.  
  1253.       if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  1254.       {
  1255.          LTCommDlg.SetEnableMethodErrors(FALSE);
  1256.          //assign the bitmap for preview
  1257.          LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  1258.          LTCommDlg.SetBackColor(RGB(255,255,255));
  1259.          LTCommDlg.SetUIFlags( DLG_IMG_SHEAR | DLG_IMG_SHOWPREVIEW );
  1260.          nRet = LTCommDlg.GetAngle((long)this->m_hWnd); /* the method */
  1261.          if(nRet == 0)
  1262.             bContinue = TRUE;
  1263.          //release the reference
  1264.          LTCommDlg.SetBitmap(0);
  1265.       }
  1266.       if(bContinue)
  1267.       {
  1268.          BeginProcessing();
  1269.          int nRet = GetDocLead()->Shear((short) LTCommDlg.GetAngle(), /* the property */
  1270.                                         LTCommDlg.GetAngleFlag(),
  1271.                                         RGB(255, 255, 255) );
  1272.          OnChanged();
  1273.          EndProcessing(nRet);
  1274.       }    
  1275.       else if(nRet != ERROR_DLG_CANCELED)
  1276.          theApp.DisplayLEADError(nRet);
  1277.    }
  1278. }
  1279.  
  1280. void CMfcdemoView::OnColorColorresolution() 
  1281. {
  1282.    CLeadDlg LTCommDlg;
  1283.    RECT rcWin;
  1284.    BOOL bContinue=FALSE;
  1285.    int nRet;
  1286.    
  1287.    ::SetRect(&rcWin, 0, 0, 1, 1);
  1288.  
  1289.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  1290.    {
  1291.       LTCommDlg.SetEnableMethodErrors(FALSE);
  1292.       //assign the bitmap for preview
  1293.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  1294.       LTCommDlg.SetUIFlags( DLG_CR_BITALL | DLG_CR_DITHER_ALL | DLG_CR_PAL_ALL | DLG_CR_ORDER | DLG_CR_SHOWPREVIEW );
  1295.       nRet =    LTCommDlg.GetColorRes((long)this->m_hWnd);
  1296.       if(nRet == 0)
  1297.          bContinue = TRUE;
  1298.       //release the reference
  1299.       LTCommDlg.SetBitmap(0);
  1300.    }
  1301.    if(bContinue)
  1302.    {
  1303.        BeginProcessing();
  1304.        int nRet = GetDocLead()->ColorRes( LTCommDlg.GetBitsPerPixel(),
  1305.                                           LTCommDlg.GetPaletteFlags(),
  1306.                                           LTCommDlg.GetDitherFlags(),
  1307.                                           0 );
  1308.  
  1309.        OnChanged();
  1310.        EndProcessing(nRet);
  1311.    }    
  1312.    else if(nRet != ERROR_DLG_CANCELED)
  1313.       theApp.DisplayLEADError(nRet);
  1314. }
  1315.  
  1316. void CMfcdemoView::OnColorIntensitydetect() 
  1317. {
  1318.    CLeadDlg LTCommDlg;
  1319.    RECT rcWin;
  1320.    BOOL bContinue=FALSE;
  1321.    int nRet;
  1322.    
  1323.    ::SetRect(&rcWin, 0, 0, 1, 1);
  1324.  
  1325.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  1326.    {
  1327.       LTCommDlg.SetEnableMethodErrors(FALSE);
  1328.       //assign the bitmap for preview
  1329.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  1330.       LTCommDlg.SetUIFlags( DLG_IMG_SHOWPREVIEW );
  1331.       nRet = LTCommDlg.GetRange((long)this->m_hWnd);//the method
  1332.       if(nRet == 0)
  1333.          bContinue = TRUE;
  1334.       //release the reference
  1335.       LTCommDlg.SetBitmap(0);
  1336.    }
  1337.    if(bContinue)
  1338.    {
  1339.        BeginProcessing();
  1340.        int nRet = GetDocLead()->IntensityDetect( LTCommDlg.GetLow(), LTCommDlg.GetHigh());
  1341.        OnChanged();
  1342.        EndProcessing(nRet);
  1343.    }    
  1344.    else if(nRet != ERROR_DLG_CANCELED)
  1345.       theApp.DisplayLEADError(nRet);
  1346. }
  1347.  
  1348. void CMfcdemoView::OnViewZoom() 
  1349. {
  1350.     CRangeDlg dlg;
  1351.  
  1352.     dlg.m_strTitle = _T("Zoom");
  1353.     dlg.m_strLabel = _T("&Amount");
  1354.     dlg.m_nValue = m_nZoom;
  1355.     dlg.m_nMin = 1;
  1356.     dlg.m_nMax = 800;
  1357.     dlg.m_nPage = 100;
  1358.  
  1359.     if(dlg.DoModal() == IDOK)
  1360.     {
  1361.         SetZoom(dlg.m_nValue);
  1362.     }    
  1363. }
  1364.  
  1365. void CMfcdemoView::OnViewNormal() 
  1366. {
  1367.         SetZoom(100);
  1368. }
  1369.  
  1370. static int nEffectIndex[] =
  1371. {
  1372.    EFX_EFFECT_WIPE_CLASS,              EFX_EFFECT_WIPE_MAX,
  1373.    EFX_EFFECT_WIPE_RECTANGLE_CLASS,    EFX_EFFECT_WIPE_RECTANGLE_MAX,
  1374.    EFX_EFFECT_WIPE_CIRCLE_CLASS,       EFX_EFFECT_WIPE_CIRCLE_MAX,
  1375.    EFX_EFFECT_PUSH_CLASS,              EFX_EFFECT_PUSH_MAX,
  1376.    EFX_EFFECT_SLIDE_CLASS,             EFX_EFFECT_SLIDE_MAX,
  1377.    EFX_EFFECT_ROLL_CLASS,              EFX_EFFECT_ROLL_MAX,
  1378.    EFX_EFFECT_ROTATE_CLASS,            EFX_EFFECT_ROTATE_MAX,
  1379.    EFX_EFFECT_ZOOM_CLASS,              EFX_EFFECT_ZOOM_MAX,
  1380.    EFX_EFFECT_DRIP_CLASS,              EFX_EFFECT_DRIP_MAX,
  1381.    EFX_EFFECT_BLIND_CLASS,             EFX_EFFECT_BLIND_MAX,
  1382.    EFX_EFFECT_RANDOM_CLASS,            EFX_EFFECT_RANDOM_MAX,
  1383.    EFX_EFFECT_CHECKERBOARD_CLASS,      EFX_EFFECT_CHECKERBOARD_MAX,
  1384.    EFX_EFFECT_BLOCKS_CLASS,            EFX_EFFECT_BLOCKS_MAX,
  1385.    EFX_EFFECT_CIRCLE_CLASS,            EFX_EFFECT_CIRCLE_MAX,
  1386.    EFX_EFFECT_ELLIPSE_CLASS,           EFX_EFFECT_ELLIPSE_MAX,
  1387. };
  1388.  
  1389. void CMfcdemoView::OnViewPainteffects() 
  1390. {
  1391.    CClientDC cdc(this);
  1392.    DWORD dw;
  1393.    int i;
  1394.  
  1395.    BeginWaitCursor();
  1396.    for (i = 0; i < sizeof(nEffectIndex) / sizeof(nEffectIndex[0]); i += 2)
  1397.    {
  1398.       for (m_nEffect = nEffectIndex[i]; m_nEffect <= nEffectIndex[i+1]; m_nEffect++)
  1399.       {
  1400.         m_Lead.SetPaintEffect(m_nEffect);
  1401.         dw = GetTickCount ();
  1402.         while ((GetTickCount () - dw) < 1000);
  1403.       }                 
  1404.    }
  1405.    m_nEffect = EFX_EFFECT_NONE;
  1406.    m_Lead.SetPaintEffect(m_nEffect);
  1407.    EndWaitCursor();
  1408. }
  1409.  
  1410. void CMfcdemoView::OnViewSnapwindowtoimage() 
  1411. {
  1412.    CWnd* pFrame = GetParent();
  1413.    CRect rcWindow;
  1414.    CRect rcClient;
  1415.  
  1416.    pFrame->ShowWindow(SW_NORMAL);
  1417.    GetClientRect(&rcClient);
  1418.    pFrame->GetWindowRect(&rcWindow);
  1419.  
  1420.    pFrame->GetParent()->ScreenToClient (rcWindow);
  1421.  
  1422.    pFrame->MoveWindow (rcWindow.left, rcWindow.top,
  1423.                rcWindow.Width() + (int) m_Lead.GetDstWidth() - rcClient.Width(),
  1424.                rcWindow.Height() + (int) m_Lead.GetDstHeight() - rcClient.Height());
  1425. }
  1426.  
  1427. void CMfcdemoView::OnViewFitimagetowindow() 
  1428. {
  1429.     int cxZoom, cyZoom; 
  1430.     cxZoom = (int) ((long) m_Lead.GetScaleWidth() * 100 / m_Lead.GetBitmapWidth());
  1431.     cyZoom = (int) ((long) m_Lead.GetScaleHeight() * 100 / m_Lead.GetBitmapHeight());
  1432.     SetZoom(max(min(cxZoom, cyZoom), 1));
  1433. }
  1434.  
  1435. void CMfcdemoView::OnImageEffectsEmboss() 
  1436. {
  1437.    CLeadDlg LTCommDlg;
  1438.    RECT rcWin;
  1439.    BOOL bContinue=FALSE;
  1440.    int nRet;
  1441.    
  1442.    ::SetRect(&rcWin, 0, 0, 1, 1);
  1443.  
  1444.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  1445.    {
  1446.       LTCommDlg.SetEnableMethodErrors(FALSE);
  1447.       //assign the bitmap for preview
  1448.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  1449.       LTCommDlg.SetUIFlags( DLG_IMG_SHOWPREVIEW );
  1450.       nRet = LTCommDlg.GetEmboss((long)this->m_hWnd);
  1451.       if(nRet == 0)
  1452.          bContinue = TRUE;
  1453.       //release the reference
  1454.       LTCommDlg.SetBitmap(0);
  1455.    }
  1456.    if(bContinue)
  1457.    {
  1458.        BeginProcessing();
  1459.        int nRet = GetDocLead()->Emboss( LTCommDlg.GetDirection(), LTCommDlg.GetDepth());
  1460.        OnChanged();
  1461.        EndProcessing(nRet);
  1462.    }    
  1463.    else if(nRet != ERROR_DLG_CANCELED)
  1464.       theApp.DisplayLEADError(nRet);
  1465. }
  1466.  
  1467. void CMfcdemoView::OnColorHalftone() 
  1468. {
  1469.    CLeadDlg LTCommDlg;
  1470.    RECT rcWin;
  1471.    BOOL bContinue=FALSE;
  1472.    int nRet;
  1473.    
  1474.    ::SetRect(&rcWin, 0, 0, 1, 1);
  1475.  
  1476.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  1477.    {
  1478.       LTCommDlg.SetEnableMethodErrors(FALSE);
  1479.       //assign the bitmap for preview
  1480.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  1481.       LTCommDlg.SetUIFlags( DLG_IMG_HALFTONE | DLG_IMG_SHOWPREVIEW );
  1482.       nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
  1483.       if(nRet == 0)
  1484.          bContinue = TRUE;
  1485.       //release the reference
  1486.       LTCommDlg.SetBitmap(0);
  1487.    }
  1488.    if(bContinue)
  1489.    {
  1490.        BeginProcessing();
  1491.        int nRet = GetDocLead()->Halftone(1, LTCommDlg.GetChange()/*the property*/);
  1492.        OnChanged();
  1493.        EndProcessing(nRet);
  1494.    }    
  1495.    else if(nRet != ERROR_DLG_CANCELED)
  1496.       theApp.DisplayLEADError(nRet);
  1497. }
  1498.  
  1499. void CMfcdemoView::OnColorFill() 
  1500. {
  1501.     CColorDialog dlg;
  1502.  
  1503.     if(dlg.DoModal() == IDOK)
  1504.     {
  1505.         BeginProcessing();
  1506.         int nRet = GetDocLead()->Fill(dlg.GetColor());
  1507.         OnChanged();
  1508.         EndProcessing(nRet);
  1509.     }
  1510. }
  1511.  
  1512. void CMfcdemoView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
  1513. {
  1514.     CMfcdemoDoc* pDoc = GetDocument();
  1515.     long hRegion;
  1516.  
  1517.     m_Lead.SetAutoRepaint(FALSE);
  1518.     m_Lead.SetBitmap(GetDocLead()->GetBitmap());
  1519.     m_Lead.SetPaintPalette(theApp.m_fAutoPalette ? PAINTPALETTE_AUTO : PAINTPALETTE_FIXED);
  1520.     m_Lead.SetPaintDither(theApp.m_fOrderedDither ? PAINTDITHER_ORDERED : PAINTDITHER_DIFFUSION);
  1521.     m_Lead.SetBitonalScaling(theApp.m_nBitonalScaling);
  1522.     m_Lead.SetDstRect(m_Lead.GetDstLeft(), m_Lead.GetDstTop(), m_Lead.GetBitmapWidth() * m_nZoom / 100, m_Lead.GetBitmapHeight() * m_nZoom / 100);
  1523.     m_Lead.SetDstClipRect(m_Lead.GetDstLeft(), m_Lead.GetDstTop(), m_Lead.GetDstWidth(), m_Lead.GetDstHeight());
  1524.     /* copy the region from the document control */
  1525.     if( GetDocLead()->GetHasRgn() )
  1526.     {
  1527.       hRegion = GetDocLead()->GetRgnHandle();
  1528.       m_Lead.SetRgnHandle(hRegion,0.0f,0.0f,L_RGN_SET);
  1529.       m_Lead.SetRgnFrameType(RGNFRAME_STATIC);
  1530.       m_Lead.DeleteRgnHandle(hRegion);
  1531.     }
  1532.     else
  1533.     {
  1534.       /* the region processing are only for express toolkits */
  1535.       if( !m_Lead.IsSupportLocked(L_SUPPORT_EXPRESS) )
  1536.       {
  1537.          m_Lead.SetRgnFrameType(RGNFRAME_NONE);
  1538.          m_Lead.FreeRgn();
  1539.       }
  1540.     }
  1541.     m_Lead.SetAutoRepaint(TRUE);
  1542. }
  1543.  
  1544. void CMfcdemoView::OnEditUndo() 
  1545. {
  1546.     BeginWaitCursor();
  1547.     GetDocLead()->SetBitmap(GetUndoLead()->GetBitmap());
  1548.     GetUndoLead()->SetBitmap(0);
  1549.     OnChanged();
  1550.     EndWaitCursor();
  1551. }
  1552.  
  1553. void CMfcdemoView::OnUpdateEditUndo(CCmdUI* pCmdUI) 
  1554. {
  1555.     pCmdUI->Enable(GetUndoLead()->GetBitmap() != 0);    
  1556. }
  1557.  
  1558. void CMfcdemoView::OnEditCopy() 
  1559. {
  1560.     BeginWaitCursor();
  1561.     GetDocLead()->Copy(COPY_DIB | COPY_DDB | COPY_PALETTE);
  1562.     EndWaitCursor();
  1563. }
  1564.  
  1565. void CMfcdemoView::OnColorSeparation() 
  1566. {
  1567.     CListDlg dlg;
  1568.     int i, nPlanes;
  1569.  
  1570.     dlg.m_strTitle = _T("Separation");
  1571.     dlg.m_strLabel = _T("&Color Space");
  1572.     dlg.m_strInit = _T("RGB|CMYK|HSV|HLS|CMY|");
  1573.     if(dlg.DoModal() == IDOK)
  1574.     {
  1575.         BeginProcessing();
  1576.         int nRet = GetDocLead()->ColorSeparate(dlg.m_nValue);
  1577.         if(!nRet)
  1578.         {
  1579.             nPlanes = (dlg.m_nValue == COLORSEP_CMYK) ? 4 : 3;
  1580.             for(i = 0; i < nPlanes; i++)
  1581.             {
  1582.                 theApp.m_Bitmap = GetDocLead()->GetColorPlanes(i);
  1583.                 theApp.OpenDocument(OPENMODE_BITMAP);
  1584.                 GetDocLead()->SetColorPlanes(i, 0);
  1585.             }
  1586.         }
  1587.         EndProcessing(nRet);
  1588.     }
  1589. }
  1590.  
  1591. void CMfcdemoView::OnImageEffectsEdgeenhance() 
  1592. {
  1593.     BeginProcessing();
  1594.  
  1595.     int nRet = TRUE; //m_Lead.SpatialFilter(FLT_LAPLACE_1);
  1596.     if(!nRet)
  1597.     {
  1598.         nRet = GetDocLead()->Combine(0.0f, 0.0f, m_Lead.GetBitmapWidth(), m_Lead.GetBitmapHeight(),
  1599.                         m_Lead.GetBitmap(), 0.0f, 0.0f, CB_OP_ADD);
  1600.     }
  1601.     OnChanged();
  1602.     EndProcessing(nRet);
  1603. }
  1604.  
  1605. void CMfcdemoView::OnUpdateImageEffectsEdgeenhance(CCmdUI* pCmdUI) 
  1606. {
  1607.     pCmdUI->Enable(TRUE); //GetDocLead()->GetBitmapBits() > 8); 
  1608. }
  1609.  
  1610.  
  1611. void CMfcdemoView::OnImageDeskew() 
  1612. {
  1613.     BeginProcessing();
  1614.     int nRet = GetDocLead()->Deskew();
  1615.     OnChanged();
  1616.     EndProcessing(nRet);
  1617. }
  1618.  
  1619. void CMfcdemoView::OnImageEffectsUnderlay() 
  1620. {
  1621.     CUnderLayDlg dlg;
  1622.  
  1623.     if(dlg.DoModal() == IDOK)
  1624.     {
  1625.         BeginProcessing();
  1626.         int nRet = GetDocLead()->Underlay(((CMfcdemoDoc*)dlg.m_pDocument)->m_Lead.GetBitmap(), dlg.m_fTile ? UNDERLAY_TILE : UNDERLAY_STRETCH);
  1627.         OnChanged();
  1628.         EndProcessing(nRet);
  1629.     }
  1630. }
  1631.  
  1632. void CMfcdemoView::OnUpdateImageDeskew(CCmdUI* pCmdUI) 
  1633. {
  1634.     pCmdUI->Enable((GetDocLead()->GetVersionLevel() == VERSIONLEVEL_EXP||GetDocLead()->GetVersionLevel() == VERSIONLEVEL_MEDICAL)
  1635.        && !m_Lead.GetHasRgn());
  1636. }
  1637.  
  1638. void CMfcdemoView::OnUpdateImageShear(CCmdUI* pCmdUI) 
  1639. {
  1640.     //pCmdUI->Enable(!m_Lead.GetHasRgn());
  1641. }
  1642.  
  1643. void CMfcdemoView::OnUpdateImageBinaryfiltersDilation(CCmdUI* pCmdUI) 
  1644. {
  1645.     pCmdUI->Enable(GetDocLead()->GetVersionLevel() == VERSIONLEVEL_EXP||GetDocLead()->GetVersionLevel() == VERSIONLEVEL_MEDICAL);
  1646. }
  1647.  
  1648. void CMfcdemoView::OnUpdateImageBinaryfiltersErosion(CCmdUI* pCmdUI) 
  1649. {
  1650.     pCmdUI->Enable(GetDocLead()->GetVersionLevel() == VERSIONLEVEL_EXP||GetDocLead()->GetVersionLevel() == VERSIONLEVEL_MEDICAL);
  1651. }
  1652.  
  1653. void CMfcdemoView::OnUpdateImageEffectsDespeckle(CCmdUI* pCmdUI) 
  1654. {
  1655.     pCmdUI->Enable(GetDocLead()->GetVersionLevel() == VERSIONLEVEL_EXP||GetDocLead()->GetVersionLevel() == VERSIONLEVEL_MEDICAL);
  1656. }
  1657.  
  1658. void CMfcdemoView::OnSize(UINT nType, int cx, int cy) 
  1659. {
  1660.     CFormView::OnSize(nType, cx, cy);
  1661.  
  1662.     if( IsWindow(m_Lead.m_hWnd) )
  1663.         m_Lead.MoveWindow(0, 0, cx, cy);
  1664. }
  1665.  
  1666.  
  1667. void CMfcdemoView::OnToolnone() 
  1668. {
  1669.     SetRegionTool( IDM_TOOLNONE );
  1670. }
  1671.  
  1672. void CMfcdemoView::OnUpdateToolnone(CCmdUI* pCmdUI) 
  1673. {
  1674.    pCmdUI->Enable(!m_Lead.IsSupportLocked(L_SUPPORT_EXPRESS));
  1675.    pCmdUI->SetCheck(m_nRegionTool == IDM_TOOLNONE);
  1676. }
  1677.  
  1678. void CMfcdemoView::OnToolellipse() 
  1679. {
  1680.     SetRegionTool( IDM_TOOLELLIPSE );
  1681. }
  1682.  
  1683. void CMfcdemoView::OnUpdateToolellipse(CCmdUI* pCmdUI) 
  1684. {
  1685.    pCmdUI->Enable(!m_Lead.IsSupportLocked(L_SUPPORT_EXPRESS));
  1686.    pCmdUI->SetCheck(m_nRegionTool == IDM_TOOLELLIPSE);
  1687. }
  1688.  
  1689. void CMfcdemoView::OnToolfreehand() 
  1690. {
  1691.     SetRegionTool( IDM_TOOLFREEHAND );
  1692. }
  1693.  
  1694. void CMfcdemoView::OnUpdateToolfreehand(CCmdUI* pCmdUI) 
  1695. {
  1696.    pCmdUI->Enable(!m_Lead.IsSupportLocked(L_SUPPORT_EXPRESS));
  1697.    pCmdUI->SetCheck(m_nRegionTool == IDM_TOOLFREEHAND);
  1698. }
  1699.  
  1700. void CMfcdemoView::OnToolrect() 
  1701. {
  1702.     SetRegionTool( IDM_TOOLRECT );
  1703. }
  1704.  
  1705. void CMfcdemoView::OnUpdateToolrect(CCmdUI* pCmdUI) 
  1706. {
  1707.    pCmdUI->Enable(!m_Lead.IsSupportLocked(L_SUPPORT_EXPRESS));
  1708.    pCmdUI->SetCheck(m_nRegionTool == IDM_TOOLRECT);
  1709. }
  1710.  
  1711. void CMfcdemoView::OnToolrndrect() 
  1712. {
  1713.     SetRegionTool( IDM_TOOLRNDRECT );
  1714. }
  1715.  
  1716. void CMfcdemoView::OnUpdateToolrndrect(CCmdUI* pCmdUI) 
  1717. {
  1718.    pCmdUI->Enable(!m_Lead.IsSupportLocked(L_SUPPORT_EXPRESS));
  1719.    pCmdUI->SetCheck(m_nRegionTool == IDM_TOOLRNDRECT);
  1720. }
  1721.  
  1722. void CMfcdemoView::SetRegionTool( int nNewRegionTool )
  1723. {
  1724.    m_nRegionTool = nNewRegionTool;
  1725. }
  1726.  
  1727.  
  1728. BEGIN_EVENTSINK_MAP(CMfcdemoView, CFormView)
  1729.     //{{AFX_EVENTSINK_MAP(CMfcdemoView)
  1730.     ON_EVENT(CMfcdemoView, IDC_LEADCTRL1, -605 /* MouseDown */, OnMouseDownLeadctrl1, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
  1731.     ON_EVENT(CMfcdemoView, IDC_LEADCTRL1, -606 /* MouseMove */, OnMouseMoveLeadctrl1, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
  1732.     ON_EVENT(CMfcdemoView, IDC_LEADCTRL1, -607 /* MouseUp */, OnMouseUpLeadctrl1, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
  1733.     ON_EVENT(CMfcdemoView, IDC_LEADCTRL1, 7 /* RgnChange */, OnRgnChangeLeadctrl1, VTS_NONE)
  1734.     //}}AFX_EVENTSINK_MAP
  1735. END_EVENTSINK_MAP()
  1736.  
  1737. void CMfcdemoView::OnRgnChangeLeadctrl1()
  1738. {
  1739.       if(GetDocument()->m_Lead2.GetBitmap() == NULL)
  1740.         SaveBackground();
  1741. }
  1742.  
  1743. void CMfcdemoView::OnMouseDownLeadctrl1(short Button, short Shift, long x, long y) 
  1744. {
  1745.     if( Button != 1 )
  1746.       return; /* nothing to do! */
  1747.  
  1748.    HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
  1749.  
  1750.    if( m_Lead.GetHasRgn() && m_Lead.IsPtInRgn((x - m_Lead.GetDstLeft()) * m_Lead.GetSrcWidth() / m_Lead.GetDstWidth(), (y - m_Lead.GetDstTop()) * m_Lead.GetSrcHeight() / m_Lead.GetDstHeight()) )
  1751.    {
  1752.       m_Lead.SetAutoRepaint(FALSE);
  1753.       m_Lead.SetRgnMarkingMode(RGNMARK_NONE);
  1754.       m_Lead.SetRgnFrameType(RGNFRAME_NONE);
  1755.       m_xStart = x;
  1756.       m_yStart = y;
  1757.       // we put the floater into the bitmap only when we select another region
  1758.       // if we have a floater at this point, it's because we clicked INSIDE the floater
  1759.       m_Lead.SetFloaterVisible(FALSE);
  1760.       m_Lead.SetFloater(m_Lead.GetBitmap());
  1761.       // the floater coordinates are relative to the window, while the
  1762.       // ocx region coordinates are relative to the bitmap. Adding m_Lead.DstLeft
  1763.       // converts m_Lead.RgnLeft to window coordinates
  1764.       m_rcFloater.left = (int) ((m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() + m_Lead.GetSrcWidth() - 1) / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft());
  1765.       m_rcFloater.top = (int) (m_Lead.GetRgnTop() * m_Lead.GetDstHeight() / m_Lead.GetSrcHeight() + m_Lead.GetDstTop());
  1766.       m_rcFloater.right = (int) (((m_Lead.GetFloaterWidth() + m_Lead.GetRgnLeft()) * m_Lead.GetDstWidth() + m_Lead.GetSrcWidth() - 1) / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft());
  1767.       m_rcFloater.bottom = (int) ((m_Lead.GetFloaterHeight() + m_Lead.GetRgnTop()) * m_Lead.GetDstHeight() / m_Lead.GetSrcHeight() + m_Lead.GetDstTop());
  1768.       m_Lead.SetFloaterDstRect((float) m_rcFloater.left, (float) m_rcFloater.top,
  1769.                  (float) m_rcFloater.Width(), (float) m_rcFloater.Height());
  1770.       if( GetDocument()->m_Lead2.GetBitmap() != NULL )
  1771.       {
  1772.          m_Lead.Combine(m_Lead.GetRgnLeft(), 
  1773.                         m_Lead.GetRgnTop(), 
  1774.                         m_Lead.GetFloaterWidth(), 
  1775.                         m_Lead.GetFloaterHeight(), 
  1776.                         GetDocument()->m_Lead2.GetBitmap(), 
  1777.                         0.0f, 
  1778.                         0.0f, 
  1779.                         L_SRC_COPY );
  1780.          // RepaintRect uses window coordinates like the floater bitmap
  1781.          m_Lead.RepaintRect(m_Lead.GetFloaterDstLeft(), 
  1782.                            m_Lead.GetFloaterDstTop(), 
  1783.                            m_Lead.GetFloaterDstWidth(), 
  1784.                            m_Lead.GetFloaterDstHeight(), 
  1785.                            FALSE);
  1786.       }
  1787.       m_Lead.SetFloaterVisible(TRUE);
  1788.       m_bMovingFloater = TRUE;
  1789.    }
  1790.    else if (m_nRegionTool != IDM_TOOLNONE)
  1791.    {
  1792.       m_Lead.SetRgnFrameType(RGNFRAME_NONE);
  1793.  
  1794.       switch(m_nRegionTool)
  1795.       {
  1796.       case IDM_TOOLRECT:
  1797.          m_Lead.SetRgnMarkingMode(RGNMARK_RECT);
  1798.          break;
  1799.       case IDM_TOOLELLIPSE:
  1800.          m_Lead.SetRgnMarkingMode(RGNMARK_ELLIPSE);
  1801.          break;
  1802.       case IDM_TOOLRNDRECT:
  1803.          m_Lead.SetRgnMarkingMode(RGNMARK_ROUNDRECT);
  1804.          break;
  1805.       case IDM_TOOLFREEHAND:
  1806.          m_Lead.SetRgnMarkingMode(RGNMARK_FREEHAND);
  1807.          break;
  1808.       }
  1809.    }
  1810.  
  1811.    GetDocument()->m_Lead2.SetBitmap(0); // the background bitmap is not needed anymore
  1812.  
  1813.    SetCursor(hOldCursor);
  1814. }
  1815.  
  1816. void CMfcdemoView::OnMouseMoveLeadctrl1(short Button, short Shift, long x, long y) 
  1817. {
  1818.    if( (Button == 1) && m_bMovingFloater )
  1819.    {
  1820.       m_Lead.SetFloaterDstRect((float) (m_rcFloater.left + x - m_xStart), (float) (m_rcFloater.top + y - m_yStart),
  1821.            m_Lead.GetFloaterDstWidth(), m_Lead.GetFloaterDstHeight());
  1822.    }
  1823. }
  1824.  
  1825. void CMfcdemoView::OnMouseUpLeadctrl1(short Button, short Shift, long x, long y) 
  1826. {
  1827.   HRGN hRegion;
  1828.    long dx, dy;
  1829.  
  1830.    if (Button != 1)
  1831.       return;  /* nothing to do ! */
  1832.  
  1833.    HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
  1834.  
  1835.    if( m_Lead.GetRgnMarkingMode() != RGNMARK_NONE )
  1836.    {
  1837.       m_Lead.SetRgnMarkingMode(RGNMARK_NONE);
  1838.       m_Lead.SetRgnFrameType(RGNFRAME_STATIC);
  1839.  
  1840.       if( m_Lead.GetHasRgn() )
  1841.       {
  1842.          hRegion = (HRGN)m_Lead.GetRgnHandle();
  1843.          GetDocLead()->SetRgnHandle((long)hRegion,0.0f,0.0f,L_RGN_SET);
  1844.          m_Lead.DeleteRgnHandle((long)hRegion);
  1845.       }
  1846.       else
  1847.          GetDocLead()->FreeRgn();
  1848.       GetDocument()->UpdateAllViews(this, (LPARAM)0);
  1849.    }
  1850.    else if(m_bMovingFloater)
  1851.    {
  1852.       m_bMovingFloater = FALSE;
  1853.       m_Lead.SetRgnFrameType(RGNFRAME_NONE);
  1854.       hRegion = (HRGN)m_Lead.GetFloaterHandle();
  1855.  
  1856.  
  1857.       // Calculate the region offset    
  1858.  
  1859.       if(x >= m_xStart)
  1860.         dx = (x - m_xStart) * (long) m_Lead.GetSrcWidth() / (long) m_Lead.GetDstWidth();
  1861.       else
  1862.         dx = ((x - m_xStart) * (long) m_Lead.GetSrcWidth() - (long) m_Lead.GetDstWidth() + 1) / (long) m_Lead.GetDstWidth();
  1863.       if(y >= m_yStart)
  1864.         dy = (y - m_yStart) * (long) m_Lead.GetSrcHeight() / (long) m_Lead.GetDstHeight();
  1865.       else
  1866.         dy = ((y - m_yStart) * (long) m_Lead.GetSrcHeight() - (long) m_Lead.GetDstHeight() + 1) / (long) m_Lead.GetDstHeight();
  1867.  
  1868.       m_Lead.OffsetRgn((float) dx, (float) dy);
  1869.  
  1870.       // save the background in case we want to move the floater again
  1871.       GetDocument()->m_Lead2.CreateBitmap(m_Lead.GetFloaterWidth(), 
  1872.                            m_Lead.GetFloaterHeight(), 
  1873.                            m_Lead.GetBitmapBits() );
  1874.       if((m_Lead.GetIsGrayscale() != GRAY_NO) && (m_Lead.GetBitmapBits()>8))
  1875.          GetDocument()->m_Lead2.Grayscale(m_Lead.GetBitmapBits());
  1876.  
  1877.       GetDocument()->m_Lead2.Combine( 0.0f, 
  1878.                         0.0f, 
  1879.                         m_Lead.GetFloaterWidth(), 
  1880.                         m_Lead.GetFloaterHeight(), 
  1881.                         m_Lead.GetBitmap(), 
  1882.                         m_Lead.GetRgnLeft(), 
  1883.                         m_Lead.GetRgnTop(), 
  1884.                         L_SRC_COPY);
  1885.  
  1886.       // now blend the floater into the bitmap and make it dissapear
  1887.       // if we leave it, when we scroll, the floater won't move with the bitmap
  1888.       // that's because the floater is independent of the bitmap
  1889.       m_Lead.Combine( m_Lead.GetRgnLeft(), 
  1890.                      m_Lead.GetRgnTop(), 
  1891.                      m_Lead.GetFloaterWidth(), 
  1892.                      m_Lead.GetFloaterHeight(), 
  1893.                      m_Lead.GetFloater(), 
  1894.                      0.0f, 
  1895.                      0.0f, 
  1896.                      L_SRC_COPY);
  1897.       // free the floater
  1898.       m_Lead.SetFloater(NULL);
  1899.  
  1900.       // draw the frame
  1901.       m_Lead.SetRgnFrameType(RGNFRAME_STATIC);
  1902.       m_Lead.DeleteRgnHandle ((long)hRegion); // delete the region object
  1903.  
  1904.  
  1905.       m_Lead.SetAutoRepaint(TRUE);
  1906.       /* update the changes back into the master document and all other views */
  1907.       UpdateMasterDocument();
  1908.    }
  1909.  
  1910.    SetCursor(hOldCursor);
  1911. }
  1912.  
  1913. void CMfcdemoView::OnImageRegiontransformationsFlip() 
  1914. {
  1915.    long hRegion;
  1916.    float xCenter;
  1917.    float yCenter;
  1918.  
  1919.    HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
  1920.  
  1921.    m_Lead.SetAutoRepaint(FALSE);
  1922.    m_Lead.SetFloaterVisible(FALSE);
  1923.    m_Lead.SetFloater(m_Lead.GetBitmap());
  1924.    RestoreBackground();
  1925.    m_Lead3.SetBitmap(m_Lead.GetFloater());
  1926.    m_Lead.SetFloater(0);
  1927.  
  1928.    // do the transformation on the copy
  1929.    m_Lead3.Flip();
  1930.  
  1931.    m_Lead.SetRgnFrameType(RGNFRAME_NONE);
  1932.    hRegion = m_Lead3.GetRgnHandle();
  1933.    xCenter = m_Lead.GetRgnLeft() + m_Lead.GetRgnWidth() / 2;
  1934.    yCenter = m_Lead.GetRgnTop() + m_Lead.GetRgnHeight() / 2;
  1935.    /* the next two statements
  1936.    m_Lead.SetRgnHandle(hRegion,
  1937.       0, 
  1938.       0,
  1939.       L_RGN_SET);
  1940.    m_Lead.OffsetRgn(
  1941.       xCenter - m_Lead3.GetBitmapWidth() / 2, 
  1942.       yCenter - m_Lead3.GetBitmapHeight() / 2);
  1943.       do exactly the same thing as the following statement: */
  1944.    m_Lead.SetRgnHandle(hRegion,
  1945.       xCenter - m_Lead3.GetBitmapWidth() / 2, 
  1946.       yCenter - m_Lead3.GetBitmapHeight() / 2,
  1947.       L_RGN_SET);
  1948.    m_Lead.DeleteRgnHandle (hRegion);
  1949.    SaveBackground();
  1950.    m_Lead.Combine(
  1951.       xCenter - m_Lead3.GetBitmapWidth() / 2, 
  1952.       yCenter - m_Lead3.GetBitmapHeight() / 2, 
  1953.       m_Lead3.GetBitmapWidth(), 
  1954.       m_Lead3.GetBitmapHeight(), 
  1955.       m_Lead3.GetBitmap(), 
  1956.       0.0f, 
  1957.       0.0f, 
  1958.       L_SRC_COPY);
  1959.    m_Lead.RepaintRect(
  1960.       m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft(), 
  1961.       m_Lead.GetRgnTop() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstTop(), 
  1962.       m_Lead.GetRgnWidth() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  1963.       m_Lead.GetRgnHeight() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  1964.       FALSE);
  1965.    m_Lead.SetRgnFrameType(RGNFRAME_STATIC);
  1966.    m_Lead3.SetBitmap(0);
  1967.    m_Lead.SetAutoRepaint(TRUE);
  1968.  
  1969.  
  1970.    /* update the changes back into the master document and all other views */
  1971.    UpdateMasterDocument();
  1972.  
  1973.    SetCursor(hOldCursor);
  1974. }
  1975.  
  1976. void CMfcdemoView::OnImageRegiontransformationsResize() 
  1977. {
  1978.    CResizeDlg dlg;
  1979.  
  1980.    dlg.m_nWidth = (int) GetDocLead()->GetRgnWidth();
  1981.    dlg.m_nHeight = (int) GetDocLead()->GetRgnHeight();
  1982.    if(dlg.DoModal() == IDOK)
  1983.    {
  1984.       int nRet;
  1985.       long hRegion;
  1986.       float xCenter;
  1987.       float yCenter;
  1988.  
  1989.       HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
  1990.  
  1991.       m_Lead.SetAutoRepaint(FALSE);
  1992.       m_Lead.SetFloaterVisible(FALSE);
  1993.       m_Lead.SetFloater(m_Lead.GetBitmap());
  1994.       RestoreBackground();
  1995.       m_Lead3.SetBitmap(m_Lead.GetFloater());
  1996.       m_Lead.SetFloater(0);
  1997.  
  1998.       // do the transformation on the copy
  1999.       if(dlg.m_fResample)
  2000.          nRet = m_Lead3.Size((float) dlg.m_nWidth, (float) dlg.m_nHeight, RESIZE_RESAMPLE);
  2001.       else
  2002.          nRet = m_Lead3.Size((float) dlg.m_nWidth, (float) dlg.m_nHeight, RESIZE_NORMAL);
  2003.  
  2004.       m_Lead.SetRgnFrameType(RGNFRAME_NONE);
  2005.       hRegion = m_Lead3.GetRgnHandle();
  2006.       xCenter = m_Lead.GetRgnLeft() + m_Lead.GetRgnWidth() / 2;
  2007.       yCenter = m_Lead.GetRgnTop() + m_Lead.GetRgnHeight() / 2;
  2008.       m_Lead.SetRgnHandle(hRegion, 
  2009.          xCenter - m_Lead3.GetBitmapWidth() / 2, 
  2010.          yCenter - m_Lead3.GetBitmapHeight() / 2,
  2011.          L_RGN_SET);
  2012.       m_Lead.DeleteRgnHandle (hRegion);
  2013.       SaveBackground();
  2014.       m_Lead.Combine(
  2015.          xCenter - m_Lead3.GetBitmapWidth() / 2, 
  2016.          yCenter - m_Lead3.GetBitmapHeight() / 2, 
  2017.          m_Lead3.GetBitmapWidth(), 
  2018.          m_Lead3.GetBitmapHeight(), 
  2019.          m_Lead3.GetBitmap(), 
  2020.          0.0f, 
  2021.          0.0f, 
  2022.          L_SRC_COPY);
  2023.       m_Lead.RepaintRect(
  2024.          m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft(), 
  2025.          m_Lead.GetRgnTop() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstTop(), 
  2026.          m_Lead.GetRgnWidth() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  2027.          m_Lead.GetRgnHeight() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  2028.          FALSE);
  2029.       m_Lead.SetRgnFrameType(RGNFRAME_STATIC);
  2030.       m_Lead3.SetBitmap(0);
  2031.       m_Lead.SetAutoRepaint(TRUE);
  2032.  
  2033.       /* update the changes back into the master document and all other views */
  2034.       UpdateMasterDocument();
  2035.  
  2036.       SetCursor(hOldCursor);
  2037.    }
  2038. }
  2039.  
  2040. void CMfcdemoView::OnImageRegiontransformationsReverse() 
  2041. {
  2042.    long hRegion;
  2043.    float xCenter;
  2044.    float yCenter;
  2045.  
  2046.    HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
  2047.  
  2048.    m_Lead.SetAutoRepaint(FALSE);
  2049.    m_Lead.SetFloaterVisible(FALSE);
  2050.    m_Lead.SetFloater(m_Lead.GetBitmap());
  2051.    RestoreBackground();
  2052.    m_Lead3.SetBitmap(m_Lead.GetFloater());
  2053.    m_Lead.SetFloater(0);
  2054.  
  2055.    // do the transformation on the copy
  2056.    m_Lead3.Reverse();
  2057.  
  2058.    m_Lead.SetRgnFrameType(RGNFRAME_NONE);
  2059.    hRegion = m_Lead3.GetRgnHandle();
  2060.    xCenter = m_Lead.GetRgnLeft() + m_Lead.GetRgnWidth() / 2;
  2061.    yCenter = m_Lead.GetRgnTop() + m_Lead.GetRgnHeight() / 2;
  2062.    m_Lead.SetRgnHandle(hRegion, 
  2063.          xCenter - m_Lead3.GetBitmapWidth() / 2, 
  2064.          yCenter - m_Lead3.GetBitmapHeight() / 2,
  2065.       L_RGN_SET);
  2066.    m_Lead.DeleteRgnHandle (hRegion);
  2067.    SaveBackground();
  2068.    m_Lead.Combine(
  2069.       xCenter - m_Lead3.GetBitmapWidth() / 2, 
  2070.       yCenter - m_Lead3.GetBitmapHeight() / 2, 
  2071.       m_Lead3.GetBitmapWidth(), 
  2072.       m_Lead3.GetBitmapHeight(), 
  2073.       m_Lead3.GetBitmap(), 
  2074.       0.0f, 
  2075.       0.0f, 
  2076.       L_SRC_COPY);
  2077.    m_Lead.RepaintRect(
  2078.       m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft(), 
  2079.       m_Lead.GetRgnTop() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstTop(), 
  2080.       m_Lead.GetRgnWidth() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  2081.       m_Lead.GetRgnHeight() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  2082.       FALSE);
  2083.    m_Lead.SetRgnFrameType(RGNFRAME_STATIC);
  2084.    m_Lead3.SetBitmap(0);
  2085.    m_Lead.SetAutoRepaint(TRUE);
  2086.  
  2087.    /* update the changes back into the master document and all other views */
  2088.    UpdateMasterDocument();
  2089.  
  2090.    SetCursor(hOldCursor);
  2091. }
  2092.  
  2093. void CMfcdemoView::OnImageRegiontransformationsRotate()
  2094. {
  2095.    CLeadDlg LTCommDlg;
  2096.    RECT rcWin;
  2097.    BOOL bContinue=FALSE;
  2098.    int nRet;
  2099.  
  2100.    ::SetRect(&rcWin, 0, 0, 1, 1);
  2101.    
  2102.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  2103.    {
  2104.       LTCommDlg.SetEnableMethodErrors(FALSE);
  2105.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  2106.       LTCommDlg.SetBackColor(RGB(255,255,255));
  2107.       LTCommDlg.SetUIFlags( DLG_IMG_ROTATE );
  2108.       nRet = LTCommDlg.GetAngle((long)this->m_hWnd); /* the method */
  2109.       if(nRet == 0)
  2110.          bContinue = TRUE;
  2111.       LTCommDlg.SetBitmap(0);
  2112.    }
  2113.    if(bContinue)
  2114.    {
  2115.      OnImageRegiontransformationsRotate((long)LTCommDlg.GetAngle(),/* the property */
  2116.                                         LTCommDlg.GetAngleFlag() );
  2117.    }
  2118.    else if(nRet != ERROR_DLG_CANCELED)
  2119.       theApp.DisplayLEADError(nRet);
  2120. }
  2121.  
  2122. void CMfcdemoView::OnImageRegiontransformationsShear()
  2123. {
  2124.    CLeadDlg LTCommDlg;
  2125.    RECT rcWin;
  2126.    BOOL bContinue=FALSE;
  2127.    int nRet;
  2128.  
  2129.    ::SetRect(&rcWin, 0, 0, 1, 1);
  2130.    
  2131.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  2132.    {
  2133.       LTCommDlg.SetEnableMethodErrors(FALSE);
  2134.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  2135.       LTCommDlg.SetBackColor(RGB(255,255,255));
  2136.       LTCommDlg.SetUIFlags( DLG_IMG_SHEAR );
  2137.       nRet = LTCommDlg.GetAngle((long)this->m_hWnd); /* the method */
  2138.       if(nRet == 0)
  2139.          bContinue = TRUE;
  2140.       //release the reference
  2141.       LTCommDlg.SetBitmap(0);
  2142.    }
  2143.    if(bContinue)
  2144.    {
  2145.      OnImageRegiontransformationsShear((long)LTCommDlg.GetAngle(),/* the property */
  2146.                                         LTCommDlg.GetAngleFlag() );
  2147.    }
  2148.    else if(nRet != ERROR_DLG_CANCELED)
  2149.       theApp.DisplayLEADError(nRet);
  2150. }
  2151.  
  2152.  
  2153. void CMfcdemoView::OnImageRegiontransformationsRotate(long nAngle, BOOL fResize) 
  2154. {
  2155.     long hRegion;
  2156.     float xCenter;
  2157.     float yCenter;
  2158.  
  2159.     HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
  2160.  
  2161.     m_Lead.SetAutoRepaint(FALSE);
  2162.     m_Lead.SetFloaterVisible(FALSE);
  2163.     m_Lead.SetFloater(m_Lead.GetBitmap());
  2164.     RestoreBackground();
  2165.     m_Lead3.SetBitmap(m_Lead.GetFloater());
  2166.     m_Lead.SetFloater(0);
  2167.  
  2168.     // do the transformation on the copy
  2169.     m_Lead3.Rotate(nAngle, fResize, RGB(255, 255, 255));
  2170.  
  2171.     m_Lead.SetRgnFrameType(RGNFRAME_NONE);
  2172.     hRegion = m_Lead3.GetRgnHandle();
  2173.     xCenter = m_Lead.GetRgnLeft() + m_Lead.GetRgnWidth() / 2;
  2174.     yCenter = m_Lead.GetRgnTop() + m_Lead.GetRgnHeight() / 2;
  2175.     m_Lead.SetRgnHandle(hRegion, 
  2176.        xCenter - m_Lead3.GetBitmapWidth() / 2, 
  2177.        yCenter - m_Lead3.GetBitmapHeight() / 2,
  2178.        L_RGN_SET);
  2179.     m_Lead.DeleteRgnHandle (hRegion);
  2180.     SaveBackground();
  2181.     m_Lead.Combine(
  2182.        xCenter - m_Lead3.GetBitmapWidth() / 2, 
  2183.        yCenter - m_Lead3.GetBitmapHeight() / 2, 
  2184.        m_Lead3.GetBitmapWidth(), 
  2185.        m_Lead3.GetBitmapHeight(), 
  2186.        m_Lead3.GetBitmap(), 
  2187.        0.0f, 
  2188.        0.0f, 
  2189.        L_SRC_COPY);
  2190.     m_Lead.RepaintRect(
  2191.        m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft(), 
  2192.        m_Lead.GetRgnTop() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstTop(), 
  2193.        m_Lead.GetRgnWidth() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  2194.        m_Lead.GetRgnHeight() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  2195.        FALSE);
  2196.     m_Lead.SetRgnFrameType(RGNFRAME_STATIC);
  2197.     m_Lead3.SetBitmap(0);
  2198.  
  2199.     m_Lead.SetAutoRepaint(TRUE);
  2200.     /* update the changes back into the master document and all other views */
  2201.     UpdateMasterDocument();
  2202.  
  2203.     SetCursor(hOldCursor);
  2204. }
  2205.  
  2206. void CMfcdemoView::OnImageRegiontransformationsShear(long nAngle, BOOL fResize) 
  2207. {
  2208.     long hRegion;
  2209.     float xCenter;
  2210.     float yCenter;
  2211.  
  2212.     HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
  2213.  
  2214.     m_Lead.SetAutoRepaint(FALSE);
  2215.     m_Lead.SetFloaterVisible(FALSE);
  2216.     m_Lead.SetFloater(m_Lead.GetBitmap());
  2217.     RestoreBackground();
  2218.     m_Lead3.SetBitmap(m_Lead.GetFloater());
  2219.     m_Lead.SetFloater(0);
  2220.  
  2221.     // do the transformation on the copy
  2222.     m_Lead3.Shear((short)nAngle, fResize, RGB(255, 255, 255));
  2223.  
  2224.     m_Lead.SetRgnFrameType(RGNFRAME_NONE);
  2225.     hRegion = m_Lead3.GetRgnHandle();
  2226.     xCenter = m_Lead.GetRgnLeft() + m_Lead.GetRgnWidth() / 2;
  2227.     yCenter = m_Lead.GetRgnTop() + m_Lead.GetRgnHeight() / 2;
  2228.     m_Lead.SetRgnHandle(hRegion, 
  2229.        xCenter - m_Lead3.GetBitmapWidth() / 2, 
  2230.        yCenter - m_Lead3.GetBitmapHeight() / 2,
  2231.        L_RGN_SET);
  2232.     m_Lead.DeleteRgnHandle (hRegion);
  2233.     SaveBackground();
  2234.     m_Lead.Combine(
  2235.        xCenter - m_Lead3.GetBitmapWidth() / 2, 
  2236.        yCenter - m_Lead3.GetBitmapHeight() / 2, 
  2237.        m_Lead3.GetBitmapWidth(), 
  2238.        m_Lead3.GetBitmapHeight(), 
  2239.        m_Lead3.GetBitmap(), 
  2240.        0.0f, 
  2241.        0.0f, 
  2242.        L_SRC_COPY);
  2243.     m_Lead.RepaintRect(
  2244.        m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft(), 
  2245.        m_Lead.GetRgnTop() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstTop(), 
  2246.        m_Lead.GetRgnWidth() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  2247.        m_Lead.GetRgnHeight() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(), 
  2248.        FALSE);
  2249.     m_Lead.SetRgnFrameType(RGNFRAME_STATIC);
  2250.     m_Lead3.SetBitmap(0);
  2251.  
  2252.     m_Lead.SetAutoRepaint(TRUE);
  2253.     /* update the changes back into the master document and all other views */
  2254.     UpdateMasterDocument();
  2255.  
  2256.     SetCursor(hOldCursor);
  2257. }
  2258.  
  2259. void CMfcdemoView::UpdateMasterDocument() 
  2260. {
  2261.    /* merge the changes back into the master document */
  2262.    long hRegion = m_Lead.GetRgnHandle();
  2263.    GetDocLead()->SetBitmap(m_Lead.GetBitmap());
  2264.    GetDocLead()->SetRgnHandle(hRegion,0.0f,0.0f,L_RGN_SET);
  2265.    m_Lead.DeleteRgnHandle(hRegion);
  2266.    GetDocument()->UpdateAllViews(this, (LPARAM)0);
  2267. }
  2268.  
  2269. void CMfcdemoView::SaveBackground() 
  2270. {
  2271.    GetDocument()->m_Lead2.CreateBitmap(m_Lead.GetRgnWidth(), m_Lead.GetRgnHeight(), m_Lead.GetBitmapBits());
  2272.    if((m_Lead.GetIsGrayscale() != GRAY_NO) && (m_Lead.GetBitmapBits()>8))
  2273.       GetDocument()->m_Lead2.Grayscale(m_Lead.GetBitmapBits());
  2274.  
  2275.    GetDocument()->m_Lead2.Combine(
  2276.       0.0f, 0.0f, 
  2277.       m_Lead.GetRgnWidth(), m_Lead.GetRgnHeight(), 
  2278.       m_Lead.GetBitmap(), 
  2279.       m_Lead.GetRgnLeft(), m_Lead.GetRgnTop(), 
  2280.       L_SRC_COPY);
  2281. }
  2282.  
  2283. void CMfcdemoView::RestoreBackground() 
  2284. {
  2285.    if(GetDocument()->m_Lead2.GetBitmap())
  2286.       m_Lead.Combine(
  2287.          m_Lead.GetRgnLeft(), 
  2288.          m_Lead.GetRgnTop(), 
  2289.          m_Lead.GetRgnWidth(), 
  2290.          m_Lead.GetRgnHeight(), 
  2291.          GetDocument()->m_Lead2.GetBitmap(), 
  2292.          0.0f, 
  2293.          0.0f, 
  2294.          L_SRC_COPY);
  2295. }
  2296.  
  2297. void CMfcdemoView::OnUpdateImageRegiontransformationsCancel(CCmdUI* pCmdUI) 
  2298. {
  2299.     pCmdUI->Enable(m_Lead.GetHasRgn());
  2300. }
  2301.  
  2302. void CMfcdemoView::OnImageRegiontransformationsCancel() 
  2303. {
  2304.    HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
  2305.  
  2306.    RestoreBackground();
  2307.  
  2308.    /* delete the regions from the master document and all other views */
  2309.    m_Lead.SetRgnFrameType(RGNFRAME_NONE);
  2310.    m_Lead.FreeRgn();
  2311.  
  2312.    GetDocLead()->SetBitmap(m_Lead.GetBitmap());
  2313.    GetDocLead()->FreeRgn();
  2314.    GetDocument()->UpdateAllViews(this, (LPARAM)0);
  2315.  
  2316.    SetCursor(hOldCursor);
  2317. }
  2318.  
  2319. void CMfcdemoView::OnColorWindowlevel() 
  2320. {
  2321.    CLeadDlg LTCommDlg;
  2322.    RECT rcWin;
  2323.    BOOL bContinue=FALSE;
  2324.    unsigned int uMid;
  2325.    int nRet;
  2326.    unsigned int uVal;
  2327.  
  2328.    ::SetRect(&rcWin, 0, 0, 1, 1);
  2329.    
  2330.    if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
  2331.    {
  2332.       LTCommDlg.SetEnableMethodErrors(FALSE);
  2333.       GetDocLead()->GetMinMaxBits();
  2334.       GetDocLead()->GetMinMaxVal();
  2335.       LTCommDlg.SetLowBit(GetDocLead()->GetMinBit());
  2336.       LTCommDlg.SetHighBit(GetDocLead()->GetMaxBit());
  2337.  
  2338.       // now, let's set the range to somewhere in the middle
  2339.       uMid = (GetDocLead()->GetMinVal() + GetDocLead()->GetMaxVal())/2;
  2340.  
  2341.       uVal = (unsigned short)(uMid * 9 / 10);
  2342.       LTCommDlg.SetLowLevel(uVal);
  2343.       uVal = (unsigned short)(uMid + (uMid - uVal));
  2344.       LTCommDlg.SetHighLevel(uVal);
  2345.  
  2346.          //assign the bitmap for preview
  2347.       LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
  2348.       LTCommDlg.SetUIFlags(DLG_WL_SHOWPREVIEW | DLG_WL_AUTOPROCESS);
  2349.       nRet = LTCommDlg.GetWindowLevel((long)this->m_hWnd);
  2350.       if(nRet == 0)
  2351.          bContinue = TRUE;
  2352.       //release the reference
  2353.       LTCommDlg.SetBitmap(0);
  2354.    }
  2355.    if(bContinue)
  2356.    {
  2357.       OnChanged();
  2358.       GetDocLead()->ForceRepaint();
  2359.    }
  2360.    else if(nRet != ERROR_DLG_CANCELED)
  2361.       theApp.DisplayLEADError(nRet);
  2362. }
  2363.  
  2364. void CMfcdemoView::OnUpdateColorWindowlevel(CCmdUI* pCmdUI) 
  2365. {
  2366.    BOOL bVal;
  2367.  
  2368.    bVal = FALSE;
  2369.    if((GetDocLead()->GetBitmapBits() == 12) || (GetDocLead()->GetBitmapBits() == 16))
  2370.       bVal = TRUE;
  2371.    if(GetDocLead()->GetIsGrayscale() == GRAY_NO)
  2372.       bVal = FALSE;
  2373.    pCmdUI->Enable(bVal);
  2374. }
  2375.