MFC程式設計(五)

calong發表於2020-10-30

終身程式設計者

將旋轉按鈕與其他元件進行繫結

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
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章