Using Class Library DigitalPaint Tools

Take the following steps to start a project and to add some code that creates a new paint window.

Note:

This example is for a 32-bit (NT or Windows 9x) environment.

Step 1

1.

Start Visual C++, version 5.

2.

Select the File->New menu option, click the "projects" tab.

3.

Select "MFC AppWizard".

4.

In the Project Name dialog box, enter "Tutorial".

5.

In the Location dialog box, use the examples\classlib\msvc5 directory of your LEAD installation. For example, if you installed LEADTOOLS in c:\ltwin14x, enter c:\ltwin14x\examples\classlib\msvc5\ Click OK.

6.

Choose Multiple Document and click "Next".

7.

The "MFC AppWizard step 2 of 6", appears. Keep the default settings and press the "Next" Button.

8.

The "MFC AppWizard step 3 of 6", appears. Keep the default settings and press the "Next" Button.

9.

The "MFC AppWizard step 4 of 6", appears. Uncheck the "Docking Toolbar" combo box.

10.

Uncheck the "Printing and print preview" combo box and press the "Finish" Button.

Step 2

1.

Choose Project->Settings.

2.

In the "Settings For" drop down box, choose "All Configurations".

3.

Click on the C/C++ tab.

4.

In the "Category" drop down box, choose "Preprocessor".

5.

In the "Additional include directories" dialog box, enter the include\classlib directory of your LEAD installation. For example, if you installed LEADTOOSL in c:\ltwin14x, enter c:\ltiwn14x\include\classlib then Press OK.

6.

Open the Stdafx.h file from the "File View" tab.

7.

Add the following lines before the "//{{AFX_INSERT_LOCATION}}" comment:

#include "ltwrappr.h"
class CTutorialApp;
class CTutorialView;
class CTutorialDoc;
#include "TutorialDoc.h"
#include "TutorialView.h"

 

The stdafx.h file should be something like this:

// stdafx.h : include file for standard system include files,
//  or project specific include files that are used frequently, but
//      are changed infrequently
//
#if !defined(AFX_STDAFX_H__47B5950A_21D9_11D5_8F4C_0060087C0C73__INCLUDED_)
#define AFX_STDAFX_H__47B5950A_21D9_11D5_8F4C_0060087C0C73__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#define VC_EXTRALEAN                        // Exclude rarely-used stuff from Windows headers
#include <afxwin.h>                                   // MFC core and standard components
#include <afxext.h>                                    // MFC extensions
#include <afxdisp.h>                                  // MFC OLE automation classes
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>                                 // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

#include "ltwrappr.h"
class CTutorialApp;
class CTutorialView;
class CTutorialDoc;

#include "TutorialDoc.h"
#include "TutorialView.h"
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__47B5950A_21D9_11D5_8F4C_0060087C0C73__INCLUDED_)

Step 3

1.

Click on the "Class View" tab.

2.

Click to open the Tutorial Classes branch.

3.

Click "CTutorialApp", and then double click the CTutorialApp() constructor.

4.

Add the following lines after "//TODO: add construction code here":

 LBase::LoadLibraries(LT_PDG|LT_KRN|LT_FIL|LT_DLG|LT_AUT|LT_CON|LT_TLB|LT_DIS);
L_UNLOCKSUPPORT(L_SUPPORT_GIFLZW, L_KEY_GIFLZW); 
L_UNLOCKSUPPORT(L_SUPPORT_TIFLZW, L_KEY_TIFLZW); 
L_UNLOCKSUPPORT(L_SUPPORT_DIGITALPAINT, L_KEY_DIGITALPAINT); 

 

The function should be something like this:

CTutorialApp::CTutorialApp()
{
   // TODO: add construction code here,
   // Place all significant initialization in InitInstance
    LBase::LoadLibraries(LT_PDG|LT_KRN|LT_FIL|LT_DLG|LT_AUT|LT_CON|LT_TLB|LT_DIS);
   L_UNLOCKSUPPORT(L_SUPPORT_GIFLZW, L_KEY_GIFLZW); 
   L_UNLOCKSUPPORT(L_SUPPORT_TIFLZW, L_KEY_TIFLZW); 
   L_UNLOCKSUPPORT(L_SUPPORT_DIGITALPAINT, L_KEY_DIGITALPAINT);
}

5.

Click on the "Class View" tab.

6.

Click to open the Tutorial Classes branch.

7.

Right click on "CTutorialApp", and select "Add Member Function&&quot;.

8.

In the Add Member Function Dialog, write "~CTutorialApp( );" on the Function Declaration text box and then press OK.

9.

Add the following lines inside the generated function":

   LBase::UnloadLibraries(LT_PDG|LT_KRN|LT_FIL|LT_DLG|LT_AUT|LT_CON|LT_TLB|LT_DIS);

 

The function should be something like this:

CTutorialApp::~CTutorialApp()
{
   LBase::UnloadLibraries(LT_PDG|LT_KRN|LT_FIL|LT_DLG|LT_AUT|LT_CON|LT_TLB|LT_DIS);
}

Step 4

1.

Click on the "Class View" tab.

2.

Click to open the Tutorial Classes branch.

3.

Click "CTutorialApp", and then double click the InitInstance() function.

4.

Add the following lines after the call to the ParseCommandLine function:

//Hide the Auto appearance window (View)
   cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;

 

The function should be something like this:

BOOL CTutorialApp::InitInstance()
{
   AfxEnableControlContainer();
   // Standard initialization
   // If you are not using these features and wish to reduce the size
   //  of your final executable, you should remove from the following
   //  the specific initialization routines you do not need.

#ifdef _AFXDLL
   Enable3dControls();         // Call this when using MFC in a shared DLL
#else
   Enable3dControlsStatic();     // Call this when linking to MFC statically
#endif

   // Change the registry key under which our settings are stored.
   // You should modify this string to be something appropriate
   // such as the name of your company or organization.
   SetRegistryKey(_T("Local AppWizard-Generated Applications"));
   LoadStdProfileSettings();  // Load standard INI file options (including MRU)
   // Register the application's document templates.  Document templates
   //  serve as the connection between documents, frame windows and views.
   CMultiDocTemplate* pDocTemplate;
   pDocTemplate = new CMultiDocTemplate(
   IDR_TUTORITYPE,
   RUNTIME_CLASS(CTutorialDoc),
   RUNTIME_CLASS(CChildFrame), // custom MDI child frame
   RUNTIME_CLASS(CTutorialView));
   AddDocTemplate(pDocTemplate);
   // create main MDI Frame window
   CMainFrame* pMainFrame = new CMainFrame;
   if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
      return FALSE;
   m_pMainWnd = pMainFrame;
   // Parse command line for standard shell commands, DDE, file open
   CCommandLineInfo cmdInfo;
   ParseCommandLine(cmdInfo);
   
   //Hide the Auto appearance window (View)
   cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;

   // Dispatch commands specified on the command line
   if (!ProcessShellCommand(cmdInfo))
      return FALSE;

   // The main window has been initialized, so show and update it.
   pMainFrame->ShowWindow(m_nCmdShow);
   pMainFrame->UpdateWindow();
   return TRUE;
}

Step 5

Select Project->Add To Project->Files... and browse to <your LEAD installation directory>\lib\ltwvc_n.lib.

Step 6

1.

Click on the "Class View" tab.

2.

Right click "CTutorialView" and select "Add Member Variable..."

3.

For Variable Type enter LRasterPaintWindow, and for Variable Declaration put m_RasterPntWnd. Leave Access as "Public" and click OK.

4.

Right click "CTutorialView" again and select "Add Member Variable..."

5.

For Variable Type enter LRasterDialog, and for Variable Declaration put m_PaintDialog leave Access as "Public" and click OK.

 

The Class declaration should be something like this:

class CTutorialView : public Cview
{
protected: // create from serialization only
   CTutorialView();
   DECLARE_DYNCREATE(CTutorialView)
// Attributes
public:
   CRstDemoDoc*   GetDocument();
// Operations
public:
   LRasterPaintWindow  m_RasterPntWnd;
   LRasterDialog                 m_PaintDialog;

//  Rest of class stuff goes here
}

Step 7

1.

Click on the "Class View" tab.

2.

Right click "CTutorialView" and select "Add Windows Message Handler..."

3.

Select "WM_CREATE" from "New Windows messages/events" list and click "Add and Edit" button.

4.

Add the following line of code before the " return 0;" line:

m_RasterPntWnd.SetWndHandle(m_hWnd);

 

The function should be something like this:

int CTutorialView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
   if(CView::OnCreate(lpCreateStruct) == -1)
       return -1;

    m_RasterPntWnd. SetWndHandle (m_hWnd);

    return 0;
}

Step 8

1.

Click on the "Class View" tab.

2.

Click to open the Tutorial Classes branch.

3.

Click "CMainFrame", and then double click the "OnCreate" function.

4.

Add the following lines before the last "return 0;" line:

LRasterPaintWindow::Initialize();
LRasterPaintWindow::CreateToolbar
(&m_LToolbar, m_hWnd, TEXT("Test Toolbar"));
LRasterPaintWindow::SetToolbar
(&m_LToolbar);

POINT ptPos = {0, 0};
RECT  rcClient; 
CMainFrame::GetClientRect(&rcClient);
ptPos.x = rcClient.left + 2;
ptPos.y = rcClient.top + 2;
CMainFrame::ClientToScreen(&ptPos);
LRasterPaintWindow::SetToolbarPosition
(&ptPos);
LRasterPaintWindow::ShowToolbar
(TRUE);

The function should be something like this
:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
   if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
      return -1;

   if (!m_wndStatusBar.Create(this) ||
   !m_wndStatusBar.SetIndicators(indicators,
     sizeof(indicators)/sizeof(UINT)))
   {
        TRACE0(TEXT("Failed to create status bar\n"));
        return -1;      // fail to create
   }

   LRasterPaintWindow::Initialize();
   LRasterPaintWindow::CreateToolbar(&m_LToolbar, m_hWnd, TEXT("Test Toolbar"));
   LRasterPaintWindow::SetToolbar(&m_LToolbar);

   POINT ptPos = {0, 0};
   RECT  rcClient; 
   CMainFrame::GetClientRect(&rcClient);
   ptPos.x = rcClient.left + 2;
   ptPos.y = rcClient.top + 2;
   CMainFrame::ClientToScreen(&ptPos);
   LRasterPaintWindow::SetToolbarPosition(&ptPos);
   LRasterPaintWindow::ShowToolbar(TRUE);

   return 0;
}

Step 9

1.

Click on the "Class View" tab.

2.

Right click "CMainFrame" and select "Add Windows Message Handler..."

3.

Select "WM_CLOSE" from "New Windows messages/events" list and click "Add and Edit" button.

4.

Add the following line of code before the call to " CMDIFrameWnd::OnClose" function:

LRasterPaintWindow::FreeToolbar (&m_LToolbar);
LRasterPaintWindow::Free
 ();

 

The function should be something like this:

void CMainFrame::OnClose() 
{
   LRasterPaintWindow::FreeToolbar (&m_LToolbar);
   LRasterPaintWindow::Free();
   
   CMDIFrameWnd::OnClose();
}

Step 10

1.

Click on the "Class View" tab.

2.

Right click "CMainFrame" and select "Add Member Variable..."

3.

For Variable Type enter LToolbar, and for Variable Declaration put m_LToolbar.

4.

Select Access as "Protected" and click OK.

 

The Class declaration should be something like this:

class CMainFrame : public CMDIFrameWnd
{
   DECLARE_DYNAMIC(CMainFrame)
public:
   CMainFrame();
// Attributes
public:
// Operations
public:
// Overrides
   // ClassWizard generated virtual function overrides
   //{{AFX_VIRTUAL(CMainFrame)
   public:
   virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
   //}}AFX_VIRTUAL
// Implementation
public:
   virtual ~CMainFrame();
#ifdef _DEBUG
   virtual void AssertValid() const;
   virtual void Dump(CDumpContext& dc) const;
#endif
protected:  // control bar embedded members
   CStatusBar           m_wndStatusBar;
// Generated message map functions
protected:
   LToolbar m_LToolbar;
   // rest of  stuff goes here
   }

Step 11

Handle Save & Update UI for it

1.

Click on the "Class View" tab.

2.

Right click "CTutorialView" and select "Add Windows Message Handler..."

3.

Select "ID_FILE_SAVE" from "Class or object to handle" list

4.

Select "COMMAND" from "New Windows messages/events" list and click "Add and Edit" button.

5.

The "Add Member Function" Dialog appears, write "OnFileSave" as the "Member function name", press OK.

 

Add the following lines of code after the "// TODO" comment line:

 LBitmapBase* pLBtmpbase = m_RasterPntWnd.GetBitmap ();

   BOOL bFlag = AfxGetMainWnd()->EnableWindow(FALSE);   

  pLBtmpbase->Dialog()->EnableAutoProcess (TRUE);
   L_INT nRetCode = pLBtmpbase->Dialog()->DoModalFileSave;
   
   if(nRetCode!=SUCCESS && nRetCode!=ERROR_DLG_CANCELED)
         MessageBox(NULL, TEXT("Can't save to file. See if file is read only."), TEXT("File Save Error")), 
B_ICONWARNING | MB_OK);  

   bFlag = AfxGetMainWnd()->EnableWindow(TRUE);
   AfxGetMainWnd()->SetActiveWindow();

 The function should be like this:

