Hide

SftButton/OCX 3.0 - Button Control

Display
Print

Animations Sample (C++)

This sample illustrates AVI animations with AVIPlay method.

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

// AnimationsDlg.cpp : implementation file
//

#include "stdafx.h"

#include "Animations.h"
#include "AnimationsDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAnimationsDlg dialog

CAnimationsDlg::CAnimationsDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CAnimationsDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CAnimationsDlg)
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CAnimationsDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAnimationsDlg)
    DDX_Control(pDX, IDC_TITLE, m_Title);
    DDX_Control(pDX, IDC_SFTBUTTONDOWNLOAD, m_DownloadButton);
    DDX_Control(pDX, IDC_SFTBUTTONFIND, m_FindButton);
    DDX_Control(pDX, IDC_SFTBUTTONSEARCH, m_SearchButton);
    //}}AFX_DATA_MAP
}

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

/////////////////////////////////////////////////////////////////////////////
// CAnimationsDlg message handlers

BOOL CAnimationsDlg::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_vSearchButton = m_SearchButton.GetControlUnknown();
    m_vFindButton = m_FindButton.GetControlUnknown();
    m_vDownloadButton = m_DownloadButton.GetControlUnknown();

    TCHAR szModule[_MAX_PATH];
    TCHAR szDrive[_MAX_DRIVE];
    TCHAR szPath[_MAX_PATH];

    GetModuleFileName(AfxGetApp()->m_hInstance, szModule, sizeof(szModule)/sizeof(TCHAR));
    _tsplitpath(szModule, szDrive, szPath, NULL, NULL);

    // Define all animations at run-time using the AVIPlay method
    // NOTE! If you are rebuilding this sample, you'll have to move the AVI files into the same folder as your executable
    _tmakepath(szModule, szDrive, szPath, _T("Search.avi"), NULL);
    m_vSearchButton->AVIPlay(1, _bstr_t(szModule), 0, -1);
    _tmakepath(szModule, szDrive, szPath, _T("FindComp.avi"), NULL);
    m_vFindButton->AVIPlay(1, _bstr_t(szModule), 0, -1);
    _tmakepath(szModule, szDrive, szPath, _T("Download.avi"), NULL);
    m_vDownloadButton->AVIPlay(1, _bstr_t(szModule), 0, -1);

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

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