MFC编程(五)

旋转按钮的使用

终身编程者

将旋转按钮与其他组件进行绑定

Ctrl+D查看Tab焦点顺序,与其绑定的组件必须是SpinButton的前一个

旋转按钮点击事件

void CDemo2Dlg::OnDeltaposSpin(NMHDR* pNMHDR, LRESULT* pResult) 
{
    NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
    // TODO: Add your control notification handler code here
    m_length = m_spin.GetPos();
    InvalidateRect(&m_example);
    UpdateWindow();
    *pResult = 0;
}

绘画事件

void CDemo2Dlg::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
    {
        COLORREF Color = RGB(255, 20, 30);
        GetDlgItem(IDC_S_EXAMPLE)->GetWindowRect(&m_example);
        ScreenToClient(&m_example);
        int border = (m_example.right - m_example.left - m_length) / 2;
        m_example.InflateRect(-border, -30);
        CBrush brush(Color);
        CPaintDC dc(this);
        dc.FillRect(&m_example, &brush);
        CDialog::OnPaint();
    }
}

窗口初始化

BOOL CDemo2Dlg::OnInitDialog()
{
    CDialog::OnInitDialog();
    ...
    // TODO: Add extra initialization here
    m_length = 50;
    m_spin.SetRange(10, 100);
    m_spin.SetPos(50);
    return TRUE;  // return TRUE  unless you set the focus to a control
}
MFC
本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!