void CTutorialView::OnFileSave() 
{
// TODO: Add your command handler code here   
   LBitmapBase* pLBtmpbase = m_RasterPntWnd.GetBitmap();

   BOOL bFlag = AfxGetMainWnd()->EnableWindow(FALSE);   
   pLBtmpbase->Dialog()->EnableAutoProcess(TRUE);
   L_INT nRetCode = pLBtmpbase->Dialog()->DoModalFileSave();

   if(nRetCode!=SUCCESS && nRetCode!=ERROR_DLG_CANCELED)
      MessageBox(NULL, TEXT("Can't save to file. See if file is read only."), TEXT("File Save Error"), MB_ICONWARNING | MB_OK);
   
   bFlag = AfxGetMainWnd()->EnableWindow(TRUE);
   AfxGetMainWnd()->SetActiveWindow();
 }

Step 12

1.

Click on the "Class View" tab.

2.

Right click "CTutorialView" and select "Add Windows Message Handler..."

3.

Select "ID_FILE_SAVE" from "Class or object to handle" list

4.

Select "UPDATE_COMMAND_UI" from "New Windows messages/events" and click "Add and Edit" button.

5.

The "Add Member Function" Dialog appears, write " OnUpdateFileSave" as the "Member function name", press OK.

6.

Add the following lines of code after the "// TODO" comment line:

pCmdUI->Enable(m_RasterPntWnd. GetBitmap ()->IsAllocated());

The function should be like this:

void CTutorialView::OnUpdateFileSave(CCmdUI* pCmdUI) 
{
   // TODO: Add your command update UI handler code here
   pCmdUI->Enable(m_RasterPntWnd. GetBitmap ()->IsAllocated());
}

Step 13

Handle Open & Update UI for it

1.

Click on the "Class View" tab.

2.

Right click "CTutorialApp" and select "Add Windows Message Handler..."

3.

Select "ID_FILE_OPEN" from "Class or object to handle" list

4.

Select "COMMAND" from "New Windows messages/events" list and click "Add and Edit" button.

5.

The "Add Member Function" Dialog appear, write "OnFileOpen" as the "Member function name", press OK.

6.

Add the following lines of code after the "// TODO" comment line:

POSITION pos = GetFirstDocTemplatePosition();
CDocTemplate* pDocTemplate = GetNextDocTemplate(pos);
pDocTemplate->OpenDocumentFile((LPCTSTR)NULL);

The function should be like this:

void CTutorialApp::OnFileOpen() 
{
   // TODO: Add your command handler code here
   POSITION pos = GetFirstDocTemplatePosition();
   CDocTemplate* pDocTemplate = GetNextDocTemplate(pos);
   pDocTemplate->OpenDocumentFile((LPCTSTR)NULL);
}

Step 14

1.

Click on the "Class View" tab.

2.

Click to open the "Tutorial Classes" branch.

3.

Click on the "CTutorialDoc" to expand the functions branch.

4.

Double click on the "OnNewDocument" function to view the code.

5.

Place the following code after the // TODO: add reinitialization code here

   POSITION        pos   =   GetFirstViewPosition();
   CTutorialView*   pView = (CTutorialView*) GetNextView(pos);

   L_TCHAR szTitle[200] = "[ ";
   L_TCHAR szBuff[56];      /* file name */

   LBitmapBase LBtmpbase;

   BOOL bFlag = AfxGetMainWnd()->EnableWindow(FALSE);
   
   LBtmpbase.Dialog()->EnableAutoProcess (TRUE);
      
   if(LBtmpbase.Dialog()->DoModalFileOpen () == SUCCESS)
   {
      FILEOPENPARM FileParam;

      LBtmpbase.Dialog()->GetFileOpenParameters (&FileParam);

      L_INT nBitsPerPixel = FileParam.pBitmap->BitsPerPixel;

      if (nBitsPerPixel != 1 && nBitsPerPixel != 4) 
         if(nBitsPerPixel != 8 && nBitsPerPixel != 16 && nBitsPerPixel != 24)
         {
               pView->MessageBox(NULL, TEXT("Your image format is not 1,4,8,16 or 24 bits per pixel"), TEXT("Error Opening Image"), MB_ICONWARNING | MB_OK);

            bFlag  = AfxGetMainWnd()->EnableWindow(TRUE);
            AfxGetMainWnd()->SetActiveWindow();

            return FALSE;
         }

      L_INT nRetCode = pView->m_RasterPntWnd.SetBitmap(&LBtmpbase);

      if (nRetCode == SUCCESS) 
      {
         LBtmpbase.Dialog()->GetFileName (szBuff, sizeof(szBuff));

         lstrcat(szTitle, szBuff);
         lstrcat(szTitle, TEXT(" ]"));

         SetTitle(szTitle);

         bFlag  = AfxGetMainWnd()->EnableWindow(TRUE);
         AfxGetMainWnd()->SetActiveWindow();
         return TRUE;
      }
      
      pView->MessageBox(NULL, TEXT("Not Supported Format"), TEXT("Error Opening Image "), MB_ICONWARNING | MB_OK);
   }

   bFlag  = AfxGetMainWnd()->EnableWindow(TRUE);
   AfxGetMainWnd()->SetActiveWindow();
   return FALSE;

