// ImageViewerPropDlg.cpp : implementation file // #include "stdafx.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CImageViewerPropDlg dialog CImageViewerPropDlg::CImageViewerPropDlg(LImageViewer *pImageViewer, CWnd* pParent /*=NULL*/) : CDialog(CImageViewerPropDlg::IDD, pParent) { memset(&m_ImageViewerProps, 0, sizeof(m_ImageViewerProps)); m_ImageViewerProps.uStructSize = sizeof(m_ImageViewerProps); m_pImageViewer = pImageViewer; //{{AFX_DATA_INIT(CImageViewerPropDlg) m_bShowFreeze = FALSE; m_bMaintainSize = FALSE; //}}AFX_DATA_INIT } void CImageViewerPropDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CImageViewerPropDlg) DDX_Control(pDX, IDBTN_CONPROP_ALL, m_AllCursor); DDX_Control(pDX, IDBTN_CONPROP_VERT, m_VertCursor); DDX_Control(pDX, IDBTN_CONPROP_HORZ, m_HorzCursor); DDX_Control(pDX, IDBTN_CONPROP_DEF, m_DefultCursor); DDX_Control(pDX, IDEDT_CONPROP_COLS, m_edtColumns); DDX_Control(pDX, IDEDT_CONPROP_ROWS, m_edtRow); DDX_Control(pDX, IDCMB_CONPROP_RULERSTYLE, m_cmbRulerStyle); DDX_Control(pDX, IDCMB_CONPROP_BORDERSTYLE, m_cmbBorderStyle); DDX_Control(pDX, IDCMB_CONPROP_TEXTQUALITY, m_cmbTextQulity); DDX_Check(pDX, IDCHK_CONPROP_FRZ, m_bShowFreeze); DDX_Check(pDX, IDCHK_CONPROP_MNTNSIZE, m_bMaintainSize); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CImageViewerPropDlg, CDialog) //{{AFX_MSG_MAP(CImageViewerPropDlg) ON_WM_PAINT() ON_BN_CLICKED(IDBTN_CONPROP_EMPTY, OnConPropEmpty) ON_BN_CLICKED(IDBTN_CONPROP_TEXT, OnConPropText) ON_BN_CLICKED(IDBTN_CONPROP_SHADOW, OnConPropShadow) ON_BN_CLICKED(IDBTN_CONPROP_ACTIVEBORDER, OnConPropActiveBorder) ON_BN_CLICKED(IDBTN_CONPROP_ACTIVESUBCELLBORDER, OnConPropActiveSubCellBorder) ON_BN_CLICKED(IDBTN_CONPROP_BACKGROUND, OnConPropBackground) ON_BN_CLICKED(IDBTN_CONPROP_RULERIN, OnConPropRulerIn) ON_BN_CLICKED(IDBTN_CONPROP_RULEROUT, OnConPropRulerout) ON_BN_CLICKED(IDBTN_CONPROP_NONACTIVE, OnConPropNonActive) ON_BN_CLICKED(IDBTN_CONPROP_DEF, OnConPropDef) ON_BN_CLICKED(IDBTN_CONPROP_HORZ, OnConPropHorz) ON_BN_CLICKED(IDBTN_CONPROP_VERT, OnConPropVert) ON_BN_CLICKED(IDBTN_CONPROP_ALL, OnConPropAll) ON_BN_CLICKED(IDAPPLY, OnApply) ON_BN_CLICKED(IDRESET, OnReset) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CImageViewerPropDlg message handlers void CImageViewerPropDlg::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); } int CImageViewerPropDlg::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; } COLORREF CImageViewerPropDlg:: 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; } BOOL CImageViewerPropDlg::OnInitDialog() { CDialog::OnInitDialog(); CString strVal; UpdateData(TRUE); m_ImageViewerProps.uMask = DCPF_ALL; if(m_pImageViewer) { m_pImageViewer->GetProperties(&m_ImageViewerProps, 0); } strVal.Format(TEXT("%d"), m_ImageViewerProps.uNumRows); m_edtRow.SetWindowText(strVal); strVal.Format(TEXT("%d"), m_ImageViewerProps.uNumCols); m_edtColumns.SetWindowText(strVal); m_cmbTextQulity.AddString(TEXT("Default quality")); m_cmbTextQulity.AddString(TEXT("Draft quality")); m_cmbTextQulity.AddString(TEXT("Proof quality")); m_cmbTextQulity.AddString(TEXT("Force draft")); m_cmbTextQulity.AddString(TEXT("Force Anti-aliasing")); m_cmbTextQulity.SetCurSel(m_ImageViewerProps.uTextQuality); m_cmbBorderStyle.AddString(TEXT("Solid")); m_cmbBorderStyle.AddString(TEXT("Dashed")); m_cmbBorderStyle.AddString(TEXT("Dotted")); m_cmbBorderStyle.AddString(TEXT("Dash-Dot")); m_cmbBorderStyle.AddString(TEXT("Dash-Dot-Dot")); m_cmbBorderStyle.SetCurSel(m_ImageViewerProps.uBorderStyle); m_cmbRulerStyle.AddString(TEXT("Inverted")); m_cmbRulerStyle.AddString(TEXT("Bordered")); m_cmbRulerStyle.SetCurSel(m_ImageViewerProps.uRulerStyle); m_bShowFreeze = m_ImageViewerProps.bShowFreezeText; m_bMaintainSize = !m_ImageViewerProps.uCellsMaintenance; m_edtRow.SetNumericEditBox(1, 4, 1, 0, 0); m_edtColumns.SetNumericEditBox(1, 8, 1, 0, 0); m_DefultCursor.SetCursor(m_ImageViewerProps.hDefaultCursor ? m_ImageViewerProps.hDefaultCursor : LoadCursor(NULL, IDC_ARROW)); m_HorzCursor.SetCursor(m_ImageViewerProps.hRszHorzCursor ? m_ImageViewerProps.hRszHorzCursor : LoadCursor(NULL, IDC_SIZEWE)); m_VertCursor.SetCursor(m_ImageViewerProps.hRszVertCursor ? m_ImageViewerProps.hRszVertCursor : LoadCursor(NULL, IDC_SIZENS)); m_AllCursor.SetCursor(m_ImageViewerProps.hRszBothCursor ? m_ImageViewerProps.hRszBothCursor : LoadCursor(NULL, IDC_SIZEALL)); UpdateData(FALSE); RedrawWindow(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CImageViewerPropDlg::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here RepaintButton(IDTXT_CONPROP_EMPTY, m_ImageViewerProps.crEmptyCellBackGroundColor); RepaintButton(IDTXT_CONPROP_TEXT, m_ImageViewerProps.crText); RepaintButton(IDTXT_CONPROP_SHADOW, m_ImageViewerProps.crShadow); RepaintButton(IDTXT_CONPROP_ACTIVEBORDER, m_ImageViewerProps.crActiveBorderColor); RepaintButton(IDTXT_CONPROP_ACTIVESUBCELLBORDER, m_ImageViewerProps.crActiveSubCellBorderColor); RepaintButton(IDTXT_CONPROP_BACKGROUND, m_ImageViewerProps.crBackground); RepaintButton(IDTXT_CONPROP_RULERIN, m_ImageViewerProps.crRulerIn); RepaintButton(IDTXT_CONPROP_RULEROUT, m_ImageViewerProps.crRulerout); RepaintButton(IDTXT_CONPROP_NONACTIVE, m_ImageViewerProps.crNonActiveBorderColor); } void CImageViewerPropDlg::OnConPropEmpty() { m_ImageViewerProps.crEmptyCellBackGroundColor = ShowColorDlg (m_ImageViewerProps.crEmptyCellBackGroundColor); RedrawWindow(); } void CImageViewerPropDlg::OnConPropText() { m_ImageViewerProps.crText = ShowColorDlg (m_ImageViewerProps.crText); RedrawWindow(); } void CImageViewerPropDlg::OnConPropShadow() { m_ImageViewerProps.crShadow = ShowColorDlg (m_ImageViewerProps.crShadow); RedrawWindow(); } void CImageViewerPropDlg::OnConPropActiveBorder() { m_ImageViewerProps.crActiveBorderColor = ShowColorDlg (m_ImageViewerProps.crActiveBorderColor); RedrawWindow(); } void CImageViewerPropDlg::OnConPropActiveSubCellBorder() { m_ImageViewerProps.crActiveSubCellBorderColor = ShowColorDlg (m_ImageViewerProps.crActiveSubCellBorderColor); RedrawWindow(); } void CImageViewerPropDlg::OnConPropBackground() { m_ImageViewerProps.crBackground = ShowColorDlg (m_ImageViewerProps.crBackground); RedrawWindow(); } void CImageViewerPropDlg::OnConPropRulerIn() { m_ImageViewerProps.crRulerIn = ShowColorDlg (m_ImageViewerProps.crRulerIn); RedrawWindow(); } void CImageViewerPropDlg::OnConPropRulerout() { m_ImageViewerProps.crRulerout = ShowColorDlg (m_ImageViewerProps.crRulerout); RedrawWindow(); } void CImageViewerPropDlg::OnConPropNonActive() { m_ImageViewerProps.crNonActiveBorderColor = ShowColorDlg (m_ImageViewerProps.crNonActiveBorderColor); RedrawWindow(); } void CImageViewerPropDlg::OnConPropDef() { TCHAR strFileName[MAX_PATH]; if(GetIconFileName(strFileName)) { m_ImageViewerProps.hDefaultCursor = LoadCursorFromFile(strFileName); m_DefultCursor.SetCursor(m_ImageViewerProps.hDefaultCursor); } } void CImageViewerPropDlg::OnConPropHorz() { TCHAR strFileName[MAX_PATH]; if(GetIconFileName(strFileName)) { m_ImageViewerProps.hRszHorzCursor = LoadCursorFromFile(strFileName); m_HorzCursor.SetCursor(m_ImageViewerProps.hRszHorzCursor); } } void CImageViewerPropDlg::OnConPropVert() { TCHAR strFileName[MAX_PATH]; if(GetIconFileName(strFileName)) { m_ImageViewerProps.hRszVertCursor = LoadCursorFromFile(strFileName); m_VertCursor.SetCursor(m_ImageViewerProps.hRszVertCursor); } } void CImageViewerPropDlg::OnConPropAll() { TCHAR strFileName[MAX_PATH]; if(GetIconFileName(strFileName)) { m_ImageViewerProps.hRszBothCursor = LoadCursorFromFile(strFileName); m_AllCursor.SetCursor(m_ImageViewerProps.hRszBothCursor); } } void CImageViewerPropDlg::OnApply() { CString strVal; UpdateData(TRUE); m_edtRow.GetWindowText(strVal); m_ImageViewerProps.uNumRows = max(1, _ttoi(strVal)); m_edtColumns.GetWindowText(strVal); m_ImageViewerProps.uNumCols = max(1, _ttoi(strVal)); m_ImageViewerProps.uCellsMaintenance = !m_bMaintainSize; m_ImageViewerProps.bShowFreezeText = m_bShowFreeze; m_ImageViewerProps.uBorderStyle = m_cmbBorderStyle.GetCurSel(); m_ImageViewerProps.uTextQuality = m_cmbTextQulity.GetCurSel(); m_ImageViewerProps.uRulerStyle = m_cmbRulerStyle.GetCurSel(); if(m_pImageViewer) { m_pImageViewer->SetProperties(&m_ImageViewerProps, 0); } UpdateData(FALSE); } void CImageViewerPropDlg::OnOK() { OnApply(); CDialog::OnOK(); } void CImageViewerPropDlg::OnReset() { CString strVal; UpdateData(TRUE); memset(&m_ImageViewerProps, 0, sizeof(DISPCONTAINERPROPERTIES)); m_ImageViewerProps.uStructSize = sizeof(DISPCONTAINERPROPERTIES); m_ImageViewerProps.uMask = DCPF_ALL; m_ImageViewerProps.uNumRows = 1; strVal.Format(TEXT("%d"), m_ImageViewerProps.uNumRows); m_edtRow.SetWindowText(strVal); m_ImageViewerProps.uNumCols = 2; strVal.Format(TEXT("%d"), m_ImageViewerProps.uNumCols); m_edtColumns.SetWindowText(strVal); DestroyCursor(m_ImageViewerProps.hDefaultCursor); DestroyCursor(m_ImageViewerProps.hRszHorzCursor); DestroyCursor(m_ImageViewerProps.hRszVertCursor); DestroyCursor(m_ImageViewerProps.hRszBothCursor); m_DefultCursor.SetCursor(LoadCursor(NULL, IDC_ARROW)); m_HorzCursor.SetCursor(LoadCursor(NULL, IDC_SIZEWE)); m_VertCursor.SetCursor(LoadCursor(NULL, IDC_SIZENS)); m_AllCursor.SetCursor(LoadCursor(NULL, IDC_SIZEALL)); m_ImageViewerProps.uTextQuality = 0; m_cmbTextQulity.SetCurSel(m_ImageViewerProps.uTextQuality); m_ImageViewerProps.uBorderStyle = PS_DOT; m_cmbBorderStyle.SetCurSel(m_ImageViewerProps.uBorderStyle); m_ImageViewerProps.uRulerStyle = DCPF_RULERSTYLE_INVERT; m_cmbRulerStyle.SetCurSel(m_ImageViewerProps.uRulerStyle); m_ImageViewerProps.crActiveBorderColor = RGB(255, 192, 0); m_ImageViewerProps.crActiveSubCellBorderColor = RGB(255, 255, 0); m_ImageViewerProps.crBackground = RGB(0, 0, 0); m_ImageViewerProps.crEmptyCellBackGroundColor = RGB(0, 0, 0); m_ImageViewerProps.crNonActiveBorderColor = RGB(255, 255, 255); m_ImageViewerProps.crRulerIn = RGB(255, 255, 255); m_ImageViewerProps.crRulerout = RGB(0, 0, 255); m_ImageViewerProps.crText = RGB(255, 255, 255); m_ImageViewerProps.crShadow = RGB(0, 0, 0); m_bMaintainSize = FALSE; m_ImageViewerProps.uCellsMaintenance = DCPF_CELLSMAINTENANCE_SIZE; m_ImageViewerProps.bShowFreezeText = TRUE; m_bShowFreeze = m_ImageViewerProps.bShowFreezeText; m_pImageViewer->SetProperties(&m_ImageViewerProps, 0); UpdateData(FALSE); RedrawWindow(); }