Hide

SftButton/OCX 3.0 - Button Control

Display
Print

Label Sample (C++)

This sample illustrates various button labels, text, images.

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

// LabelDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Label.h"
#include "LabelDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLabelDlg dialog

CLabelDlg::CLabelDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CLabelDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CLabelDlg)
        // 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 CLabelDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CLabelDlg)
    DDX_Control(pDX, IDC_TITLE, m_Title);
    DDX_Control(pDX, IDC_SFTBTN8, m_Button8);
    //}}AFX_DATA_MAP
}

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

/////////////////////////////////////////////////////////////////////////////
// CLabelDlg message handlers

BOOL CLabelDlg::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_vButton8 = m_Button8.GetControlUnknown();
    m_vButton8->Text = _bstr_t(_T("Two Lines\nof Text"));

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

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