The function should be like this:

BOOL CTutorialDoc::OnNewDocument()
{
   if (!CDocument::OnNewDocument())
      return FALSE;

   // TODO: add reinitialization code here
   // (SDI documents will reuse this document)

// TODO: Add your command handler code here
   POSITION        pos   =   GetFirstViewPosition();
   CTutorialView*   pView = (CTutorialView*) GetNextView(pos);

   L_TCHAR szTitle[200] = "[ ";
   L_TCHAR szBuff[56];      /* file name */

   LBitmapBase LBtmpbase;

   BOOL bFlag = AfxGetMainWnd()->EnableWindow(FALSE);
   
   LBtmpbase.Dialog()->EnableAutoProcess (TRUE);
   
   
   if(LBtmpbase.Dialog()->DoModalFileOpen () == SUCCESS)
   {
      FILEOPENPARM FileParam;

      LBtmpbase.Dialog()->GetFileOpenParameters (&FileParam);

      L_INT nBitsPerPixel = FileParam.pBitmap->BitsPerPixel;

      if (nBitsPerPixel != 1 && nBitsPerPixel != 4) 
         if(nBitsPerPixel != 8 && nBitsPerPixel != 16 && nBitsPerPixel != 24)
         {
               pView->MessageBox(NULL, TEXT("Your image format is not 1,4,8,16 or 24 bits per pixel"), TEXT("Error Opening Image"), MB_ICONWARNING | MB_OK);

            bFlag  = AfxGetMainWnd()->EnableWindow(TRUE);
            AfxGetMainWnd()->SetActiveWindow();

            return FALSE;
         }
         
      L_INT nRetCode = pView->m_RasterPntWnd.SetBitmap (&LBtmpbase);

      if (nRetCode == SUCCESS) 
      {

         LBtmpbase.Dialog()->GetFileName (szBuff, sizeof(szBuff));

         lstrcat(szTitle, szBuff);
         lstrcat(szTitle, TEXT(" ]"));

         SetTitle(szTitle);

         bFlag  = AfxGetMainWnd()->EnableWindow(TRUE);
         AfxGetMainWnd()->SetActiveWindow();
         return TRUE;
      }

      pView->MessageBox(NULL, TEXT("Non-Supported Format"), TEXT("Error Opening Image "), MB_ICONWARNING | MB_OK);
   }

   bFlag  = AfxGetMainWnd()->EnableWindow(TRUE);
   AfxGetMainWnd()->SetActiveWindow();

   return FALSE;
}

Step 15

Delete Save As menu Item

Delete New Menu Item

Delete Resent Files Menu Item

1.

Move to the "Resource View" tab.

2.

Double click the "Tutorial resources" to expand the branch.

3.

Double click the "Menu" item from the tree to show the available menus.

4.

Double click on the "IDR_MAINFRAME" item to view the menu.

5.

Select "File"à"New" form the displayed menu bar and press the "Del" key to delete this menu item.

6.

Do the same with the "Recent File" and the Separator menu items.

7.

Now double click on the "IDR_TUTORITYPE" item from the "Resource View" tab to view this menu.

8.

Delete the "Save As", "Recent File" and the Separator menu items from the "File" menu as we did in step (5).

Step 16

Handling Palette Changes

1.

Open the "Tutorial.h" file from the "File View" tab.

2.

Add this define statement after the "#include "resource.h" // main symbols" statement

   #define WM_HANDLEPALETTE WM_APP + 0

3.

Click on the "Class View" tab.

4.

Right click "CMainFrame" and select "Add Windows Message Handler..."

5.

Select "WM_PALETTECHANGED" from "New Windows messages/events" list and click "Add and Edit" button.

6.

Add the following lines of code after the " CMDIFrameWnd::OnPaletteChanged(pFocusWnd); " line:

    if(pFocusWnd!=NULL)
         SendMessageToDescendants(WM_HANDLEPALETTE,(WPARAM)pFocusWnd ->m_hWnd, TRUE);

7.

Right click "CMainFrame" and select "Add Windows Message Handler..."

8.

