📄 recdefdlg.cpp
字号:
// RecDefDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PDB Reader.h"
#include "RecDefDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRecDefDlg dialog
CRecDefDlg::CRecDefDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRecDefDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRecDefDlg)
//}}AFX_DATA_INIT
thisApp=(CPDBReaderApp *) AfxGetApp();
}
void CRecDefDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRecDefDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRecDefDlg, CDialog)
//{{AFX_MSG_MAP(CRecDefDlg)
ON_BN_CLICKED(IDC_STRING, OnStringClick)
ON_WM_VSCROLL()
ON_WM_SHOWWINDOW()
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_COMMAND(ID_RECORD_ADD, OnRecordAdd)
ON_COMMAND(ID_RECORD_DELETE, OnRecordDelete)
ON_EN_SETFOCUS(IDC_LENGTH_EDIT_1, OnSetfocusLengthEdit1)
ON_EN_SETFOCUS(IDC_LENGTH_EDIT_2, OnSetfocusLengthEdit2)
ON_EN_SETFOCUS(IDC_LENGTH_EDIT_3, OnSetfocusLengthEdit3)
ON_EN_SETFOCUS(IDC_LENGTH_EDIT_4, OnSetfocusLengthEdit4)
ON_EN_SETFOCUS(IDC_NAME_EDIT_1, OnSetfocusNameEdit1)
ON_EN_SETFOCUS(IDC_NAME_EDIT_2, OnSetfocusNameEdit2)
ON_EN_SETFOCUS(IDC_NAME_EDIT_3, OnSetfocusNameEdit3)
ON_EN_SETFOCUS(IDC_NAME_EDIT_4, OnSetfocusNameEdit4)
ON_CBN_SETFOCUS(IDC_TYPE_COMBO_1, OnSetfocusTypeCombo1)
ON_CBN_SETFOCUS(IDC_TYPE_COMBO_2, OnSetfocusTypeCombo2)
ON_CBN_SETFOCUS(IDC_TYPE_COMBO_3, OnSetfocusTypeCombo3)
ON_CBN_SETFOCUS(IDC_TYPE_COMBO_4, OnSetfocusTypeCombo4)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRecDefDlg message handlers
void CRecDefDlg::OnStringClick()
{
CButton *btnStringOnly;
GetFieldValues();
btnStringOnly = (CButton *) GetDlgItem(IDC_STRING);
if (btnStringOnly->GetCheck() != 0)
ResetToString();
else
SetFieldValues();
SetMenuState();
}
void CRecDefDlg::OnOK()
{
GetFieldValues();
CDialog::OnOK();
}
void CRecDefDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
int intMinPos;
int intMaxPos;
int intCurPos;
GetFieldValues();
pScrollBar->GetScrollRange(&intMinPos, &intMaxPos);
intCurPos = pScrollBar->GetScrollPos();
switch (nSBCode) {
case SB_BOTTOM:
pScrollBar->SetScrollPos(intMaxPos);
break;
case SB_ENDSCROLL:
break;
case SB_LINEDOWN:
pScrollBar->SetScrollPos(intCurPos+1);
break;
case SB_LINEUP:
pScrollBar->SetScrollPos(intCurPos-1);
break;
case SB_PAGEDOWN:
pScrollBar->SetScrollPos(intCurPos+3);
break;
case SB_PAGEUP:
pScrollBar->SetScrollPos(intCurPos-3);
break;
case SB_THUMBPOSITION:
pScrollBar->SetScrollPos(nPos);
break;
case SB_THUMBTRACK:
break;
case SB_TOP:
pScrollBar->SetScrollPos(intMinPos);
break;
default:
break;
}
SetFieldValues();
}
void CRecDefDlg::ResetToString()
{
CScrollBar *scrTemp;
thisApp->arrFields.RemoveAll();
thisApp->arrFields.SetSize(0, 10);
thisApp->arrFields.Add(CFieldDef(_T("Record"), _T("String"), 0));
CheckDlgButton(IDC_STRING, 1);
scrTemp = (CScrollBar *) GetDlgItem(IDC_FIELD_SCROLLBAR);
scrTemp->SetScrollRange(0, thisApp->arrFields.GetUpperBound(), FALSE);
scrTemp->SetScrollPos(0, TRUE);
m_lngActive = 0;
SetFieldValues();
}
void CRecDefDlg::SetFieldValues()
{
CComboBox *cboTemp;
CEdit *edtTemp;
CScrollBar *scrTemp;
CButton *btnStringOnly;
long i;
long lngStart;
BOOL bolStringOn;
CString strTemp;
btnStringOnly = (CButton *) GetDlgItem(IDC_STRING);
bolStringOn = (btnStringOnly->GetCheck() != 0);
scrTemp = (CScrollBar *) GetDlgItem(IDC_FIELD_SCROLLBAR);
lngStart = scrTemp->GetScrollPos();
for (i = 0; i < 4; i++) {
if (i + lngStart <= thisApp->arrFields.GetUpperBound()) {
strTemp = _T("");
strTemp.Format(_T("%ld"), i + lngStart + 1);
strTemp += CString(_T(":"));
SetDlgItemText(IDC_FIELD_1 + i, strTemp);
edtTemp = (CEdit *) GetDlgItem(IDC_NAME_EDIT_1 + i);
edtTemp->EnableWindow(! bolStringOn);
edtTemp->SetWindowText(thisApp->arrFields[i + lngStart].Name);
strTemp = _T("");
if (thisApp->arrFields[i + lngStart].Length > 0)
strTemp.Format("%ld", thisApp->arrFields[i + lngStart].Length);
edtTemp = (CEdit *) GetDlgItem(IDC_LENGTH_EDIT_1 + i);
edtTemp->EnableWindow(! bolStringOn);
edtTemp->SetWindowText(strTemp);
cboTemp = (CComboBox *) GetDlgItem(IDC_TYPE_COMBO_1 + i);
cboTemp->EnableWindow(! bolStringOn);
cboTemp->SelectString(-1, thisApp->arrFields[i + lngStart].Type);
}
else {
SetDlgItemText(IDC_FIELD_1 + i, _T(""));
edtTemp = (CEdit *) GetDlgItem(IDC_NAME_EDIT_1 + i);
edtTemp->EnableWindow(FALSE);
edtTemp->SetWindowText(_T(""));
edtTemp = (CEdit *) GetDlgItem(IDC_LENGTH_EDIT_1 + i);
edtTemp->EnableWindow(FALSE);
edtTemp->SetWindowText(_T(""));
cboTemp = (CComboBox *) GetDlgItem(IDC_TYPE_COMBO_1 + i);
cboTemp->EnableWindow(FALSE);
cboTemp->SetCurSel(-1);
}
}
ShowActive();
}
void CRecDefDlg::GetFieldValues()
{
CComboBox *cboTemp;
CEdit *edtTemp;
CScrollBar *scrTemp;
CButton *btnStringOnly;
long i;
long lngStart;
CString strTemp;
btnStringOnly = (CButton *) GetDlgItem(IDC_STRING);
if (btnStringOnly->GetCheck() == 0) {
scrTemp = (CScrollBar *) GetDlgItem(IDC_FIELD_SCROLLBAR);
lngStart = scrTemp->GetScrollPos();
for (i = 0; i < 4; i++) {
if (i + lngStart <= thisApp->arrFields.GetUpperBound()) {
edtTemp = (CEdit *) GetDlgItem(IDC_NAME_EDIT_1 + i);
edtTemp->GetWindowText(thisApp->arrFields[i + lngStart].Name);
strTemp = _T("");
if (thisApp->arrFields[i + lngStart].Length > 0)
strTemp.Format("%ld", thisApp->arrFields[i + lngStart].Length);
edtTemp = (CEdit *) GetDlgItem(IDC_LENGTH_EDIT_1 + i);
edtTemp->GetWindowText(strTemp);
if (! strTemp.IsEmpty())
thisApp->arrFields[i + lngStart].Length = atoi(strTemp);
cboTemp = (CComboBox *) GetDlgItem(IDC_TYPE_COMBO_1 + i);
cboTemp->GetLBText(cboTemp->GetCurSel(), thisApp->arrFields[i + lngStart].Type);
}
}
}
}
void CRecDefDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
ResetToString();
SetMenuState();
}
void CRecDefDlg::OnFileOpen()
{
ifstream filTemp;
_TCHAR strFileName[_MAX_PATH]=_T("");
CScrollBar *scrTemp;
OPENFILENAME ofnSave;
ofnSave.lStructSize = sizeof(OPENFILENAME);
ofnSave.hwndOwner = GetSafeHwnd();
ofnSave.lpstrFilter = "Record Definitions\000*.REC\000\000";
ofnSave.lpstrCustomFilter = NULL;
ofnSave.nFilterIndex = 1;
ofnSave.lpstrFile = strFileName;
ofnSave.nMaxFile = _MAX_PATH;
ofnSave.lpstrFileTitle = NULL;
ofnSave.lpstrInitialDir = NULL;
ofnSave.lpstrTitle = _T("Load Record Definition");
ofnSave.Flags = OFN_LONGNAMES | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_SHAREAWARE;
ofnSave.lpstrDefExt = _T("REC");
ofnSave.lpfnHook = NULL;
ofnSave.lpTemplateName = NULL;
if (GetOpenFileName(&ofnSave)) {
filTemp.open(strFileName);
if (filTemp.is_open()) {
long i;
long maxSize;
filTemp >> maxSize;
thisApp->arrFields.RemoveAll();
thisApp->arrFields.SetSize(maxSize, 10);
for (i=0; i < maxSize; i++)
filTemp >> thisApp->arrFields[i];
filTemp.close();
}
}
scrTemp = (CScrollBar *) GetDlgItem(IDC_FIELD_SCROLLBAR);
scrTemp->SetScrollRange(0, thisApp->arrFields.GetUpperBound(), FALSE);
SetFieldValues();
}
void CRecDefDlg::OnFileSave()
{
ofstream filTemp;
_TCHAR strFileName[_MAX_PATH]=_T("");
OPENFILENAME ofnSave;
GetFieldValues();
ofnSave.lStructSize = sizeof(OPENFILENAME);
ofnSave.hwndOwner = GetSafeHwnd();
ofnSave.lpstrFilter = "Record Definitions\000*.REC\000\000";
ofnSave.lpstrCustomFilter = NULL;
ofnSave.nFilterIndex = 1;
ofnSave.lpstrFile = strFileName;
ofnSave.nMaxFile = _MAX_PATH;
ofnSave.lpstrFileTitle = NULL;
ofnSave.lpstrInitialDir = NULL;
ofnSave.lpstrTitle = _T("Save Record Definition");
ofnSave.Flags = OFN_LONGNAMES | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_SHAREAWARE;
ofnSave.lpstrDefExt = _T("REC");
ofnSave.lpfnHook = NULL;
ofnSave.lpTemplateName = NULL;
if (GetSaveFileName(&ofnSave)) {
filTemp.open(strFileName);
if (filTemp.is_open()) {
long i;
filTemp << thisApp->arrFields.GetSize() << endl;
for (i=0; i <= thisApp->arrFields.GetUpperBound(); i++)
filTemp << thisApp->arrFields[i];
filTemp.close();
}
}
}
void CRecDefDlg::OnRecordAdd()
{
CScrollBar *scrTemp;
GetFieldValues();
thisApp->arrFields.Add(CFieldDef(_T("Unnamed"), _T("String"), 0));
scrTemp = (CScrollBar *) GetDlgItem(IDC_FIELD_SCROLLBAR);
scrTemp->SetScrollRange(0, thisApp->arrFields.GetUpperBound(), FALSE);
SetFieldValues();
}
void CRecDefDlg::OnRecordDelete()
{
CScrollBar *scrTemp;
long lngNewPos;
GetFieldValues();
if (thisApp->arrFields.GetSize() > 1) {
thisApp->arrFields.RemoveAt(m_lngActive);
if (m_lngActive > 0)
m_lngActive -= 1;
scrTemp = (CScrollBar *) GetDlgItem(IDC_FIELD_SCROLLBAR);
scrTemp->SetScrollRange(0, thisApp->arrFields.GetUpperBound(), FALSE);
if (m_lngActive >= scrTemp->GetScrollPos())
lngNewPos = scrTemp->GetScrollPos();
else
lngNewPos = m_lngActive;
scrTemp->SetScrollPos(lngNewPos);
SetFieldValues();
}
else
MessageBox(_T("A record must have at least one field. You cannot, therefore, delete the last field defined in the record."), NULL, MB_ICONWARNING | MB_OK | MB_APPLMODAL);
}
void CRecDefDlg::SetMenuState()
{
CMenu *mnuTemp = GetMenu();
CButton *btnStringOnly = (CButton *) GetDlgItem(IDC_STRING);
if (btnStringOnly->GetCheck() == 0)
mnuTemp->EnableMenuItem(0, MF_BYPOSITION | MF_ENABLED);
else
mnuTemp->EnableMenuItem(0, MF_BYPOSITION | MF_GRAYED);
DrawMenuBar();
}
void CRecDefDlg::OnSetfocusLengthEdit1()
{
ShowActive(1);
}
void CRecDefDlg::OnSetfocusLengthEdit2()
{
ShowActive(2);
}
void CRecDefDlg::OnSetfocusLengthEdit3()
{
ShowActive(3);
}
void CRecDefDlg::OnSetfocusLengthEdit4()
{
ShowActive(4);
}
void CRecDefDlg::OnSetfocusNameEdit1()
{
ShowActive(1);
}
void CRecDefDlg::OnSetfocusNameEdit2()
{
ShowActive(2);
}
void CRecDefDlg::OnSetfocusNameEdit3()
{
ShowActive(3);
}
void CRecDefDlg::OnSetfocusNameEdit4()
{
ShowActive(4);
}
void CRecDefDlg::OnSetfocusTypeCombo1()
{
ShowActive(1);
}
void CRecDefDlg::OnSetfocusTypeCombo2()
{
ShowActive(2);
}
void CRecDefDlg::OnSetfocusTypeCombo3()
{
ShowActive(3);
}
void CRecDefDlg::OnSetfocusTypeCombo4()
{
ShowActive(4);
}
void CRecDefDlg::ShowActive(int intRow)
{
int i;
int intActive;
BOOL bolActiveFound;
CWnd *pctTemp;
WINDOWPLACEMENT wndPlacement;
CScrollBar *scrTemp;
long lngStart;
if (intRow > 0) {
CScrollBar *scrTemp;
scrTemp = (CScrollBar *) GetDlgItem(IDC_FIELD_SCROLLBAR);
m_lngActive = scrTemp->GetScrollPos();
m_lngActive += intRow - 1;
}
scrTemp = (CScrollBar *) GetDlgItem(IDC_FIELD_SCROLLBAR);
lngStart = scrTemp->GetScrollPos();
wndPlacement.length = sizeof(WINDOWPLACEMENT);
intActive = 0;
bolActiveFound = FALSE;
for (i = 0; i < 4; i++) {
pctTemp = GetDlgItem(IDC_ACTIVE_1 + i);
pctTemp->GetWindowPlacement(&wndPlacement);
wndPlacement.showCmd = SW_HIDE;
pctTemp->SetWindowPlacement(&wndPlacement);
if (m_lngActive == i + lngStart) {
intActive = i;
bolActiveFound = TRUE;
}
}
if (!bolActiveFound) {
m_lngActive = lngStart;
intActive = 0;
}
pctTemp = GetDlgItem(IDC_ACTIVE_1 + intActive);
pctTemp->GetWindowPlacement(&wndPlacement);
wndPlacement.showCmd = SW_SHOW;
pctTemp->SetWindowPlacement(&wndPlacement);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -