// LeftPaneWnd.cpp : implementation file // #include "stdafx.h" #include "Overlay.h" #include "LeftPaneWnd.h" #include "MainFrm.h" #include "RightPaneWnd.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CLeftPaneWnd IMPLEMENT_DYNCREATE(CLeftPaneWnd, CView) CLeftPaneWnd::CLeftPaneWnd() { } CLeftPaneWnd::~CLeftPaneWnd() { } BEGIN_MESSAGE_MAP(CLeftPaneWnd, CView) //{{AFX_MSG_MAP(CLeftPaneWnd) ON_WM_ERASEBKGND() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CLeftPaneWnd drawing void CLeftPaneWnd::OnDraw(CDC* pDC) { CDocument* pDoc = GetDocument(); // TODO: add draw code here } ///////////////////////////////////////////////////////////////////////////// // CLeftPaneWnd diagnostics #ifdef _DEBUG void CLeftPaneWnd::AssertValid() const { CView::AssertValid(); } void CLeftPaneWnd::Dump(CDumpContext& dc) const { CView::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CLeftPaneWnd message handlers L_BOOL CLeftPaneWnd::LoadOverlays() { BITMAPHANDLE Bitmap; BITMAPHANDLE OverlayBitmap; BITMAPHANDLE TmpBitmap; L_UINT16 uRet; LILITEM Item; HCURSOR hCursor; L_CHAR szItemText [20]; LBitmap TmpLeadBitmap; CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd(); CRightPaneWnd* pRightPane = (CRightPaneWnd*)pFrame->m_wndSplitter.GetPane(0, 1); memset (&Item, 0, sizeof (LILITEM)); memset (&szItemText, 0, sizeof (szItemText)); pFrame->m_ImgList.Clear(); hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); /* Load the DICOM file data set*/ uRet = pFrame->m_DS.LoadDS (pFrame->m_szFileName, DS_LOAD_CLOSE); if (uRet != DICOM_SUCCESS) { SetCursor (hCursor); MessageBox(TEXT("Error loading data set."), TEXT("Error"), MB_OK|MB_ICONERROR); return FALSE; } pFrame->m_pElement = pFrame->m_DS.FindFirstElement(NULL, TAG_PIXEL_DATA, TRUE); if (pFrame->m_pElement != NULL) { // Set the general image list item properties Item.uStructSize = sizeof (LILITEM); Item.uBitmapStructSize = sizeof (BITMAPHANDLE); Item.pTextExt = pFrame->m_szFileName; Item.lData = 1; Item.uMask = LILITEM_ALL; uRet = pFrame->m_DS.GetImage( pFrame->m_pElement, &Bitmap, sizeof (BITMAPHANDLE), 0, 0, ORDER_BGR, DICOM_GETIMAGE_AUTO_LOAD_OVERLAYS | DICOM_GETIMAGE_AUTO_APPLY_MODALITY_LUT | DICOM_GETIMAGE_AUTO_APPLY_VOI_LUT, NULL, NULL); if (uRet != DICOM_SUCCESS) { pFrame->m_LeadBitmap.Free(); MessageBox ("Error retrieving image from pixel data element.", "Error", MB_OK|MB_ICONERROR); return FALSE; } TmpBitmap = Bitmap; pFrame->m_LeadBitmap.SetHandle (&Bitmap, FALSE); pFrame->m_uCount = pFrame->m_LeadBitmap.GetOverlayCount(0); if (pFrame->m_uCount < 1) { pRightPane->m_LBitmapWnd.Free(); MessageBox ("No overlays found in this file.", "Error", MB_OK|MB_ICONERROR); return FALSE; } // Load all overlays for (int i = 0; i < (L_INT)pFrame->m_uCount; i++) { uRet = pFrame->m_LeadBitmap.GetOverlay(i, &OverlayBitmap, sizeof(BITMAPHANDLE), OVERLAY_COPY); // Make the overlay preview looks clearer TmpLeadBitmap.SetHandle(&OverlayBitmap, TRUE); TmpLeadBitmap.Invert(); TmpLeadBitmap.Size(140, 140, SIZE_FAVORBLACK); TmpLeadBitmap.Invert(); Item.pBitmap = TmpLeadBitmap.GetHandle(); // Set each image list item text sprintf (szItemText, "Overlay %d", i); Item.pText = szItemText; Item.bSelected = (i == 0) ? TRUE : FALSE; // Select only the first item in the image list uRet = pFrame->m_ImgList.Insert(&Item, -1); pFrame->m_ImgList.EnsureVisible(pFrame->m_ImgList.GetItemCount()-1); } pRightPane->m_LBitmapWnd.SetHandle(&TmpBitmap, TRUE); } else { SetCursor (hCursor); MessageBox(TEXT("No Modules in this data set."), TEXT("Error"), MB_OK|MB_ICONERROR); return FALSE; } SetCursor (hCursor); return TRUE; } BOOL CLeftPaneWnd::OnEraseBkgnd(CDC* pDC) { // Set brush to desired background color CBrush backBrush(RGB(128, 128, 128)); // Save old brush CBrush* pOldBrush = pDC->SelectObject(&backBrush); CRect rect; pDC->GetClipBox(&rect); // Erase the area needed pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY); pDC->SelectObject(pOldBrush); return TRUE; } BOOL CLeftPaneWnd::OnCommand(WPARAM wParam, LPARAM lParam) { // what is the command and control if((L_INT)LOWORD(wParam) == IDC_IMGLISTCTRL) { switch(HIWORD(wParam)) { case L_ILN_ITEMSEL: OVERLAYATTRIBUTES OverlayAttributes; LILITEM Item; L_INT nRet; CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd(); memset (&Item, 0, sizeof (LILITEM)); Item.uStructSize = sizeof(LILITEM); Item.uBitmapStructSize = sizeof (BITMAPHANDLE); nRet = pFrame->m_ImgList.GetSelectedItems(&Item); pFrame->m_nSelItemIndex = Item.lIndex; // See if the OVERLAY_AUTOPAINT is on or off to update the "Show Overlay" menu item nRet = pFrame->m_LeadBitmap.GetOverlayAttributes(pFrame->m_nSelItemIndex, &OverlayAttributes, sizeof(OVERLAYATTRIBUTES), OVERLAYATTRIBUTES_FLAGS | OVERLAYATTRIBUTES_ORIGIN); if (OverlayAttributes.uFlags & OVERLAY_AUTOPAINT ) pFrame->m_bShowOverlay = TRUE; else pFrame->m_bShowOverlay = FALSE; break; } } return CView::OnCommand(wParam, lParam); } void CLeftPaneWnd::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd(); if (pFrame) { if(IsWindow(pFrame->m_wndSplitter)) { pFrame->m_wndSplitter.SetActivePane(0, 0, NULL); ::SetFocus(pFrame->m_hCtl); } } CView::OnActivateView(bActivate, pActivateView, pDeactiveView); }