Hide

SftDirectory 3.5 - ActiveX File/Folder Control

Display
Print

ControlStyles Sample (C++)

This sample demonstrates the control styles (ControlStyle property).

The source code is located at C:\Program Files (x86)\Softelvdm\SftDirectory 3.5\Samples\VC++\ControlStyles\ControlStylesDlg.cpp or C:\Program Files\Softelvdm\SftDirectory 3.5\Samples\VC++\ControlStyles\ControlStylesDlg.cpp (on 32-bit Windows versions).

// ControlStylesDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ControlStyles.h"
#include "ControlStylesDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CControlStylesDlg dialog

CControlStylesDlg::CControlStylesDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CControlStylesDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CControlStylesDlg)
        // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CControlStylesDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CControlStylesDlg)
    DDX_Control(pDX, IDC_CHECK_HEADERS, m_CheckShowHeaders);
    DDX_Control(pDX, IDC_CHECK_CHECKBOXES, m_CheckCheckBoxes);
    DDX_Control(pDX, IDC_CHECK_TREELINES, m_CheckTreeLines);
    DDX_Control(pDX, IDC_SFTDIRECTORYTV, m_SftDirectoryTV);
    DDX_Control(pDX, IDC_SFTDIRECTORYTV_COMBO, m_SftDirectoryTV_Combo);
    DDX_Control(pDX, IDC_SFTDIRECTORYDL, m_SftDirectoryDL);
    DDX_Control(pDX, IDC_SFTDIRECTORYDL_COMBO, m_SftDirectoryDL_Combo);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CControlStylesDlg, CDialog)
    //{{AFX_MSG_MAP(CControlStylesDlg)
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDC_CHECK_TREELINES, OnCheckTreelines)
    ON_BN_CLICKED(IDC_CHECK_CHECKBOXES, OnCheckCheckboxes)
    ON_BN_CLICKED(IDC_CHECK_HEADERS, OnCheckHeaders)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CControlStylesDlg message handlers

BOOL CControlStylesDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon


    CDC* pDC;
    pDC = GetDC();

    LOGFONT lf;
    CFont* pFont = GetFont();
    pFont->GetLogFont(&lf);

    LOGFONT lfNew = lf;
    lfNew.lfHeight = - MulDiv(10, pDC->GetDeviceCaps(LOGPIXELSY), 72);
    lfNew.lfWeight += (FW_BOLD-FW_NORMAL);
    m_FontBig.CreateFontIndirect(&lfNew);

    lfNew = lf;
    lfNew.lfHeight = - MulDiv(8, pDC->GetDeviceCaps(LOGPIXELSY), 72);
    lfNew.lfWeight += (FW_BOLD-FW_NORMAL);
    m_Font.CreateFontIndirect(&lfNew);

    ReleaseDC(pDC);

    GetDlgItem(IDC_TITLE)->SetFont(&m_FontBig);
    GetDlgItem(IDC_TITLE1)->SetFont(&m_Font);
    GetDlgItem(IDC_TITLE2)->SetFont(&m_Font);
    GetDlgItem(IDC_TITLE3)->SetFont(&m_Font);
    GetDlgItem(IDC_TITLE4)->SetFont(&m_Font);

    // use form's default font
    ISftDirectoryPtr vDirTV = m_SftDirectoryTV.GetControlUnknown();
    vDirTV->PutFontFont(NULL);
    vDirTV->Headers->PutFont(NULL);
    ISftDirectoryPtr vDirDL = m_SftDirectoryDL.GetControlUnknown();
    vDirDL->PutFont(NULL);
    vDirDL->Headers->PutFont(NULL);
    ISftDirectoryPtr vDirTV_Combo = m_SftDirectoryTV_Combo.GetControlUnknown();
    vDirTV_Combo->PutFont(NULL);
    vDirTV_Combo->Headers->PutFont(NULL);

    ISftDirectoryPtr vDirDL_Combo = m_SftDirectoryDL_Combo.GetControlUnknown();
    vDirDL_Combo->PutFont(NULL);
    vDirDL_Combo->Headers->PutFont(NULL);

    return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CControlStylesDlg::OnPaint()
{
    if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialog::OnPaint();
    }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CControlStylesDlg::OnQueryDragIcon()
{
    return (HCURSOR) m_hIcon;
}

void CControlStylesDlg::OnCheckTreelines()
{
    SftDirectoryTreeLineStyleConstants style;

    if (m_CheckTreeLines.GetCheck())
        style = treeLineStyleSftDirectoryDotted;
    else
        style = treeLineStyleSftDirectoryNone;

    ISftDirectoryPtr vDirTV = m_SftDirectoryTV.GetControlUnknown();
    vDirTV->TreeLineStyle = style;
    ISftDirectoryPtr vDirDL = m_SftDirectoryDL.GetControlUnknown();
    vDirDL->TreeLineStyle = style;
    ISftDirectoryPtr vDirTV_Combo = m_SftDirectoryTV_Combo.GetControlUnknown();
    vDirTV_Combo->TreeLineStyle = style;
    ISftDirectoryPtr vDirDL_Combo = m_SftDirectoryDL_Combo.GetControlUnknown();
    vDirDL_Combo->TreeLineStyle = style;
}

void CControlStylesDlg::OnCheckCheckboxes()
{
    SftDirectoryCheckBoxDisplayConstants style;

    if (m_CheckCheckBoxes.GetCheck())
        style = checkboxDisplaySftDirectoryAll;
    else
        style = checkboxDisplaySftDirectoryNone;

    ISftDirectoryPtr vDirTV = m_SftDirectoryTV.GetControlUnknown();
    vDirTV->ShowCheckBoxes = style;
    ISftDirectoryPtr vDirDL = m_SftDirectoryDL.GetControlUnknown();
    vDirDL->ShowCheckBoxes = style;
    ISftDirectoryPtr vDirTV_Combo = m_SftDirectoryTV_Combo.GetControlUnknown();
    vDirTV_Combo->ShowCheckBoxes = style;
    ISftDirectoryPtr vDirDL_Combo = m_SftDirectoryDL_Combo.GetControlUnknown();
    vDirDL_Combo->ShowCheckBoxes = style;
}

void CControlStylesDlg::OnCheckHeaders()
{
    SftDirectoryHeadersStyleConstants style;

    if (m_CheckShowHeaders.GetCheck())
        style = headersSftDirectoryButton;
    else
        style = headersSftDirectoryNone;

    ISftDirectoryPtr vDirTV = m_SftDirectoryTV.GetControlUnknown();
    vDirTV->Headers->Style = style;
    ISftDirectoryPtr vDirDL = m_SftDirectoryDL.GetControlUnknown();
    vDirDL->Headers->Style = style;
    ISftDirectoryPtr vDirTV_Combo = m_SftDirectoryTV_Combo.GetControlUnknown();
    vDirTV_Combo->Headers->Style = style;
    ISftDirectoryPtr vDirDL_Combo = m_SftDirectoryDL_Combo.GetControlUnknown();
    vDirDL_Combo->Headers->Style = style;
}

void CControlStylesDlg::OnCheckBoxClickedSftDirectoryTV(LPDISPATCH Folder, long OldValue, long FAR* NewValue)
{
    if (*NewValue != checkboxSftDirectoryNo && *NewValue != checkboxSftDirectoryYes)
        *NewValue = checkboxSftDirectoryYes;
    ISftDirectoryPtr vDirTV = m_SftDirectoryTV.GetControlUnknown();
    vDirTV->CurrentFolder->SetSubFolderCheckBoxes((SftDirectoryCheckBoxValueConstants) *NewValue, VARIANT_TRUE);
    vDirTV->CurrentFolder->CheckBox = (SftDirectoryCheckBoxValueConstants) *NewValue;
    vDirTV->RootFolder->EvaluateSubFolderCheckBoxes(VARIANT_TRUE);
}

void CControlStylesDlg::OnCheckBoxClickedSftDirectoryTVCombo(LPDISPATCH Folder, long OldValue, long FAR* NewValue)
{
    if (*NewValue != checkboxSftDirectoryNo && *NewValue != checkboxSftDirectoryYes)
        *NewValue = checkboxSftDirectoryYes;
    ISftDirectoryPtr vDirTV_Combo = m_SftDirectoryTV_Combo.GetControlUnknown();
    vDirTV_Combo->CurrentFolder->SetSubFolderCheckBoxes((SftDirectoryCheckBoxValueConstants) *NewValue, VARIANT_TRUE);
    vDirTV_Combo->CurrentFolder->CheckBox = (SftDirectoryCheckBoxValueConstants) *NewValue;
    vDirTV_Combo->RootFolder->EvaluateSubFolderCheckBoxes(VARIANT_TRUE);
}

BEGIN_EVENTSINK_MAP(CControlStylesDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CControlStylesDlg)
    ON_EVENT(CControlStylesDlg, IDC_SFTDIRECTORYTV, 2 /* CheckBoxClicked */, OnCheckBoxClickedSftDirectoryTV, VTS_DISPATCH VTS_I4 VTS_PI4)
    ON_EVENT(CControlStylesDlg, IDC_SFTDIRECTORYTV_COMBO, 2 /* CheckBoxClicked */, OnCheckBoxClickedSftDirectoryTVCombo, VTS_DISPATCH VTS_I4 VTS_PI4)
    //}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.