15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


SetWindowText to a CEdit in a dialog bar

Thomas Matelich -- matelich@pacsim.com
Wednesday, January 08, 1997

Environment: VC++ 4.2b, Win 95, NT 4.0

I have implemented a dialog bar which contains a series of edit boxes.
These boxes will display either a number, or the word 'None'.  
I handled the kill focus message (ON_EN_KILLFOCUS(IDC_SOFT_LOWER,
OnKillfocusSoftLower)) and within that I get a pointer to the edit box with
GetDlgItem and call SetWindowText to either reformat the number, or display
None.

const CString None("None");

void CMainFrame::OnKillfocusEdit()
{
    CMyDoc* doc = (CMyDoc*)GetActiveDocument();
    CEdit* edit;

    edit = (CEdit*) (m_wndCtrlDlgBar.GetDlgItem(IDC_EDIT));

    if (doc->m_XLower[m_SelectedVar] > -1.0e30)
        edit->SetWindowText(MakeNumString( doc->m_XLower[m_SelectedVar] ));
    else
        edit->SetWindowText(None);  
}

MakeNumString returns a CString.  Here is the problem.  This works if
SetWindowText recieves the number from MakeNumString.  If None is passed,
there is a stack overflow which I haven't been able to understand.

Other things I've tried:

1)  Instead of the CString None, call edit->SetWindowText("None");

2)  Have MakeNumString check the value and return "None" if necessary.


Thanks for your help,

Thomas Matelich






Kit Kauffmann -- kitk@mudshark.sunquest.com
Friday, January 10, 1997

[Mini-digest: 2 responses]

doing certain things during focus processing can cause *very* odd behavior - 
it might be worth posting yourself a u-d message, from which you actually do 
the setwindowtext

hth!

>Environment: VC++ 4.2b, Win 95, NT 4.0
>
>I have implemented a dialog bar which contains a series of edit boxes.
>These boxes will display either a number, or the word 'None'.  
>I handled the kill focus message (ON_EN_KILLFOCUS(IDC_SOFT_LOWER,
>OnKillfocusSoftLower)) and within that I get a pointer to the edit box with
>GetDlgItem and call SetWindowText to either reformat the number, or display
>None.
>
>const CString None("None");
>
>void CMainFrame::OnKillfocusEdit()
>{
>    CMyDoc* doc = (CMyDoc*)GetActiveDocument();
>    CEdit* edit;
>
>    edit = (CEdit*) (m_wndCtrlDlgBar.GetDlgItem(IDC_EDIT));
>
>    if (doc->m_XLower[m_SelectedVar] > -1.0e30)
>        edit->SetWindowText(MakeNumString( doc->m_XLower[m_SelectedVar] ));
>    else
>        edit->SetWindowText(None);  
>}
>
>MakeNumString returns a CString.  Here is the problem.  This works if
>SetWindowText recieves the number from MakeNumString.  If None is passed,
>there is a stack overflow which I haven't been able to understand.
>
>Other things I've tried:
>
>1)  Instead of the CString None, call edit->SetWindowText("None");
>
>2)  Have MakeNumString check the value and return "None" if necessary.
The cost of feathers has risen... Now even down is up!


-----From: Jim Lawson Williams 

G'day!

This short test seems to work fine:

void CTestDbar::OnKillfocusDialogbarEdit() 
{
	// TODO: Add your control notification handler code here
	SetDlgItemText(IDC_DIALOGBAR_EDIT,"Some");
}

Regards,
Jim LW

At 03:39 PM 8/01/97 +0000, matelich@pacsim.com (Thomas Matelich) wrote:
>Environment: VC++ 4.2b, Win 95, NT 4.0
>
>I have implemented a dialog bar which contains a series of edit boxes.
>These boxes will display either a number, or the word 'None'.  
>I handled the kill focus message (ON_EN_KILLFOCUS(IDC_SOFT_LOWER,
>OnKillfocusSoftLower)) and within that I get a pointer to the edit box with
>GetDlgItem and call SetWindowText to either reformat the number, or display
>None.
>
>const CString None("None");
>
>void CMainFrame::OnKillfocusEdit()
>{
>    CMyDoc* doc = (CMyDoc*)GetActiveDocument();
>    CEdit* edit;
>
>    edit = (CEdit*) (m_wndCtrlDlgBar.GetDlgItem(IDC_EDIT));
>
>    if (doc->m_XLower[m_SelectedVar] > -1.0e30)
>        edit->SetWindowText(MakeNumString( doc->m_XLower[m_SelectedVar] ));
>    else
>        edit->SetWindowText(None);  
>}
>
>MakeNumString returns a CString.  Here is the problem.  This works if
>SetWindowText recieves the number from MakeNumString.  If None is passed,
>there is a stack overflow which I haven't been able to understand.
>
>Other things I've tried:
>
>1)  Instead of the CString None, call edit->SetWindowText("None");
>
>2)  Have MakeNumString check the value and return "None" if necessary.
>
>
>Thanks for your help,
>
>Thomas Matelich
>
>
>


>From the BBC's "Barchester Chronicles":

    "I know that ultimately we are not supposed to understand.
    But I also know that we must try."

       -- the Reverend Septimus Harding, crypt-analyst, clog-dancer, C++ programmer




| Вернуться в корень Архива |