// WinLevelPrpoDlg.cpp : implementation file // #include "stdafx.h" #include "imgconvw.h" #include "WinLevelPrpoDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CWinLevelPrpoDlg dialog CWinLevelPrpoDlg::CWinLevelPrpoDlg(LImageViewer *pImageViewer, CWnd* pParent /*=NULL*/) : CDialog(CWinLevelPrpoDlg::IDD, pParent) { m_pImageViewer = pImageViewer; memset(&m_WindowLevelProp, 0, sizeof(DISPWLEVELACTIONPROPS)); m_WindowLevelProp.DispContainerActionProps.uStructSize = sizeof(DISPWLEVELACTIONPROPS); //{{AFX_DATA_INIT(CWinLevelPrpoDlg) m_uSensitivity = 0; m_bCircleMouse = FALSE; //}}AFX_DATA_INIT } void CWinLevelPrpoDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CWinLevelPrpoDlg) DDX_Control(pDX, IDEDT_WLACTION_CENTER, m_edtCenter); DDX_Control(pDX, IDEDT_WLACTION_WIDTH, m_edtWidth); DDX_Control(pDX, IDEDT_WLACTION_SUBCELLINDEX, m_edtSubCellIndex); DDX_Control(pDX, IDEDT_WLACTION_CELLINDEX, m_edtCellIndex); DDX_Control(pDX, IDCMB_WLACTION_MOD, m_cmbModifier); DDX_Control(pDX, IDCMB_WLACTION_DOWNKEY, m_cmbDownKey); DDX_Control(pDX, IDCMB_WLACTION_RIGHTKEY, m_cmbRightKey); DDX_Control(pDX, IDCMB_WLACTION_LEFTKEY, m_cmbLeftKey); DDX_Control(pDX, IDCMB_WLACTION_UPKEY, m_cmbUpKey); DDX_Control(pDX, IDBTN_WLACTION_CUR, m_ActionCursor); DDX_Control(pDX, IDCMB_WLACTION_FILLTYPE, m_cmbFillType); DDX_Control(pDX, IDCMB_WLACTION_SUBCELLINDEX, m_cmbSubCellIndex); DDX_Control(pDX, IDCMB_WLACTION_CELLINDEX, m_cmbCell); DDX_Text(pDX, IDEDT_WLACTION_SEN, m_uSensitivity); DDX_Check(pDX, IDCHK_WLACTION_CIRCLE, m_bCircleMouse); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CWinLevelPrpoDlg, CDialog) //{{AFX_MSG_MAP(CWinLevelPrpoDlg) ON_BN_CLICKED(IDBTN_WLACTION_CUR, OnWLActionCur) ON_BN_CLICKED(IDAPPLY, OnApply) ON_EN_CHANGE(IDEDT_WLACTION_CELLINDEX, OnChangeWLActionCellIndex) ON_CBN_SELCHANGE(IDCMB_WLACTION_CELLINDEX, OnSelchangeWLActionCellIndex) ON_CBN_SELCHANGE(IDCMB_WLACTION_SUBCELLINDEX, OnSelChangeWLActionSubCellIndex) ON_EN_CHANGE(IDEDT_WLACTION_SUBCELLINDEX, OnChangeWLActionSubCellIndex) ON_WM_PAINT() ON_BN_CLICKED(IDBTN_WLACTION_CLRIN, OnWLActionClrIn) ON_BN_CLICKED(IDBTN_WLACTION_CLROUT, OnWLActionClrOut) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CWinLevelPrpoDlg message handlers BOOL CWinLevelPrpoDlg::OnInitDialog() { CDialog::OnInitDialog(); L_INT nIndex; L_INT nCount =0; CString strVal; L_INT nListCount =0; HBITMAPLIST hBitmapList = NULL; LBitmapList BitmapList; nCount = (m_pImageViewer ? m_pImageViewer->GetCellCount(0) : 0); for (nIndex = 0; nIndex < nCount; nIndex++) { if(m_pImageViewer) { if (m_pImageViewer->IsCellSelected(nIndex,0)) break; } } if (nIndex == nCount) nIndex = -1; m_pImageViewer->GetActionProperties(CONTAINER_ACTION_WINDOWLEVEL, max(0,nIndex), 0, (LONG)&m_WindowLevelProp, CONTAINER_ACTION_CONTAINERLEVEL); m_pImageViewer->GetActionProperties(CONTAINER_ACTION_WINDOWLEVEL, max(0,nIndex), 0, (LONG)&m_WindowLevelProp, CONTAINER_ACTION_CELLLEVEL); strVal.Format(TEXT("%d"), max(0,nIndex)); m_edtCellIndex.SetWindowText(strVal); strVal.Format(TEXT("%d"), max(0,nIndex)); m_edtSubCellIndex.SetWindowText(strVal); strVal.Format(TEXT("%d"), m_WindowLevelProp.nWidth); m_edtWidth.SetWindowText(strVal); strVal.Format(TEXT("%d"), m_WindowLevelProp.nCenter); m_edtCenter.SetWindowText(strVal); m_crColorIn = m_WindowLevelProp.rgbColorStart; m_crColorOut = m_WindowLevelProp.rgbColorEnd; m_edtCellIndex.SetNumericEditBox(0, nCount - 1, 1, 0, 0); m_pImageViewer->GetCellBitmapList(nIndex, &hBitmapList, 0); if(hBitmapList) { BitmapList.SetHandle(hBitmapList); nListCount = BitmapList.GetItemsCount(); } m_edtSubCellIndex.SetNumericEditBox(0, nListCount - 1, 1, 0, 0); m_edtWidth.SetNumericEditBox(1, 0xffff, 1, 0, 0); m_edtCenter.SetNumericEditBox(-0xffff, 0xffff, 1, 0, 0); BitmapList.SetHandle(NULL,0,0); if (!nCount) { m_cmbCell.EnableWindow(FALSE); m_cmbSubCellIndex.EnableWindow(FALSE); } m_cmbSubCellIndex.EnableWindow(FALSE); m_edtSubCellIndex.EnableWindow(FALSE); m_edtCellIndex.EnableWindow(FALSE); m_edtWidth.EnableWindow(FALSE); m_edtCenter.EnableWindow(FALSE); m_cmbFillType.EnableWindow(FALSE); m_cmbCell.AddString(TEXT("None")); m_cmbCell.AddString(TEXT("All")); m_cmbCell.AddString(TEXT("Custom")); m_cmbCell.SetCurSel(0); m_cmbSubCellIndex.AddString(TEXT("All")); m_cmbSubCellIndex.AddString(TEXT("Custom")); m_cmbSubCellIndex.SetCurSel(0); m_cmbFillType.AddString(TEXT("Linear")); m_cmbFillType.AddString(TEXT("Exponential")); m_cmbFillType.AddString(TEXT("Logarithmic")); m_cmbFillType.AddString(TEXT("Sigmoid")); m_cmbFillType.SetCurSel(max((L_INT)0, (L_INT)((m_WindowLevelProp.uFillType) >> 4) - 1)); CImgConVwApp::AddSupString(&m_cmbModifier); CImgConVwApp::AddVirtualKeyString(&m_cmbUpKey); CImgConVwApp::AddVirtualKeyString(&m_cmbDownKey); CImgConVwApp::AddVirtualKeyString(&m_cmbLeftKey); CImgConVwApp::AddVirtualKeyString(&m_cmbRightKey); GetKeyboardAction(&m_cmbUpKey, &m_cmbModifier, CONTAINER_ACTION_WINDOWLEVEL, CONTAINER_MOUSEMOVE_UP); GetKeyboardAction(&m_cmbLeftKey, &m_cmbModifier, CONTAINER_ACTION_WINDOWLEVEL, CONTAINER_MOUSEMOVE_LEFT); GetKeyboardAction(&m_cmbRightKey, &m_cmbModifier, CONTAINER_ACTION_WINDOWLEVEL, CONTAINER_MOUSEMOVE_RIGHT); GetKeyboardAction(&m_cmbDownKey, &m_cmbModifier, CONTAINER_ACTION_WINDOWLEVEL, CONTAINER_MOUSEMOVE_DOWN); m_ActionCursor.SetCheck(m_WindowLevelProp.DispContainerActionProps.bCircularMouseMove); m_uSensitivity = m_WindowLevelProp.DispContainerActionProps.nChange; m_bCircleMouse = m_WindowLevelProp.DispContainerActionProps.bCircularMouseMove; m_ActionCursor.SetIcon(m_WindowLevelProp.DispContainerActionProps.hCursor ? m_WindowLevelProp.DispContainerActionProps.hCursor : LoadCursor(NULL, IDC_ARROW)); m_hOldCursor = m_WindowLevelProp.DispContainerActionProps.hCursor; UpdateData(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } L_VOID CWinLevelPrpoDlg::GetKeyboardAction(CComboBox * pVComboBox, CComboBox * pModComboBox, L_INT nAction, L_INT nMouseDirection) { L_UINT uVk, uModifier; m_pImageViewer->GetKeyboardAction(nAction, nMouseDirection, &uVk, &uModifier, 0); for(int i=0;i< pVComboBox->GetCount(); ++i) { if(pVComboBox->GetItemData(i) == uVk) { pVComboBox->SetCurSel(i); break; } } pModComboBox->SetCurSel(min(3, uModifier)); } int CWinLevelPrpoDlg::GetIconFileName(L_TCHAR * m_FileName) { L_INT nRet; OPENFILENAME OpenFileName; memset(&OpenFileName, 0, sizeof(OPENFILENAME)); memset(m_FileName, 0, MAX_PATH * sizeof(TCHAR)); OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.lpstrFilter = TEXT("Cursors(*.cur)\0 *.cur"); OpenFileName.nMaxCustFilter = 12; OpenFileName.hwndOwner = this->GetSafeHwnd(); OpenFileName.lpstrTitle = TEXT("Open a File"); OpenFileName.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT; OpenFileName.lpstrFile = m_FileName; OpenFileName.nMaxFile = MAX_PATH; nRet = GetOpenFileName(&OpenFileName); return nRet; } void CWinLevelPrpoDlg::OnWLActionCur() { TCHAR strFileName[MAX_PATH]; if(GetIconFileName(strFileName)) { m_ActionCursor.SetCursor(LoadCursorFromFile(strFileName)); } } void CWinLevelPrpoDlg::OnOK() { OnApply(); CDialog::OnOK(); } void CWinLevelPrpoDlg::OnApply() { CString strVal; L_INT nRet; L_INT nVk; L_UINT uState = (8 >> (4 - m_cmbModifier.GetCurSel())); L_INT nIndex=0; L_INT nSubIndex=0; UpdateData(TRUE); m_WindowLevelProp.rgbColorStart = m_crColorIn; m_WindowLevelProp.rgbColorEnd = m_crColorOut; m_WindowLevelProp.DispContainerActionProps.bCircularMouseMove = m_bCircleMouse; m_WindowLevelProp.DispContainerActionProps.nChange = m_uSensitivity; m_WindowLevelProp.DispContainerActionProps.hCursor = m_ActionCursor.GetIcon(); nRet = m_pImageViewer->SetActionProperties(CONTAINER_ACTION_WINDOWLEVEL, nIndex, nSubIndex, (LONG)&m_WindowLevelProp, CONTAINER_ACTION_CONTAINERLEVEL); nRet = m_cmbCell.GetCurSel(); if (nRet != 0) { m_edtCenter.GetWindowText(strVal); m_WindowLevelProp.nCenter = _ttoi(strVal); m_edtWidth.GetWindowText(strVal); m_WindowLevelProp.nWidth = _ttoi(strVal); m_WindowLevelProp.uFillType = (m_cmbFillType.GetCurSel() + 1) << 4; if (nRet == 1) { nIndex = -1; } else { m_edtCellIndex.GetWindowText(strVal); nIndex = _ttoi(strVal); } nRet = m_cmbSubCellIndex.GetCurSel(); if (nRet == 0) nSubIndex = -1; else { m_edtSubCellIndex.GetWindowText(strVal); nSubIndex = _ttoi(strVal); } nRet = m_pImageViewer->SetActionProperties(CONTAINER_ACTION_WINDOWLEVEL, nIndex, nSubIndex, (LONG)&m_WindowLevelProp, CONTAINER_ACTION_CELLLEVEL); } nVk = CImgConVwApp::GetVirtualKey(&m_cmbUpKey); if (nVk != 0) m_pImageViewer->SetKeyboardAction(CONTAINER_ACTION_WINDOWLEVEL, CONTAINER_MOUSEMOVE_UP, nVk, uState); nVk = CImgConVwApp::GetVirtualKey(&m_cmbDownKey); if (nVk != 0) m_pImageViewer->SetKeyboardAction(CONTAINER_ACTION_WINDOWLEVEL, CONTAINER_MOUSEMOVE_LEFT, nVk, uState); nVk = CImgConVwApp::GetVirtualKey(&m_cmbLeftKey); if (nVk != 0) m_pImageViewer->SetKeyboardAction(CONTAINER_ACTION_WINDOWLEVEL, CONTAINER_MOUSEMOVE_RIGHT, nVk, uState); nVk = CImgConVwApp::GetVirtualKey(&m_cmbRightKey); if (nVk != 0) m_pImageViewer->SetKeyboardAction(CONTAINER_ACTION_WINDOWLEVEL, CONTAINER_MOUSEMOVE_DOWN, nVk, uState); UpdateData(FALSE); } void CWinLevelPrpoDlg::OnChangeWLActionCellIndex() { L_INT nCellIndex =0, nSubCellIndex =0, nListCount=0; CString strVal; HBITMAPLIST hBitmapList; LBitmapList BitmapList; m_edtCellIndex.GetWindowText(strVal); nCellIndex = _ttoi(strVal); m_edtSubCellIndex.GetWindowText(strVal); nSubCellIndex = _ttoi(strVal); m_pImageViewer->GetActionProperties(CONTAINER_ACTION_WINDOWLEVEL, nCellIndex, nSubCellIndex, (LONG)&m_WindowLevelProp, CONTAINER_ACTION_CELLLEVEL); strVal.Format(TEXT("%d"), m_WindowLevelProp.nWidth); m_edtWidth.SetWindowText(strVal); strVal.Format(TEXT("%d"), m_WindowLevelProp.nCenter); m_edtCenter.SetWindowText(strVal); m_cmbFillType.SetCurSel((m_WindowLevelProp.uFillType - 1) >> 4); m_pImageViewer->GetCellBitmapList(nCellIndex, &hBitmapList, 0); BitmapList.SetHandle(hBitmapList); nListCount = BitmapList.GetItemsCount(); m_edtSubCellIndex.SetNumericEditBox(0, nListCount - 1, 1, 0, 0); BitmapList.SetHandle(NULL,0,0); } void CWinLevelPrpoDlg::OnSelchangeWLActionCellIndex() { L_INT nRet = m_cmbCell.GetCurSel(); m_edtCellIndex.EnableWindow(nRet == 2); m_cmbSubCellIndex.EnableWindow((nRet != 0)); m_edtSubCellIndex.EnableWindow((nRet != 0) && (m_cmbSubCellIndex.GetCurSel())); m_edtWidth.EnableWindow(nRet != 0); m_edtCenter.EnableWindow(nRet != 0); m_cmbFillType.EnableWindow(nRet != 0); } void CWinLevelPrpoDlg::OnSelChangeWLActionSubCellIndex() { m_edtSubCellIndex.EnableWindow((m_cmbSubCellIndex.GetCurSel() == 1)); } void CWinLevelPrpoDlg::OnChangeWLActionSubCellIndex() { L_INT nCellIndex =0, nSubCellIndex =0; CString strVal; UpdateData(TRUE); m_edtCellIndex.GetWindowText(strVal); nCellIndex = _ttoi(strVal); m_edtSubCellIndex.GetWindowText(strVal); nSubCellIndex = _ttoi(strVal); m_pImageViewer->GetActionProperties(CONTAINER_ACTION_WINDOWLEVEL, nCellIndex, nSubCellIndex, (LONG)&m_WindowLevelProp, CONTAINER_ACTION_CELLLEVEL); strVal.Format(TEXT("%d"), m_WindowLevelProp.nWidth); m_edtWidth.SetWindowText(strVal); strVal.Format(TEXT("%d"), m_WindowLevelProp.nCenter); m_edtCenter.SetWindowText(strVal); m_cmbFillType.SetCurSel((m_WindowLevelProp.uFillType - 1) >> 4); UpdateData(FALSE); } COLORREF CWinLevelPrpoDlg :: ShowColorDlg (COLORREF crInitial) { LDialogColor DlgColor; COLORDLGPARAMS DlgParams; memset ( &DlgParams, 0, sizeof ( COLORDLGPARAMS ) ) ; DlgParams.uStructSize = sizeof ( COLORDLGPARAMS ) ; DlgParams.crColor = crInitial; DlgParams.uColorSpace = DLG_COLOR_COLORSPACE_SHOW_RGB; DlgParams.uDlgFlags = DLG_COLOR_SHOW_OLDCOLOR | DLG_COLOR_SHOW_NEWCOLOR | DLG_COLOR_SHOW_NAME | DLG_COLOR_COLORSPACE_SHOW_HUE | DLG_COLOR_COLORSPACE_SHOW_BRIGHTNESS | DLG_COLOR_COLORSPACE_SHOW_WHEEL | DLG_COLOR_COLORSPACE_SHOW_RGB | DLG_COLOR_COLORSPACE_SHOW_CMY | DLG_COLOR_COLORSPACE_SHOW_CMYK | DLG_COLOR_COLORSPACE_SHOW_LAB | DLG_COLOR_COLORMODEL_SHOW_RGB | DLG_COLOR_COLORMODEL_SHOW_HSB | DLG_COLOR_COLORMODEL_SHOW_HLS | DLG_COLOR_COLORMODEL_SHOW_CMY | DLG_COLOR_COLORMODEL_SHOW_CMYK | DLG_COLOR_COLORMODEL_SHOW_LAB ; DlgColor.SetColorParams(&DlgParams) ; DlgColor.DoModalColor(this->GetSafeHwnd()); // Gets the updated values for the structure DlgColor.GetColorParams(&DlgParams, sizeof(DlgParams)) ; return DlgParams.crColor; } void CWinLevelPrpoDlg ::RepaintButton(L_INT id ,COLORREF ColorRef) { HBRUSH hNewBrush,hOldBrush; CDC *pcdc; RECT rect; PAINTSTRUCT ps; pcdc = GetDlgItem(id)->BeginPaint(&ps); GetDlgItem(id)->GetClientRect(&rect); hNewBrush = CreateSolidBrush (ColorRef); hOldBrush = (HBRUSH) SelectObject (pcdc->GetSafeHdc(), hNewBrush); Rectangle (pcdc->GetSafeHdc(), rect.left, rect.top, rect.right, rect.bottom); SelectObject(pcdc->GetSafeHdc(), hOldBrush); DeleteObject (hNewBrush); GetDlgItem(id)->EndPaint(&ps); } void CWinLevelPrpoDlg::OnPaint() { CPaintDC dc(this); // device context for painting RepaintButton(IDC_WLACTION_CLRIN_TXT, m_crColorIn); RepaintButton(IDC_WLACTION_CLROUT_TXT,m_crColorOut); } void CWinLevelPrpoDlg::OnWLActionClrIn() { m_crColorIn = ShowColorDlg (m_crColorIn); RedrawWindow(); } void CWinLevelPrpoDlg::OnWLActionClrOut() { m_crColorOut = ShowColorDlg (m_crColorOut); RedrawWindow(); }