Emulator
Emulator

Reputation: 186

Edit Control not updating with Spin Control MFC

I am trying to use an edit control along with a spin control using MFC visual studio .net 2003. I have carried out the basic settings for the spin control like setting the "AutoBuddy" property and "SetBuddyInteger" property to True so that the Spin control works in coordination with the edit control next to it. In my Spin control's event handler, I am facing a problem when I am trying to call my Invalidate() function. The float value in my edit control does not update and stays zero. If I remove the Invalidate(), then the value increments but my paint function is not updated obviously. A code of the following is given below:

void CMyDlg::OnSpinA(NMHDR *pNMHDR, LRESULT *pResult)
{
    LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
    // TODO: Add your control notification handler code here
    UpdateData();
    m_A = m_ASpinCtrl.GetPos(); // m_A is my edit control float value variable
    Invalidate(); // Invalidate is to be called to update my paint function to redraw the drawing
    UpdateData(false);
    *pResult = 0;
}

I have carried out the tab order correctly as well for the two controls.

Any suggestions on where I am going wrong?

Thanks in advance.

Upvotes: 0

Views: 3181

Answers (2)

Neophile
Neophile

Reputation: 5860

m_A when getting the position back would do something weird and would not return you the correct value. Try using the pointer to get your position and value and then carry out the invalidate().

{
        LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
        // TODO: Add your control notification handler code here
        UpdateData();

        CString tempStr;
        m_A += pNMUpDown->iDelta;
       tempStr.Format("%f",m_A);
        m_ACtrl.SetWindowText(tempStr); // Like a CEdit m_ACtrl to display your string

        Invalidate();
        UpdateData(false);
        *pResult = 0;
}

This should work perfectly well. Let me know if you still get any problems.

Upvotes: 2

dwo
dwo

Reputation: 3636

If you just want to have a spinning integer, you don't have to override anything.

The spin control has to be right next to the edit control in the tab order. With AutoBuddy that's all you have to do.

Upvotes: 3

Related Questions