CDialog(CDiplomMFCDlg::IDD, pParent)
, m_Elem(0)
, m_IndexElem(0)
, m_Size(_T(""))
, m_MaxElem(_T(""))
, m_MinElem(_T(""))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDiplomMFCDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, m_Elem);
DDX_Text(pDX, IDC_EDIT2, m_IndexElem);
DDX_Text(pDX, IDC_EDIT3, m_Size);
DDX_Text(pDX, IDC_EDIT4, m_MaxElem);
DDX_Text(pDX, IDC_EDIT5, m_MinElem);
DDX_Control(pDX,IDC_LIST1, m_Vector);
}
BEGIN_MESSAGE_MAP(CDiplomMFCDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, &CDiplomMFCDlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, &CDiplomMFCDlg::OnBnClickedButton2)
ON_BN_CLICKED(IDC_BUTTON3, &CDiplomMFCDlg::OnBnClickedButton3)
ON_BN_CLICKED(IDC_BUTTON4, &CDiplomMFCDlg::OnBnClickedButton4)
ON_BN_CLICKED(IDC_BUTTON5, &CDiplomMFCDlg::OnBnClickedButton5)
ON_BN_CLICKED(IDC_BUTTON6, &CDiplomMFCDlg::OnBnClickedButton6)
END_MESSAGE_MAP()
// CDiplomMFCDlg message handlers
BOOL CDiplomMFCDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CDiplomMFCDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CDiplomMFCDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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
{
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDiplomMFCDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CDiplomMFCDlg::OnBnClickedButton1()
{
UpdateData();
CString str;
vect.AddItem(m_Elem);
str.Format(_T("%i"), m_Elem);
m_Vector.AddString(str);
}
void CDiplomMFCDlg::OnBnClickedButton2()
{
UpdateData();
if (m_IndexElem<0||m_IndexElem>vect.GetSize()) MessageBox(_T("Неправильний індекс"));
else
{
CString str;
vect.InsertItem(m_IndexElem, m_Elem);
str.Format(_T("%i"), m_Elem);
m_Vector.InsertString(m_IndexElem,str);
}
}
void CDiplomMFCDlg::OnBnClickedButton3()
{
UpdateData();
CString str;
str.Format(_T("%i"), vect.GetSize());
m_Size=str;
UpdateData(FALSE);
}
void CDiplomMFCDlg::OnBnClickedButton4()
{
UpdateData();
CString str;
str.Format(_T("%i"), vect.MaxItem());
m_MaxElem=str;
UpdateData(FALSE);
}
void CDiplomMFCDlg::OnBnClickedButton5()
{
UpdateData();
CString str;
str.Format(_T("%i"), vect.MinItem());
m_MinElem=str;
UpdateData(FALSE);
}
void CDiplomMFCDlg::OnBnClickedButton6()
{
if (m_IndexElem<0||m_IndexElem>vect.GetSize()) MessageBox(_T("Неправильний індекс"));
else
{
UpdateData();
vect.DelItem(m_IndexElem);
m_Vector.DeleteString(m_IndexElem);
UpdateData(FALSE);
}
}