Start with the project you created in Creating an Empty Vector Handle and Attaching it to a Window.
In the solution explorer view open the Resources Files then double click on tutorial.rc
Select IDC_TUTORIAL under the Menu
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
Select File->Save All from the menu.
Edit the _tWinMain function and change the line:
WndClass.lpszMenuName = NULL;
To:
WndClass.lpszMenuName = MAKEINTRESOURCE( IDC_TUTORIAL);
Add the following lines at the beginning of the tutorial.cpp file under #include "stdafx.h"
#include <commdlg.h>
#include "C:\LEADTOOLS22\Include\ltdlg.h"
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;
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;
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;
Modify the Imports.cpp file to be as the following:
#include "stdafx.h"
#if defined(WIN64)
#pragma comment( lib, "..\\..\\..\\..\\Lib\\CDLL\\x64\\Ltvkrn_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\\Ltvkrn_u.lib")
#pragma comment( lib, "..\\..\\..\\..\\Lib\\CDLL\\Win32\\Ltkrn_u.lib")
#pragma comment( lib, "..\\..\\..\\..\\Lib\\CDLL\\Win32\\Ltfil_u.lib")
#endif
Compile and run the project. You will be able to view, load and save vector files as you browse your local hard disk.