Loading a Data Set (C++ 6.0 and later)
Take the following steps to start a project and to add some code that loads a DICOM Data Set and prints information about the data set.
1. |
Start a new project as follows: |
|
|
For C++ 6.0, run Microsoft Visual C++ 6.0, select the File >New menu option, and do the following: |
|
|
a. |
Click the Projects tab. |
|
b. |
Select MFC AppWizard (exe) as the project type |
|
c. |
In the Project name text box, specify dicom. |
|
d. |
In the Location text box, specify the path of the project. |
|
e. |
Click the OK button. |
2. |
In the Step 1 dialog box, do the following: |
|
|
a. |
Select Dialog based. |
|
b. |
Click the Next button. |
3. |
In the Step 2 of 4 dialog box, do the following: |
|
|
a. |
Ensure that About Box is selected. |
|
b. |
Ensure that 3D Controls is selected. |
|
c. |
Select ActiveX Controls. |
|
d. |
Click the Next button. |
4. |
In the Step 3 of 4 dialog box, do the following: |
|
|
a. |
For comments, ensure that Yes, Please is selected. |
|
b. |
For how to use the MFC library, select As a shared DLL. |
|
c. |
Click the Next button. |
5. |
In the Step 4 of 4 dialog box, just click Finish. |
|
6. |
Read New Project Information, and click OK. (The AppWizard creates the project files and opens the project.) |
|
7. |
Import the DICOM COM Object type libraries into your projects as follows: |
|
|
a. |
Copy the \lead\include\l_com.h and ltkey.h files to your project directory. |
|
b. |
In the Project Workspace, click the FileView tab. |
|
c. |
Double-click the dicom files folder to open it. |
|
d. |
Double-click the the Header Files folder to open it. |
|
e. |
Double-click the StdAfx.h file to edit it. |
|
f. |
Add the following lines to the file, just before "AFX_INSERT_LOCATION": |
#include "l_com.h"
#import <ltrvr14n.dll> no_namespace, named_guids, exclude("RasterSupportLockConstants")
#import <ltr14n.dll> no_namespace, named_guids, exclude("RasterSupportLockConstants")
#import <ltrvw14n.ocx> no_namespace, named_guids
#import <ltrpr14n.dll> no_namespace, named_guids
#import <ltrio14n.dll> no_namespace, named_guids, exclude("LoadResizeConstants"), exclude("J2KLimitConstants"), exclude("J2KProgressionFlags"), exclude("J2KRegionOfInterest")
#import <LTDicKrn14n.dll> no_namespace, named_guids, exclude("LoadDirectoryFlags")
#import <LTDicDS14n.dll> no_namespace, named_guids, exclude("DicomAnnSaveModifyConstants"), exclude("DicomCommandSetMessagePriorities")
#import <LTDicNet14n.dll> no_namespace, named_guids
#import <LTDPScu14n.dll> no_namespace, named_guids#ifndef MAKETAG
#define MAKETAG(nGroup,nElement) ((unsigned long)((((unsigned long)nGroup) << 16) | nElement))
#define GETGROUP(nTag) ((unsigned short)(nTag >> 16))
#define GETELEMENT(nTag) ((unsigned short)(nTag & 0xFFFF))
#endif
8. |
Add a LEADDicomDS COM Object to the application as follows: |
|
|
a. |
In the Project Workspace, click the FileView tab. |
|
b. |
Double-click the dicom files folder to open it. |
|
c. |
Double-click the Header Files folder to open it. |
|
d. |
Double-click the dicomDlg.h file to edit it. |
|
e. |
Add the following lines to the file, just after the class constructor: |
ILEADDicomDS *m_pLEADDicomDS;
9. |
Go to the OnInitDialog() function as follows: |
|
|
a. |
In the Project Workspace, click the ClassView tab. |
|
b. |
Double-click the Dicom classes folder to open it. |
|
c. |
Expand the CDicomDlg class. |
|
d. |
Double-click the OnInitDialog() function to edit it. |
10. |
Edit the OnInitDialog() function to add the following code after the line that says //TODO: Add extra initialization here: |
BSTR lpLic = SysAllocString(_szLicString);
ILEADDicomFactory *pFactory=NULL;
CoCreateInstance(CLSID_LEADDicomFactory, NULL, CLSCTX_ALL,
IID_ILEADDicomFactory, (void**)&pFactory);
#if _MSC_VER < 1200
m_pLEADDicomDS = (ILEADDicomDS*)pFactory->CreateObject ("LEADDicomDS.LEADDicomDS", lpLic);
#else
ILEADDicomDSPtr spLEADDicomDS=NULL;
spLEADDicomDS = pFactory->CreateObject ("LEADDicomDS.LEADDicomDS", lpLic);
m_pLEADDicomDS = spLEADDicomDS;
m_pLEADDicomDS->AddRef();//because when spLEADDicomDS goes out of scope, it will auto Release()!
#endif
m_pLEADDicomDS->EnableMethodErrors = FALSE;
// Unlock DICOM support.
ILEADDicomKernel *pLEADDicomKernel = NULL;
#if _MSC_VER < 1200
pLEADDicomKernel = (ILEADDicomKernel*)pFactory->CreateObject ("LEADDicomKernel.LEADDicomKernel", lpLic);
#else
ILEADDicomKernelPtr spLEADDicomKernel=NULL;
spLEADDicomKernel = pFactory->CreateObject ("LEADDicomKernel.LEADDicomKernel", lpLic);
pLEADDicomKernel = spLEADDicomKernel;
pLEADDicomKernel->AddRef();//because when spLEADDicomKernel goes out of scope, it will auto Release()!
#endif
UNLOCKSUPPORT(*pLEADDicomKernel);
pLEADDicomKernel->Release();
pFactory->Release();
SysFreeString(lpLic);
11. |
Add the following lines to the top of the file, after all the #include statements: |
const WCHAR BASED_CODE _szLicString[] =
L"LEADTOOLS OCX Copyright (c) 1991-2005 LEAD Technologies, Inc.";
12. |
Add a command button to your form and name it as follows: |
|
|
a. |
In the Project Workspace, click the ResourceView tab. |
|
b. |
Double-click the Dicom resources folder to open it. |
|
c. |
Double-click the Dialog folder to open it. |
|
d. |
Double-click IDD_DICOM_DIALOG to design the dialog box. |
|
e. |
Select the TODO... text control; then press the Delete key to delete it. |
|
f. |
Add a command button to the dialog, and name it as follows: |
|
ID |
Caption |
|
IDC_LOADDICOM |
Load |
13. |
Press Ctrl-W to go to the MFC Class Wizard; then do the following: |
|
|
a. |
Click the Message Maps tab. |
|
b. |
In the Class Name combo box, select CDicomDlg. |
|
c. |
In the Object IDs list box, select IDC_LOADDICOM. |
|
d. |
In the Messages list box, select BN_CLICKED. |
|
e. |
Click the Add function button. Choose OK for the default function name (OnLoaddicom). |
|
f. |
Click the Edit Code button and enter the following code: |
int Result;
short nRet;
long lCount;
CString cs;
IDicomDSModulePtr pCurrentModule=NULL;
IDicomDSElementPtr pCurrentElement=NULL;
m_pLEADDicomDS->EnableMethodErrors = FALSE;
nRet = m_pLEADDicomDS->LoadDS("D:\\LTWIN13\\images\\test2.dic", 0);
if (nRet != DICOM_SUCCESS)
AfxMessageBox("Error loading file");
else
{
AfxMessageBox("File is loaded.");
lCount = m_pLEADDicomDS->GetModuleCount();
m_pLEADDicomDS->FindIndexModule(0);
pCurrentModule = m_pLEADDicomDS->GetCurrentModule();
pCurrentElement = pCurrentModule->GetElement(0);
Result = m_pLEADDicomDS->SetCurrentElement (pCurrentElement->GethElement());
if(Result)
{
cs.Format("There are %d modules in this data set\n"
"The first module has %d elements.\n"
"The first element has:\n"
"Tag number: %08X\n"
"VR: %08X\n", lCount,
pCurrentModule->GetElementCount(),
pCurrentElement->GetTag(),
pCurrentElement->GetVR());
AfxMessageBox(cs);
}
}
m_pLEADDicomDS->EnableMethodErrors = TRUE;
14. |
On the main menu, select Build > Build dicom.exe to build the project. |
|
15. |
On the main menu, select Build > Execute dicom.exe to run the project. |
|
16. |
Press Ctrl-W to go to the MFC Class Wizard; then do the following: |
|
|
a. |
Click the Message Maps tab. |
|
b. |
In the Class Name combo box, select CDicomDlg. |
|
c. |
In the Object IDs list box, select CDicomDlg. |
|
d. |
In the Messages list box, select WM_CLOSED. |
|
e. |
Click the Add function button. Choose OK for the default function name (OnClose). |
|
f. |
Click the Edit Code button and enter the following code: |
if(m_pLEADDicomDS)
m_pLEADDicomDS->Release();