Getting and setting window center and width Example for C++ 6.0 and later
// This example will add a new "Window Width" and
// "Window Center" to the dataset , or replace
// the existing one(s)
BOOL bAddWindow=TRUE;// add or replace
ILWindowAttributesPtr pWindowAttributes = NULL;
short iRet;
long lWindowCount=0;
long lWindowIndex=0;
int iBitsStored = 12;
lWindowCount = m_pLEADDicomDS->WindowCount;
if(lWindowCount>0)
{
iRet = m_pLEADDicomDS->GetWindowAttributes(0,0);
if(iRet != 0)
{
AfxMessageBox("error");
return;
}
pWindowAttributes = m_pLEADDicomDS->GetWindowAttributes();
// Half the width for the first window
pWindowAttributes->WindowWidth = pWindowAttributes->WindowWidth/2;
pWindowAttributes->WindowCenter = pWindowAttributes->WindowCenter/2;
}
else
{
// This represents an identity VOI LUT transformation in the case
// where no Modality LUT is specified and the stored pixel data are
// iBitsStored bit unsigned integers.
pWindowAttributes = m_pLEADDicomDS->GetWindowAttributes();
pWindowAttributes->WindowWidth = 1 << iBitsStored;
pWindowAttributes->WindowCenter = 1 << (iBitsStored-1);
pWindowAttributes->WindowCWExplaination = "";
}
lWindowIndex = lWindowCount;
if(!bAddWindow)
{
// Delete the existing window(s)
iRet = m_pLEADDicomDS->DeleteWindow (0);
if(iRet != 0)
{
AfxMessageBox("error");
return;
}
lWindowIndex = 0;
}
// Add the new window
iRet = m_pLEADDicomDS->SetWindowAttributes (lWindowIndex,0);
if(iRet != 0)
{
AfxMessageBox("error");
return;
}
return;