Select "WM_QUERYNEWPALETTE" from "New Windows messages/events" list and click "Add and Edit" button.

9.

Replace the "return CMDIFrameWnd::OnQueryNewPalette();" statement with the following lines of code:

CMDIChildWnd* pMDIChildWnd = MDIGetActive();

   if (pMDIChildWnd!=NULL)
   {
      CView* pView = pMDIChildWnd->GetActiveView();

      if(pView!=NULL)
      {
         pView->SendMessage(WM_HANDLEPALETTE,0,FALSE);
         return TRUE;
      }
   }
   return FALSE;

10.

Right click "CMainFrame" and select "Add Windows Message Handler..."

11.

Select "WM_SYSCOLORCHANGE" from "New Windows messages/events" list and click "Add and Edit" button.

12.

Replace the "CMDIFrameWnd::OnSysColorChange();" statement with the following line of code which actually calls the OnQueryNewPalette() function:

OnQueryNewPalette();

The function should look like this:
void CMainFrame::OnSysColorChange() 
{
   OnQueryNewPalette();   
}

13.

Select "View àClass Wizard".

14.

Select the "CTutorialView" from the "Class name" dropdown list.

15.

Select the "CTutorialView" from the "Object IDs" list.

16.

Select the "OnActivateView" from the "Messages" list and press the "Add Function" button, then press the "Edit Code" button.

17.

Write the following lines of code after the "// TODO: Add your specialized code here and/or call the base class" statement:

if(bActivate==TRUE&&pActivateView==this)
m_RasterPntWnd.HandlePalette (WM_QUERYNEWPALETTE,0,0);

18.

Open the "TutorialView.h" file from the "File View" tab and add the following line before the DECLARE_MESSAGE_MAP() statement:

afx_msg LRESULT OnHandlePalette(WPARAM wParam, LPARAM lParam);  

19.

Open the "TutorialView.cpp" file from the "File View" tab and add the following line before the END_MESSAGE_MAP() statement:

ON_MESSAGE(WM_HANDLEPALETTE,OnHandlePalette)

20.

Now add the following lines of code to the end of the "TutorialView.cpp" file:

LRESULT CTutorialView::OnHandlePalette(WPARAM wParam, LPARAM lParam)
{
   if(lParam==TRUE)
   {
      if(m_RasterPntWnd.HandlePalett (WM_PALETTECHANGED, wParam, 0)==FALSE)
        m_RasterPntWnd.Repaint();
   }
   else 
   {
      if(m_RasterPntWnd.HandlePalette(WM_QUERYNEWPALETTE, 0, 0)==FALSE)
         m_RasterPntWnd.Repaint();
   }

   return TRUE;
}

Step 17

Show / Hide the Tool bar

1.

Move to the "Resource View" tab.

2.

Double click the "Tutorial resources" to expand the branch.

3.

Double click the "Menu" item from the tree to show the available menus.

4.

Double click on the "IDR_MAINFRAME" item to view the menu.

5.

Press on the "View" menu to view the menu items.

6.

You will notice that there is only one menu item, which is the "Status Bar", and there is an empty menu item below the previous mentioned menu item.

7.

Right click on this menu item and select "Properties".

8.

In the "Caption" edit box, write the word "&Toolbar" to name the menu and then close the dialog.

9.

Now do the same with the "IDR_TUTORITYPE" menu.

10.

Press View->ClassWizard menu to activate the class wizard.

11.

Select "Message Maps" tab and select " CMainFrame " as the Class name

12.

Select " ID_VIEW_TOOLBAR " from the "Object IDs" list box.

13.

Select "COMMAND" from the Messages list box.

14.

Press "Add Function" button à Press "OK" in the displayed dialog.

15.

Select " OnViewToolbar" from the Member functions list box.

16.

Press the "Edit Code" button

17.

Add the following line of code inside the generated function body:

   LRasterPaintWindow::ShowToolbar (!m_LToolbar.IsVisible());

The function should be look like this:

void CMainFrame::OnViewToolBar() 
{
   LRasterPaintWindow::ShowToolbar(!m_LToolbar.IsVisible());
}

18.

Press View->ClassWizard menu to activate the class wizard.

19.

Select "Message Maps" tab and select " CMainFrame " as the Class name

20

Select "ID_VIEW_TOOLBAR" from the "Object IDs" list box.

21.

Select "UPDATE_COMMAND_UI" from the Messages list box.

22.

Press "Add Function" button à Press "OK" in the displayed dialog.

23.

Select "OnUpdateViewToolbar" from the Member functions list box.

24.

Press the "Edit Code" button

25.

Add the following line of code inside the generated function body:

