⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringsetsampledlg.cpp

📁 vc++的部分比较经典的源码
💻 CPP
字号:
// StringSetSampleDlg.cpp : implementation file

#include "stdafx.h"
#include "StringSetSample.h"
#include "StringSetSampleDlg.h"

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

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//                          C A b o u t D l g
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class CAboutDlg : public CDialog
{
    public:
        CAboutDlg() ;

    // Dialog Data
        //{{AFX_DATA(CAboutDlg)
        enum { IDD = IDD_ABOUTBOX } ;
        //}}AFX_DATA

    // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CAboutDlg)
    protected:
        virtual void DoDataExchange( CDataExchange * pDX ) ;
        //}}AFX_VIRTUAL

    // Implementation
    protected:
        //{{AFX_MSG(CAboutDlg)
        //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
} ;

CAboutDlg::CAboutDlg() : CDialog( CAboutDlg::IDD )
{
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange( CDataExchange * pDX )
{
    CDialog::DoDataExchange( pDX ) ;
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//                  C S t r i n g S e t S a m p l e D l g
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CStringSetSampleDlg Constructor
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CStringSetSampleDlg::CStringSetSampleDlg( CWnd * pParent /*=NULL*/ )
    : CDialog( CStringSetSampleDlg::IDD, pParent )
{
    //{{AFX_DATA_INIT(CStringSetSampleDlg)
    //}}AFX_DATA_INIT
    m_strSearch = _T("The quick red fox jumped over the lazy brown dog.  Now is the time for ")
                  _T("all good men to come\r\nto the aid of their country.  Ask not what your ")
                  _T("country can do for you, but what you can do\r\nfor your country.") ;
    m_hIcon = AfxGetApp()->LoadIcon( IDR_MAINFRAME ) ;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// DoDataExchange
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void CStringSetSampleDlg::DoDataExchange( CDataExchange * pDX )
{
    CDialog::DoDataExchange( pDX ) ;
    //{{AFX_DATA_MAP(CStringSetSampleDlg)
    DDX_Control( pDX, IDC_SEARCH_STRING,   m_editSearch     ) ;
    DDX_Text(    pDX, IDC_SEARCH_STRING,   m_strSearch      ) ;
    DDX_Control( pDX, IDC_STRINGS_TO_SEEK, m_editSeekTokens ) ;
    DDX_Control( pDX, IDC_SEEK_TOKENS,     m_lbSeekTokens   ) ;
    DDX_Control( pDX, IDC_FOUND_TOKENS,    m_lbFoundTokens  ) ;
    //}}AFX_DATA_MAP
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// OnInitDialog
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BOOL CStringSetSampleDlg::OnInitDialog()
{
    CDialog::OnInitDialog() ;

    // Add "About..." menu item to system menu.
    // IDM_ABOUTBOX must be in the system command range.
    ASSERT(( IDM_ABOUTBOX & 0xFFF0 ) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu * pSysMenu = GetSystemMenu( FALSE ) ;
    if ( pSysMenu != NULL )
    {
        CString strAboutMenu ;
        strAboutMenu.LoadString( IDS_ABOUTBOX ) ;
        if ( !strAboutMenu.IsEmpty() )
        {
            pSysMenu->AppendMenu( MF_SEPARATOR ) ;
            pSysMenu->AppendMenu( MF_STRING, IDM_ABOUTBOX, strAboutMenu ) ;
        }
    }

    SetIcon( m_hIcon, TRUE ) ;         // Set big icon
    SetIcon( m_hIcon, FALSE ) ;        // Set small icon

    CRect rectListboxes ;
    m_lbSeekTokens.GetWindowRect( rectListboxes ) ;
    int nColWid = rectListboxes.Width() / 3 ;
    m_lbSeekTokens.SetColumnWidth( nColWid ) ;
    m_lbFoundTokens.SetColumnWidth( nColWid ) ;
    m_editSeekTokens.SetFocus() ;

    return false ;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Message Map
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BEGIN_MESSAGE_MAP(CStringSetSampleDlg, CDialog)
    //{{AFX_MSG_MAP(CStringSetSampleDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_EN_KILLFOCUS(IDC_STRINGS_TO_SEEK, OnKillFocusStringsToSeek)
    ON_BN_CLICKED( IDC_SEARCH, OnSearch )
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CStringSetSampleDlg message handlers
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// OnKillFocusStringsToSeek
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void CStringSetSampleDlg::OnKillFocusStringsToSeek()
{
    CString strTokens ;
    m_editSeekTokens.GetWindowText( strTokens ) ;
    int nCount = m_setStrings.Add( strTokens, _T(", |;") ) ;
    if ( nCount > 0 )
    {
        for ( int nIdx = 0 ; nIdx < nCount ; nIdx++ )
            m_lbSeekTokens.AddString( m_setStrings[nIdx] ) ;
    }
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// OnSearch
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void CStringSetSampleDlg::OnSearch()
{
    m_editSearch.GetWindowText( m_strSearch ) ;
    int nWord ;
    UINT nPos = m_setStrings.FindFirstIn( m_strSearch, nWord ) ;
    if ( nPos != 0xFFFFFFFF )
    {
        CString strWord ;
        do
        {
            strWord.Format( _T("%s (%u)"), (LPCTSTR)m_setStrings[nWord], nPos ) ;
            m_lbFoundTokens.AddString( strWord ) ;
            nPos = m_setStrings.FindNext( nWord ) ;
        } while ( nPos != 0xFFFFFFFF ) ;
    }
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// OnSysCommand
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void CStringSetSampleDlg::OnSysCommand( UINT nID, LPARAM lParam )
{
    if ( (nID & 0xFFF0) == IDM_ABOUTBOX )
    {
        CAboutDlg dlgAbout ;
        dlgAbout.DoModal() ;
    }
    else
    {
        CDialog::OnSysCommand( nID, lParam ) ;
    }
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// OnPaint
// 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 CStringSetSampleDlg::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() ;
    }
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// OnQueryDragIcon
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HCURSOR CStringSetSampleDlg::OnQueryDragIcon()
{
    return (HCURSOR)m_hIcon ;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -