Hide

SftButton/OCX 3.0 - Button Control

Display
Print

Special Sample (C++)

This sample illustrates special effects.

The source code is located at C:\Program Files (x86)\Softelvdm\SftButton OCX 3.0\Samples\VC++\Special\SpecialDlg.cpp or C:\Program Files\Softelvdm\SftButton OCX 3.0\Samples\VC++\Special\SpecialDlg.cpp (on 32-bit Windows versions).

// SpecialDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Special.h"
#include "SpecialDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSpecialDlg dialog

CSpecialDlg::CSpecialDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CSpecialDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CSpecialDlg)
        // 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);

    for (int i = 0 ; i < WORLDBITMAPS ; ++i ) {
        m_World[i].LoadBitmap(IDB_WORLD1+i);
        ASSERT(m_World[i].m_hObject);
    }
    m_WorldIndex = 0;
}

void CSpecialDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CSpecialDlg)
    DDX_Control(pDX, IDC_TITLE, m_Title);
    DDX_Control(pDX, IDC_SFTBTN1, m_Button1);
    DDX_Control(pDX, IDC_SFTBTN2, m_Button2);
    DDX_Control(pDX, IDC_SFTBTN3, m_Button3);
    DDX_Control(pDX, IDC_SFTBTN4, m_Button4);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSpecialDlg, CDialog)
    //{{AFX_MSG_MAP(CSpecialDlg)
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_WM_TIMER()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSpecialDlg message handlers

BOOL CSpecialDlg::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

    // Make a bold font for the dialog title
    CFont* pFont = GetFont(); // get dialog font
    LOGFONT lf;
    pFont->GetLogFont(&lf);
    lf.lfWeight += (FW_BOLD-FW_NORMAL);
    m_BoldFont.CreateFontIndirect(&lf);

    m_Title.SetFont(&m_BoldFont);

    // Get all ISftButton interface pointers for access to all
    // properties and methods (see Using SftButton/OCX with Visual C++
    // in the online help for more information)
    m_vButton1 = m_Button1.GetControlUnknown();
    m_vButton2 = m_Button2.GetControlUnknown();
    m_vButton3 = m_Button3.GetControlUnknown();
    m_vButton4 = m_Button4.GetControlUnknown();

    SetImage();             // set the first image (spinning globe)
    SetTimer(IDC_SFTBTN2, 200, NULL);// timer for button2 (spinning globe)
    SetTimer(IDC_SFTBTN3, 300, NULL);// timer for button3 (alternating border)
    SetTimer(IDC_SFTBTN4, 500, NULL);// timer for button4 (button/dropdown toggle)

    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 CSpecialDlg::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 CSpecialDlg::OnQueryDragIcon()
{
    return (HCURSOR) m_hIcon;
}

void CSpecialDlg::SetImage()
{
    // Update the button with the next bitmap in the m_World bitmap
    // array to get the spinning globe effect

    PICTDESC pictDesc;
    pictDesc.cbSizeofstruct = sizeof(pictDesc);
    pictDesc.picType = PICTYPE_BITMAP;
    pictDesc.bmp.hbitmap = (HBITMAP) m_World[m_WorldIndex].m_hObject;

    IPicture* pPic;
    HRESULT hr = ::OleCreatePictureIndirect(&pictDesc, IID_IPicture, FALSE, (void**)&pPic);
    ASSERT(SUCCEEDED(hr));
    if (FAILED(hr)) return;

    IPictureDispPtr pPicDisp = pPic;

    ISftPictureObjectPtr pImg;
    hr = m_vButton2->get_Image1(&pImg);
    ASSERT(SUCCEEDED(hr));

    hr = pImg->putref_Picture(pPicDisp);
    ASSERT(SUCCEEDED(hr));

    ++m_WorldIndex;
    if (m_WorldIndex >= WORLDBITMAPS) m_WorldIndex = 0;
}

void CSpecialDlg::ChangeBorder()
{
    // Change the button border
    if (m_vButton3->Pressed || m_vButton3->GetDarkEdgeColor() != (0x80000000L|COLOR_3DDKSHADOW)) {
        m_vButton3->PutDarkEdgeColor(0x80000000L|COLOR_3DDKSHADOW);
        m_vButton3->PutShadowEdgeColor(0x80000000L|COLOR_3DSHADOW);
        m_vButton3->PutLightEdgeColor(0x80000000L|COLOR_3DLIGHT);
        m_vButton3->PutWhiteEdgeColor(0x80000000L|COLOR_3DHILIGHT);
    } else {
        m_vButton3->PutDarkEdgeColor(0x80000000L|COLOR_3DHILIGHT);
        m_vButton3->PutShadowEdgeColor(0x80000000L|COLOR_3DHILIGHT);
        m_vButton3->PutLightEdgeColor(0x80000000L|COLOR_3DHILIGHT);
        m_vButton3->PutWhiteEdgeColor(0x80000000L|COLOR_3DHILIGHT);
    }
}

void CSpecialDlg::ToggleButton()
{
    // Toggle the button and drop down button state
    if (m_vButton4->Pressed) {
        if (m_vButton4->DropDownPressed)
            m_vButton4->Pressed = VARIANT_FALSE;
        else
            m_vButton4->DropDownPressed = VARIANT_TRUE;
    } else {
        if (m_vButton4->DropDownPressed)
            m_vButton4->DropDownPressed = VARIANT_FALSE;
        else
            m_vButton4->Pressed = VARIANT_TRUE;
    }
}

void CSpecialDlg::OnTimer(UINT_PTR nIDEvent)
{
    if (nIDEvent == IDC_SFTBTN2)
        SetImage();
    else if (nIDEvent == IDC_SFTBTN3)
        ChangeBorder();
    else if (nIDEvent == IDC_SFTBTN4)
        ToggleButton();

    CDialog::OnTimer(nIDEvent);
}

void CSpecialDlg::OnHoverOnSftbtn1()
{
    // The cursor is over the button, change the font
    // and button text
    IFontPtr pFont = m_vButton1->GetFont();
    pFont->put_Underline(TRUE);
    m_vButton1->Text = _bstr_t("Click Me, Please");

}

void CSpecialDlg::OnHoverOffSftbtn1()
{
    // The cursor has left the button, change the font
    // and button text back to their original settings
    IFontPtr pFont = m_vButton1->GetFont();
    pFont->put_Underline(FALSE);
    m_vButton1->Text = _bstr_t("Click Me");
}

BEGIN_EVENTSINK_MAP(CSpecialDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CSpecialDlg)
    ON_EVENT(CSpecialDlg, IDC_SFTBTN1, 7 /* HoverOn */, OnHoverOnSftbtn1, VTS_NONE)
    ON_EVENT(CSpecialDlg, IDC_SFTBTN1, 6 /* HoverOff */, OnHoverOffSftbtn1, VTS_NONE)
    //}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

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