Available in LEADTOOLS Imaging Pro, Vector, Document, and Medical Imaging toolkits. |
Using C++ Class Library DigitalPaint Tools
To start a project and add code that creates a new paint window:
Step 1
1. |
Start Visual Studio 2005. |
2. |
Select the File->New menu option, click the "projects" tab. |
3. |
From “Project Types” click on Visual C++ to expand it, then select MFC. From the right window select MFC Application. |
4. |
In the Project Name dialog box, enter "Tutorial". |
5. |
In the Location dialog box, use the examples\ClassLibrary\MSVC directory of your LEAD installation. For example, if you installed LEADTOOLS in c:\ltwin16x, enter c:\ltwin16x\examples\classlibrary\msvc\ Click OK. Then click “Next” |
6. |
Choose Multiple Document and click "Next". |
7. |
The "MFC AppWizard step 3 of 8", appears. Keep the default settings and press the "Next" Button. |
8. |
The "MFC AppWizard step 4 of 8", appears. Keep the default settings and press the "Next" Button. |
9. |
The "MFC AppWizard step 5 of 8", appears. Keep the default settings and press the "Next" Button. |
10. |
The "MFC AppWizard step 6 of 8", appears. Check "None" radio button under "Toolbars" and press the "Next" Button. |
13. |
The "MFC AppWizard step 7 of 8", appears. Uncheck the "Printing and print preview" combo box and press the "Finish" Button. |
Step 2
1. |
In stdafx.h add the following headers: (keep in mind, you may have to change the path to where the header files reside): |
#include "..\..\..\..\..\include\ClassLib\ltWrappr.h"
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": |
LSettings::UnlockSupport(L_SUPPORT_GIFLZW, L_KEY_GIFLZW);
LSettings::UnlockSupport(L_SUPPORT_TIFLZW, L_KEY_TIFLZW);
LBase::LoadLibraries(LT_PDG|LT_KRN|LT_FIL|LT_DLG|LT_AUT|LT_CON|LT_TLB|LT_DIS);
LDialogBase::Initialize(DLG_INIT_COLOR);
5. |
Click on the "Class View" tab. |
6. |
Click to open the Tutorial Classes branch. |
7. |
Right click on "CTutorialApp", and select "Add Function” |
8. |
In the Add Member Function Dialog, enter "~CTutorialApp" for the Function name and enter “void” for the return type and then press Finish. |
9. |
Add the following lines inside the generated function": |
LDialogBase::Free();
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;
Step 5
|
Create a new file called Imports.cpp in place it beside your project files. |
a. |
In the Project Workspace, click the Solution Explorer tab. |
b. |
Double-click the Automated folder to open it. |
c. |
Right-click the Source files folder and select Add à New item. |
d. |
Right-click on the Source file |
e. |
Expand Visual C++ tree, if it is not already expanded. |
f. |
Select Code from the sub tree. |
g. |
Select C++ File (.cpp) from the right window. |
h. |
In the name text box, specify Imports. |
i. |
Click the OK button. |
j. |
Double-click the Imports.cpp file in the solution Explorer and add the following lines: |
#include "StdAfx.h"
#if defined(WIN64)
#pragma comment(lib, "..\\..\\..\\..\\..\\Lib\\CDLL\\x64\\Ltwvc_x.lib")
#else
#pragma comment(lib, "..\\..\\..\\..\\..\\Lib\\CDLL\\Win32\\Ltwvc_u.lib")
#endif // #if defined(WIN64)
Step 6
1. |
Click on the "Class View" tab. |
2. |
Double click on "CTutorialView" |
3. |
Add the following public variables: LRasterPaintWindow m_RasterPntWnd; LRasterDialog m_PaintDialog; |
Step 7
1. |
Go to TutorialView.h file then add the following function declaration: public: afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); |
2. |
Go to TutorialView.cpp file then add the following line between the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP: ON_WM_CREATE() |
3. |
Add the following function: |
int CTutorialView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if(CView::OnCreate(lpCreateStruct) == -1)
return -1;
m_RasterPntWnd.SetWndHandle (m_hWnd);
return 1;
}
Step 8
1. |
Click on the "Class View" tab. |
2. |
Right click "CMainFrame" and select "Add Variable..." |
3. |
Add the following variable: protected: |
Step 9
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);
Step 10
1. |
Go to MainFrm.h file then add the following function declaration: afx_msg void OnClose(); |
2. |
Go to MainFrm.cpp file then add the following line between the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP: ON_WM_CLOSE() |
3. |
Add the following function: |
void CMainFrame::OnClose()
{
LRasterPaintWindow::FreeToolbar (&m_LToolbar);
LRasterPaintWindow::Free();
CMDIFrameWnd::OnClose();
}
Step 11
Handle Save & Update UI for it
1. |
Click on the "Resource View" tab. |
2. |
Click on the “Menu” folder to expand it. Then double click “IDR_TutorialTYPE” to edit the menu. |
3. |
Click on the “File” menu, then right click on the “Save” item and click "Add event handler" |
4. |
From Class list select “CTutorialDoc” and make sure that the "COMMAND" is selected on the “Message Type” window, then click the "Add and Edit" button. |
|
Add the following lines of code after the "// TODO" comment line: |
POSITION pos = GetFirstViewPosition();
CTutorialView* pView = (CTutorialView*) GetNextView(pos);
LBitmapBase* pLBtmpbase = pView->m_RasterPntWnd.GetBitmap();
BOOL bFlag = AfxGetMainWnd()->EnableWindow(FALSE);
SAVEDLGPARAMS SaveParms ;
OPENFILENAME OpenFileName ;
memset ( &SaveParms, 0, sizeof ( SAVEDLGPARAMS ) ) ;
memset ( &OpenFileName, 0, sizeof ( OPENFILENAME ) ) ;
OpenFileName.lStructSize = sizeof ( OPENFILENAME ) ;
OpenFileName.lpstrInitialDir = NULL;
OpenFileName.lpstrTitle = _T("Save a File");
OpenFileName.nFilterIndex = 0 ;
SaveParms.uStructSize = sizeof ( SAVEDLGPARAMS) ;
SaveParms.nQFactor = 2 ;
SaveParms.nPageNumber = 1 ;
SaveParms.nStampBits = 24;
SaveParms.nStampWidth = 120;
SaveParms.nStampHeight = 120;
SaveParms.nBitsPerPixel = 24;
SaveParms.nFormat = FILE_BMP;
SaveParms.uSaveMulti = MULTIPAGE_OPERATION_REPLACE ;
SaveParms.uDlgFlags = DLG_SAVE_SHOW_FILEOPTIONS_PROGRESSIVE |
DLG_SAVE_SHOW_FILEOPTIONS_MULTIPAGE |
DLG_SAVE_SHOW_FILEOPTIONS_STAMP |
DLG_SAVE_SHOW_FILEOPTIONS_QFACTOR |
DLG_SAVE_SHOW_FILEOPTIONS_J2KOPTIONS |
DLG_SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS ;
pLBtmpbase->DialogFile()->SetSaveParams(&SaveParms);
pLBtmpbase->DialogFile()->SetOpenFile(&OpenFileName);
pLBtmpbase->DialogFile()->EnableAutoProcess(TRUE);
L_INT nRetCode = pLBtmpbase->DialogFile()->DoModalSave(pView->m_hWnd);
if(nRetCode!=SUCCESS_DLG_OK && nRetCode!=SUCCESS_DLG_CANCEL)
pView->MessageBox(_T("Can't Save to file, check if file is read only."), _T("File Save Error"), MB_ICONWARNING | MB_OK);
bFlag = AfxGetMainWnd()->EnableWindow(TRUE);
AfxGetMainWnd()->SetActiveWindow();
Step 12
1. |
Click on the "Resource View" tab. |
2. |
Click on the “Menu” folder to expand it. Then double click “IDR_TutorialTYPE” to show the menu on the right window. |
3. |
Click on the “File” menu, then right click on the “Save” item and click "Add event handler" |
4. |
From “Message Type” select "UPDATE_COMMAND_UI ", and from Class list select “CTutorialDoc”. Then click the "Add and Edit" button. |
6. |
Add the following lines of code after the "// TODO" comment line: |
pCmdUI->Enable(m_RasterPntWnd. GetBitmap ()->IsAllocated());
Step 13
Handle Open & Update UI for it
1. |
Click on the "Resource View" tab. |
2. |
Click on the “Menu” folder to expand it. Then double click “IDR_MAINFRAME” to show the menu on the right window. |
3. |
Click on the “File” menu, then right click on the “Open” item and click “Properties”. In ID field, set the ID to IDM_FILE_OPEN. |
4. |
Click on the “File” menu, then right click on the “Open” item and click "Add event handler" |
5. |
From Class list select “CTutorialApp” and make sure that the "COMMAND" is selected on the “Message Type” window, then click the "Add and Edit" button. |
6. |
Add the following lines of code after the "// TODO" comment line: |
OPENDLGPARAMS FOParm ;
OPENFILENAME OpenFileName;
memset ( &FOParm, 0, sizeof(OPENDLGPARAMS)) ;
memset ( &OpenFileName, 0, sizeof(OPENFILENAME)) ;
OpenFileName.lStructSize = sizeof(OPENFILENAME);
OpenFileName.lpstrInitialDir = NULL;
OpenFileName.Flags = OFN_EXPLORER;
FOParm.uStructSize = sizeof(OPENDLGPARAMS);
FOParm.uDlgFlags = DLG_OPEN_ENABLESIZING |
DLG_OPEN_SHOW_PROGRESSIVE |
DLG_OPEN_USEFILESTAMP |
DLG_OPEN_SHOW_MULTIPAGE |
DLG_OPEN_SHOW_LOADROTATED |
DLG_OPEN_SHOW_LOADCOMPRESSED |
DLG_OPEN_SHOW_DELPAGE |
DLG_OPEN_SHOW_LOADOPTIONS |
DLG_OPEN_SHOW_FILEINFO |
DLG_OPEN_SHOW_PDFOPTIONS |
DLG_OPEN_SHOW_RASTEROPTIONS |
DLG_OPEN_SHOW_VECTOROPTIONS |
DLG_OPEN_VIEWTOTALPAGES;
FOParm.bPreviewEnabled = TRUE;
m_LBitmap.DialogFile()->SetOpenParams(&FOParm) ;
m_LBitmap.DialogFile()->EnablePreview(TRUE);
m_LBitmap.DialogFile()->SetOpenFile(&OpenFileName) ;
m_LBitmap.DialogFile()->EnableCallBack(FALSE);
L_INT nRetCode = m_LBitmap.DialogFile()->DoModalOpen(m_pMainWnd->m_hWnd);
if(nRetCode==SUCCESS_DLG_OK)
{
L_TCHAR szFileName[256];
memset(szFileName,0,sizeof(szFileName));
L_UINT uSize=sizeof(szFileName);
m_LBitmap.GetFileName(szFileName,&uSize);
m_LBitmap.DialogFile()->GetOpenParams(&FOParm,sizeof(FOParm)) ;
POSITION pos = GetFirstDocTemplatePosition();
CDocTemplate* pDocTemplate = GetNextDocTemplate(pos);
pDocTemplate->OpenDocumentFile(szFileName);
}
7. |
Click on the "Class View" tab. |
8. |
Double click on "CTutorialApp" |
9. |
Add the following public variables: |
public:
LBitmapBase m_LBitmap;
Step 14
1. |
Click on the "Class View" tab. |
2. |
Click to open the "Tutorial Classes" branch. |
3. |
Right click on the "CTutorialDoc" to choose “Properties” |
4. |
From the "Properties" window toolbar, click on the overrides icon. Then click on the empty area beside the item "OnOpenDocument" and choose OnOpenDocument. |
7. |
Replace return statement with the following code: |
CTutorialApp* pTheApp = (CTutorialApp*) AfxGetApp();
POSITION pos = GetFirstViewPosition();
CTutorialView* pView = (CTutorialView*)GetNextView(pos);
FILEINFO fInfo;
OPENDLGPARAMS FOParm;
memset(&FOParm, 0, sizeof(OPENDLGPARAMS));
memset(&fInfo, 0, sizeof(FILEINFO));
fInfo.uStructSize = sizeof(FILEINFO);
LBitmapBase LBtmpbase;
pTheApp->m_LBitmap.DialogFile()->GetOpenParams(&FOParm, sizeof(OPENDLGPARAMS));
LBtmpbase.SetFileName((L_TCHAR *)lpszPathName);
LBtmpbase.File()->GetInfo(&fInfo, sizeof(FILEINFO), FILEINFO_TOTALPAGES, NULL);
L_INT nBitsPerPixel = fInfo.BitsPerPixel;
if (nBitsPerPixel != 1 && nBitsPerPixel != 4 && nBitsPerPixel != 8 && nBitsPerPixel != 16 && nBitsPerPixel != 24)
{
pView->MessageBox(_T("Your image format is not either 1,4,8,16 or 24 bits per pixel"), _T("Error Opening Image"), MB_ICONWARNING | MB_OK);
return FALSE;
}
L_INT nRetCode = LBtmpbase.Load(fInfo.BitsPerPixel, ORDER_BGRORGRAY, (FOParm.pFileData)? FOParm.pFileData[0].nPageNumber : 1);
if(nRetCode!=SUCCESS)
{
if(nRetCode== ERROR_PDF_BAD_INITIALIZATION_FILES)
{
if( IDYES == MessageBox(AfxGetApp()->m_pMainWnd->m_hWnd, TEXT("LEADTOOLS PDF plugin is not found, do you want to download the plugin now?"),
TEXT("Open file"),MB_ICONEXCLAMATION | MB_YESNO))
ShellExecute(AfxGetApp()->m_pMainWnd->m_hWnd, TEXT("open"), TEXT("http://www.leadtools.com/ReleaseDownloads/v16/LEADTOOLSPDFRuntime.exe"),
NULL, NULL, SW_SHOWNORMAL);
}
else
LBase::DisplayError (NULL, nRetCode);
}
else
{
pView->m_RasterPntWnd.SetBitmap(&LBtmpbase);
}
return ((nRetCode == SUCCESS) ? TRUE : FALSE);
6. |
Open the "TutorialDoc.cpp" file from the "File View" tab. |
7. |
Add this include statement after the #include "TutorialDoc.h" |
#include "TutorialView.h"
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_TutorialTYPE" item from the "Resource View" tab to view this menu. |
8. |
Delete the “New”, "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 on the "CMainFrame" and select "Properties". |
5. |
From the "Properties" window toolbar, click on the Message icon. Then click on the empty area beside the item "WM_PALETTECHANGED" and choose OnPaletteChanged |
6. |
Add the following lines of code after the " void CMainFrame::OnPaletteChanged(CWnd* pFocusWnd) line: |
if(pFocusWnd!=NULL)
SendMessageToDescendants(WM_HANDLEPALETTE,(WPARAM)pFocusWnd ->m_hWnd, TRUE);
7. |
Right click "CMainFrame" and select "Properties". |
8. |
From the "Properties" window toolbar, click on the Message icon. Then click on the empty area beside the item " WM_QUERYNEWPALETTE" and choose OnQueryNewPalette |
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 "Properties". |
11. |
From the "Properties" window toolbar, click on the Message icon. Then click on the empty area beside the item " WM_SYSCOLORCHANGE" and choose OnSysColorChange |
12. |
Replace the "CMDIFrameWnd::OnSysColorChange();" statement with the following line of code which actually calls the OnQueryNewPalette() function: |
OnQueryNewPalette();
13. |
Right click " CTutorialView" and select "Properties". |
14. |
From the "Properties" window toolbar, click on the overrides icon. Then click on the empty area beside the item "OnActivateView" and choose OnActivateView |
15. |
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 "Soluation Explorer" 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.HandlePalette(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" 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. |
Click on the "View" menu to view the menu items. |
8. |
Add a new menu item "&Toolbar" to the menu. |
9. |
Now do the same with the "IDR_TutorialTYPE" menu. |
10. |
Right-click on the "Toolbar" menu item and choose "Add Event Handler…" |
11. |
Select "Message Maps" tab and select " CMainFrame " as the Class name |
13. |
Select "COMMAND" from the Messages list box. |
14. |
Click the "Add and Edit" button. |
17. |
Add the following line of code inside the generated function body: |
LRasterPaintWindow::ShowToolbar (!m_LToolbar.IsVisible());
18. |
Right-click again on the "Toolbar" menu item and choose "Add Event Handler…" |
19. |
Select "Message Maps" tab and select " CMainFrame " as the Class name |
21. |
Select "UPDATE_COMMAND_UI" from the Messages list box. |
22. |
Click the "Add and Edit" button. |
25. |
Add the following line of code inside the generated function body: |
pCmdUI->SetCheck(m_LToolbar.IsVisible());
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" to expand the branch. |
3. |
Double click the "Menu" item from the tree to show the available menus. |
4. |
Double click on the "IDR_TutorialTYPE" item to view the menu. |
5. |
Click on the empty menu and then type "&Properties" |
7. |
Drag the new menu next to the "Help" menu and drop it before the "Help" menu. |
8. |
A new menu item will appear within the created menu "Properties". |
9. |
click on the empty menu item and enter "&Brush" |
11. |
Right-click on "&Brush" menu item and select "Add Event Handler…" |
12. |
Select "Message Maps" tab and select " CTutorialView" as the Class name |
14. |
Select "COMMAND" from the Messages list box. |
15. |
Click the "Add and Edit" 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 [ ] = { TEXT("Leaf") };
L_TCHAR* TextureBitmap [ ] = { TEXT("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. |
Click on the "Class View" tab. |
20. |
Double click on "CTutorialApp" |
21. |
Add the following public variables: LBitmapBase m_LBtmpBrush; |
22 |
Copy the bitmaps you want to use in the dialog to the "Res" folder in your current directory. |
23. |
Now move to the "Resource View" tab. |
24. |
Right click on the "Tutorial.rc” and select “Add resource”. In “Add Resource” dialog click “Import” |
25. |
In the "Import Resource" dialog browse to the LEADTOOLS "Images" directory (%UserProfile%\My Documents\LEADTOOLS Images), and select one of the bitmap files (ex. ULAY1.BMP) then click “Open”. |
26. |
Right click on the new added bitmap and select "Properties". |
27. |
Change the "ID" edit box to "IDB_BITMAP_BRUSH" and close the dialog. |
28. |
Repeat steps (29-32) to load a second bitmap (ex. ULAY2.BMP) and give it the following ID "IDB_PAPER_TEXTURE" |
29. |
Move to the "Class View" tab. |
30. |
Right click on the "CTutorialApp" class and select Add à Add Function. |
31. |
Enter "void" in the "Return Type" edit box and enter "LoadImages" statement in the "Function name" edit box à "Press "Finish". |
32. |
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);
m_LBtmpPaperTexture.SetHandle(&TempBtmapHandle);
m_LBtmpPaperTexture.ConvertFromDIB((LPBITMAPINFO) &dibsc.dsBmih, (L_UCHAR*)dibsc.dsBm.bmBits);
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);
m_LBtmpBrush.SetHandle(&TempBtmapHandle);
m_LBtmpBrush.ConvertFromDIB((LPBITMAPINFO) &dibsc.dsBmih, (L_UCHAR *)dibsc.dsBm.bmBits);
m_LBtmpBrush.ChangeViewPerspective(TOP_LEFT);
DeleteObject((HBITMAP) hBitmap);
31. |
Right click on the "CTutorialApp" class and select Add à Add Function. |
32. |
Enter "void" in the "Return Type" edit box and enter "FreeImages" statement in the "Function Name" edit box à "Press "Finish". |
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();