// LeftPaneWnd.cpp : implementation file // #include "stdafx.h" #include "Overlay.h" #include "LeftPaneWnd.h" #include "RightPaneWnd.h" #include "MainFrm.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 OverlayBitmap; L_UINT16 uRet; LILITEM Item; HCURSOR hCursor; L_CHAR szItemText [20]; CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd(); CRightPaneWnd* pRightPane = (CRightPaneWnd*)pFrame->m_wndSplitter.GetPane(0, 1); memset (&Item, 0, sizeof (LILITEM)); memset (&szItemText, 0, sizeof (szItemText)); L_ImgListClear(pFrame->m_hCtl); hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); /* Load the DICOM file data set*/ uRet = L_DicomLoadDS(pFrame->m_hDS, pFrame->m_szFileName, DS_LOAD_CLOSE); if (uRet != DICOM_SUCCESS) { SetCursor (hCursor); MessageBox(TEXT("Error loading data set."), TEXT("Error"), MB_OK|MB_ICONERROR); L_DicomResetDS (pFrame->m_hDS); return FALSE; } pFrame->m_pElement = L_DicomFindFirstElement(pFrame->m_hDS, 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 = L_DicomGetImage( pFrame->m_hDS, pFrame->m_pElement, &pFrame->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) { MessageBox ("Error retrieving image from pixel data element.", "Error", MB_OK|MB_ICONERROR); return FALSE; } uRet = L_GetOverlayCount (&pFrame->Bitmap, &pFrame->m_uCount, 0); if (pFrame->m_uCount < 1) { MessageBox ("This dataset has no overlays.\nTo insert a new overlay, please select \"Overlays\\ Insert Overlay\" from the menu.", "Note", MB_OK); } // Load all overlays for (int i = 0; i < (L_INT)pFrame->m_uCount; i++) { uRet = L_GetOverlayBitmap(&pFrame->Bitmap, i, &OverlayBitmap, sizeof(BITMAPHANDLE), OVERLAY_COPY); Item.pBitmap = &OverlayBitmap; // Make the overlay preview looks clearer uRet = L_InvertBitmap (Item.pBitmap); uRet = L_SizeBitmap (Item.pBitmap, 140, 140, SIZE_FAVORBLACK); uRet = L_InvertBitmap (Item.pBitmap); // 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 L_ImgListInsert(pFrame->m_hCtl, &Item); L_ImgListEnsureVisible(pFrame->m_hCtl, L_ImgListGetItemCount(pFrame->m_hCtl)-1); } ::PostMessage(pRightPane->m_hWnd, WM_SIZE, 0, 0); } else { SetCursor (hCursor); L_DicomResetDS (pFrame->m_hDS); 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 = L_ImgListGetSelItems (pFrame->m_hCtl, &Item); pFrame->m_nSelItemIndex = Item.lIndex; // See if the OVERLAY_AUTOPAINT is on or off to update the "Show Overlay" menu item nRet = L_GetOverlayAttributes(&pFrame->Bitmap, 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); }