pCmdUI->SetCheck( m_LToolbar.IsVisible());

The function should be look like this:

void CMainFrame::OnUpdateViewToolBar(CCmdUI* pCmdUI) 
{
   pCmdUI->SetCheck(m_LToolbar.IsVisible());
}

The following steps handling the "Show/Hide" of the toolbar from the second menu by making the application goes to the generated code in the Mainframe

1.

Now double click on the "IDR_TUTORITYPE" menu from the "Resource View" tab to view the menu.

2.

Select "ViewàToolbar" from the menu.

3.

Right click on this menu item and select "Class Wizard".

4.

Select the "CMainFrame" from the "Class name" dropdown list".

5.

Select the "COMMAND" item from the "Messages" list à press "Ok".

6.

Repeat the previous steps but select the "UPDATE_COMMAND_UI" item from the "Messages" list then press "OK".

Step 18

Here we will be dealing with one of the paint dialogs, which is the "Brush" dialog:

1.

Move to the "Resource View" tab.

2.

Double click the "Tutorial resources" to expand the branch.

3.

Double click the "Menu" item from the tree to show the available menus.

4.

Double click on the "IDR_TUTORITYPE" item to view the menu.

5.

Drag the empty menu next to the "Help" menu and drops it before the "Help" menu.

6.

Right click on the empty menu and select "Properties".

7.

In the "Caption" edit box enter "Properties" as the menu caption and then close the dialog

8.

A new menu item will appear within the created menu.

9.

Right click on the empty menu item and select "Properties".

10

In the "Caption" edit box enter "&Brush" as the menu caption and then close the dialog

11.

Press View->ClassWizard menu to activate the class wizard.

12.

Select "Message Maps" tab and select " CMainFrame " as the Class name

13.

Select " ID_PROPERTIES_BRUSH" from the "Object IDs" list box.

14.

Select "COMMAND" from the Messages list box.

15.

Press "Add Function" button à Press "OK" in the displayed dialog.

16.

Select " OnPropertiesBrush" from the Member functions list box.

17.

Press the "Edit Code" button

18.

Add the following line of code inside the generated function body:

   CTutorialApp*   pTheApp = (CTutorialApp*)AfxGetApp();
   PAINTDLGBRUSHINFO   BrushDlgInfo;
   PAINTBRUSH*   pPaintBrush = m_RasterPntWnd.GetPaintBrush ();
   L_INT      nRetCode; 
   L_TCHAR*      TouchBitmap [ ] = { "Leaf" };
   L_TCHAR*      TextureBitmap [ ] = { "Texture-00" };

   BrushDlgInfo.dwFlags                 = PAINT_DLG_BRUSH_SHOWALL;
   BrushDlgInfo.pszTitle                = TEXT("Paintbrush Properties");
   BrushDlgInfo.nContentsType           = pPaintBrush->Touch.nContentsType;
   BrushDlgInfo.crColor                 = pPaintBrush->Touch.crColor;
   BrushDlgInfo.ppszTouchImage          = TouchBitmap;
   BrushDlgInfo.uTouchImageCount        = 1;
   BrushDlgInfo.nActiveTouchImageItem   = 0;
   BrushDlgInfo.nDiameter               = pPaintBrush->nDiameter;
   BrushDlgInfo.nHardnessValue          = pPaintBrush->Hardness.nValue;
   BrushDlgInfo.nSpacing                = pPaintBrush->nSpacing;
   BrushDlgInfo.nDensity                = pPaintBrush->nDensity;
   BrushDlgInfo.nOpacity                = pPaintBrush->nOpacity;
   BrushDlgInfo.nFadeOutRate            = pPaintBrush->nFadeOutRate;
   BrushDlgInfo.ppszPaperTexture        = TextureBitmap;
   BrushDlgInfo.uPaperTextureCount      = 1;
   BrushDlgInfo.nActivePaperTextureItem = ((pPaintBrush->pTexture != NULL) ? 0 : -1);

   nRetCode = m_PaintDialog.DoModalBrush(m_hWnd, &BrushDlgInfo);

   if(nRetCode == SUCCESS)
   {
      pPaintBrush->nSize                      = sizeof(PAINTBRUSH);
      pPaintBrush->dwMask                     = PBF_ALL;
      pPaintBrush->Touch.nContentsType        = BrushDlgInfo.nContentsType;
      pPaintBrush->Touch.crColor              = BrushDlgInfo.crColor;
      pPaintBrush->Touch.nShape               = PAINT_TOUCH_SHAPE_CIRCLE;
      pPaintBrush->Touch.pBitmap              = ((BrushDlgInfo.nActiveTouchImageItem != -1) ? pTheApp->m_LBtmpBrush.GetHandle() : NULL);
      pPaintBrush->Touch.crTransparentColor   = RGB(0, 0, 0);
      pPaintBrush->nDiameter                  = BrushDlgInfo.nDiameter;
      pPaintBrush->Hardness.nDistributionType = PAINT_HARDNESS_DISTRB_TYPE_0; 
      pPaintBrush->Hardness.nValue            = BrushDlgInfo.nHardnessValue; 
      pPaintBrush->nSpacing                   = BrushDlgInfo.nSpacing;
      pPaintBrush->nDensity                   = BrushDlgInfo.nDensity;
      pPaintBrush->nOpacity                   = BrushDlgInfo.nOpacity; 
      pPaintBrush->nFadeOutRate               = BrushDlgInfo.nFadeOutRate;
      pPaintBrush->pTexture                   = ((BrushDlgInfo.nActivePaperTextureItem != -1) ? pTheApp-> m_LBtmpPaperTexture.GetHandle() : NULL);
      
      m_RasterPntWnd.SetPaintBrush (pPaintBrush);
   }   
}

