0

チェック ボックス、スクロール バー、ボタン、編集コントロールなどで構成されるダイアログ ベースの MFC アプリケーションで作業しています。アプリケーションの現在の状態を .txt ファイルに保存し、アプリケーションの再起動時にそれをロードしようとしています。CArchive クラスを使用してデータをシリアル化します。

// アプリケーション設定の保存

void CTestCalculatorDlg::OnSave()
{
this->UpdateData();
CFile f1;
CFileDialog l_SampleDlg(FALSE,".txt",NULL,0,"Text Files (*.txt)|*.txt|INI Files (*.ini)|*.ini|All Files (*.*)|*.*||");
if (l_SampleDlg.DoModal() == IDOK)
{
f1.Open(l_SampleDlg.GetPathName(), CFile::modeCreate | CFile::modeWrite);
    CArchive ar(&f1,CArchive::store); //create an archive object and tie it to the file object
    ar <<  N1 << m_OperandLeft << N2 << m_OperandRight << Res << m_Resulting << Typ << operation << m_operation << IsitChecked << m_checking; //serialize the data for the two edit boxes
    ar.Close();
}
else
    return;
f1.Close();

}

//ファイルから設定を読み込む

void CTestCalculatorDlg::OnOpen()

{

this -> UpdateData();
CFile f1;
CFileDialog l_SampleDlg(TRUE,".txt",NULL,0,"TXT Files (*.txt)|*.txt|INI Files (*.ini)|*.ini|All Files (*.*)|*.*||");
if (l_SampleDlg.DoModal() == IDOK)
{
    if (f1.Open(l_SampleDlg.GetPathName(), CFile::modeRead) == FALSE)
        return;
    //create an archive object and tie it to the file object
    CArchive ar(&f1,CArchive::load);
    //serialize the data for the two edit boxes
    ar >> N1 >> m_OperandLeft >> N2 >> m_OperandRight >> Res >> m_Resulting >> Typ >> operation >> m_operation >> IsitChecked >> m_checking >> m_Scrollingbar >> currScroll;;
    ar.Close();
}

f1.Close();
this -> UpdateData(FALSE);

}

チェック ボックス、テキスト ボックスのデータ、およびラジオ ボタンの状態を保存して読み込むことはできますが、スクロール バーを最後に保存した位置に戻すのは難しいと感じています。

//スクロール バー コントロールのコード

void CTestCalculatorDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)

{

int CurPos = m_ScrollBar.GetScrollPos();
switch (nSBCode)
{
case SB_LEFT:      // Scroll to far left.
    CurPos = 0;
    break;

case SB_RIGHT:      // Scroll to far right.
    CurPos = 100;
    break;

case SB_ENDSCROLL:   // End scroll.
    break;

case SB_LINELEFT:      // Scroll left.
    if (CurPos > 0)
        CurPos--;
    break;
m_ScrollBar.SetScrollPos(CurPos);

CString szPosition;
int currScroll;

szPosition.Format("%d", CurPos);
SetDlgItemText(IDC_DECIMAL, szPosition);
currScroll = m_ScrollBar.GetScrollPos();

CDialog::OnVScroll(nSBCode, nPos, pScrollBar);

}

また、静的テキストをスクロール バーにリンクする方法もわかりません。つまり、スライダーが真ん中にある場合、「Slider at 50 (Range: 0-100)」のように表示されるはずです。これを行う方法について誰かが私に指示できますか?

4

1 に答える 1