Available in LEADTOOLS Vector Imaging toolkits. |
Vector Load and Save
To add vector load and save functionality:
Start with the project you created in Creating an Empty Vector Handle and Attaching it to a Window.
1. |
In the solution explorer view open the Resources Files then double click on tutorial.rc |
2. |
Select IDC_TUTORIAL under the Menu |
3. |
Modify the Menu structure to be as the following: |
IDR_MENU1
&File
&Open… with ID = IDM_OPEN
&Save… with ID = IDM_SAVE
E&xit with ID = IDM_EXIT
4. |
Select File->Save All from the menu. |
5. |
Edit the _tWinMain function and change the line: |
WndClass.lpszMenuName = NULL;
To:
WndClass.lpszMenuName = MAKEINTRESOURCE( IDC_TUTORIAL);
6. |
Add the following lines at the beginning of the tutorial.cpp file ander #include "stdafx.h" |
#include <commdlg.h>
#include "C:\Program Files\LEAD Technologies\LEADTOOLS EVAL 16\Include\ltdlg.h"
7. |
Add these local variables under HDC hDC; in the WndProc function: |
static OPENFILENAME OpenFileName;
static L_TCHAR szFileName[ _MAX_PATH ];
static L_TCHAR szFileTitle[ _MAX_PATH ];
static L_TCHAR *szFilter[] = { TEXT("All Files\0*.*\0") };
L_INT nRet;
8. |
Add these lines right after ResetView( hWnd, &Vector ); in WM_CREATE handle: |
// reset the OPENFILENAME structure
memset( &OpenFileName, 0, sizeof( OPENFILENAME ) );
OpenFileName.lStructSize = sizeof( OPENFILENAME );
OpenFileName.hwndOwner = hWnd;
OpenFileName.lpstrFilter = szFilter[ 0 ];
OpenFileName.lpstrFile = szFileName;
OpenFileName.nMaxFile = _MAX_PATH;
OpenFileName.lpstrFileTitle = szFileTitle;
OpenFileName.nMaxFileTitle = _MAX_PATH;
9. |
Modify the WM_COMMAND case in WndProc to be as the following |
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd,
About);
break;
case IDM_OPEN:
OpenFileName.Flags = OFN_HIDEREADONLY;
if( GetOpenFileName( &OpenFileName ) )
{
// open the vector file
nRet = L_VecLoadFile ( szFileName, &Vector, NULL,
NULL );
if( nRet != SUCCESS )
MessageBox( hWnd, TEXT("Cannot open file!"),
TEXT("Error"), MB_ICONEXCLAMATION );
GetClientRect( hWnd, &Rect );
L_VecSetViewport ( &Vector, &Rect );
ResetView( hWnd, &Vector );
}
break;
case IDM_SAVE:
OpenFileName.Flags = OFN_HIDEREADONLY |
OFN_OVERWRITEPROMPT;
if( GetSaveFileName( &OpenFileName ) )
{
// save the vector file
nRet = L_VecSaveFile ( szFileName, &Vector, FILE_DXF,
NULL );
if( nRet != SUCCESS )
MessageBox( hWnd, TEXT("Cannot save file!"),
TEXT("Error"), MB_ICONEXCLAMATION );
}
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
10. |
Modify the Imports.cpp file to be as the following: #if defined(WIN64) #pragma comment( lib, "..\\..\\..\\..\\Lib\\CDLL\\x64\\Lvkrn_x.lib") #pragma comment( lib, "..\\..\\..\\..\\Lib\\CDLL\\x64\\Ltkrn_x.lib") #pragma comment( lib, "..\\..\\..\\..\\Lib\\CDLL\\x64\\Ltfil_x.lib") #else #pragma comment( lib, "..\\..\\..\\..\\Lib\\CDLL\\Win32\\Lvkrn_u.lib") #pragma comment( lib, "..\\..\\..\\..\\Lib\\CDLL\\Win32\\Ltkrn_u.lib") #pragma comment( lib, "..\\..\\..\\..\\Lib\\CDLL\\Win32\\Ltfil_u.lib") #endif
|
11. |
Compile and run the project. You will be able to view, load and save vector files as you browse your local hard disk. |