19.

Open the "Tutorial.h" file form the "File View" tab and add the following variables declaration after the "Public:" statement:

LBitmapBase                  m_LBtmpBrush;
LBitmapBase                  m_LBtmpPaperTexture; 

20

Copy the bitmaps you want to use in the dialog to the "Res" folder in your current directory.

21.

Now move to the "Resource View" tab.

22.

Right click on the "Tutorial resources" and select "Import" item.

23.

In the "Import Resource" dialog move to the "Res" directory where you copied the bitmaps, and select the "BitmapBrush" bitmap à "Import".

24.

Right click on the new added bitmap and select "Properties".

25.

Change the "ID" edit box to "IDB_BITMAP_BRUSH" and close the dialog.

26.

Repeat steps (29-32) to load the second bitmaps and give it the following ID "IDB_PAPER_TEXTURE"

27.

Move to the "Class View" tab.

28.

Right click on the "CTutorialApp" class and select "Add Member Function&".

29.

Enter "void" in the "Function Type" edit box and enter "LoadImages()" statement in the "Function Declaration" edit box à "Press "Ok".

30.

Add the following lines of code to the function body:

   DIBSECTION dibsc;
   BITMAPHANDLE TempBtmapHandle;

   // load paper texture image.
   HANDLE hBitmap = LoadImage(AfxGetInstanceHandle(), 
   MAKEINTRESOURCE(IDB_PAPER_TEXTURE), IMAGE_BITMAP, 0, 0, 
   LR_CREATEDIBSECTION | LR_DEFAULTSIZE);

   GetObject(hBitmap , sizeof (DIBSECTION), &dibsc);

   L_CONVERTFROMDIB(&TempBtmapHandle, (LPBITMAPINFO) &dibsc.dsBmih, (L_UCHAR*)dibsc.dsBm.bmBits);

    m_LBtmpPaperTexture.SetHandle(&TempBtmapHandle);
   m_LBtmpPaperTexture.ChangeViewPerspective(TOP_LEFT);

   DeleteObject((HBITMAP) hBitmap);

   // load the brush image.
   hBitmap = LoadImage(AfxGetInstanceHandle(), 
         MAKEINTRESOURCE(IDB_BITMAP_BRUSH), IMAGE_BITMAP, 0, 0, 
   LR_CREATEDIBSECTION | LR_DEFAULTSIZE);

   GetObject(hBitmap , sizeof (DIBSECTION), &dibsc);

   L_CONVERTFROMDIB(&TempBtmapHandle, (LPBITMAPINFO) &dibsc.dsBmih, (L_UCHAR *)dibsc.dsBm.bmBits);

   m_LBtmpBrush.SetHandle(&TempBtmapHandle);
   m_LBtmpBrush.ChangeViewPerspective(TOP_LEFT);

   DeleteObject((HBITMAP) hBitmap);

31.

Right click on the "CTutorialApp" class and select "Add Member Function&".

32.

Enter "void" in the "Function Type" edit box and enter "FreeImages()" statement in the "Function Declaration" edit box à "Press "Ok".

33.

Add the following lines of code to the function body:

 m_LBtmpBrush.Free();
m_LBtmpPaperTexture.Free();

34.

Add the following statement to the "InitInstance()" function in the "Tutorial.cpp" file before the "return TRUE" statement:

LoadImages();

35.

Add the following statement at the end of the "~CTutorialApp()" function in the "Tutorial.cpp" file

FreeImages();