- •Анотація
- •1 Аналіз індивідуального завдання
- •2 Загальна структура програми
- •3 Розробка меню
- •4 Підключення панелі інструментів та рядку стану
- •4.1 Створення панелі інструментів
- •4.2 Створення рядку стану
- •5 Створення діалогових вікон
- •5.1 Основні етапи створення діалогу
- •5.2 Створення діалогу для введення змінних
- •6 Математичне обчислення
- •6.1 Мова assembler під Win32
- •6.2 Реалізація
- •7 Створення та підключення бібліотеки dll
- •8 Робота з файлами
- •8.1 Відкриття файлу
- •8.2 Збереження файлу
- •9 Керівництво системного програміста
- •10 Керівництво оператора
- •Висновки
- •Література
- •Додатки Додаток а
- •Додаток б
Додаток б
//toolbar6.cpp Visual C++ 6.0 15-09-2001
#include
<afxwin.h>
#include <afxext.h>
#include <string.h>
#include "Resource.h"
#include "resrc1.h"
int a=0, b=0, c=0, x=0;
float y=0;
class CMyDialog :public CDialog
{
public:
CMyDialog(CWnd *pParent = NULL);
enum { IDD=IDD_DIALOG1};
CEdit text1;
CEdit text2;
CEdit text3;
CComboBox textX;
protected:
virtual void DoDataExchange(CDataExchange *pDX);
virtual void OnOk();
virtual void OnCancel();
virtual BOOL OnInitDialog();
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CMyDialog,CDialog)
ON_COMMAND(IDOK,OnOk)
ON_COMMAND(IDCANCEL,OnCancel)
END_MESSAGE_MAP()
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
text1.SetWindowText("1");
text2.SetWindowText("1");
text3.SetWindowText("1");
textX.SetWindowText("1");
UpdateData(TRUE);
return TRUE;
}
void CMyDialog::OnCancel()
{
CDialog::OnCancel();
}
CMyDialog::CMyDialog(CWnd *pParent)
:CDialog(CMyDialog::IDD,pParent)
{
}
void CMyDialog::DoDataExchange(CDataExchange *pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX,IDC_EDIT1,text1);
DDX_Control(pDX,IDC_EDIT2,text2);
DDX_Control(pDX,IDC_EDIT3,text3);
DDX_Control(pDX,IDC_COMBO1,textX);
}
void CMyDialog::OnOk()
{
char tmp[100];
text1.GetWindowText(tmp,100);
a
= atoi(tmp);
text2.GetWindowText(tmp,100);
b = atoi(tmp);
text3.GetWindowText(tmp,100);
c = atoi(tmp);
textX.GetWindowText(tmp,100);
x = atoi(tmp);
CDialog::OnOK();
}
class FileContents:public CDialog
{
public:
FileContents(char *s, CWnd *pParent = NULL)
: CDialog(IDD_DIALOG2, pParent)
{
this->s = s;
}
CEdit Edit1;
protected:
char *s;
virtual BOOL OnInitDialog()
{
CDialog::OnInitDialog();
Edit1.SetWindowText(s);
return TRUE;
}
virtual void DoDataExchange(CDataExchange *pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX,IDC_EDIT1,Edit1);
}
};
class CMyFrameWin:public CFrameWnd
{
public:
CMyFrameWin();
protected:
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnAbout();
afx_msg void OnResult();
afx_msg void OnOpen();
afx_msg void OnSave();
afx_msg void OnRun();
afx_msg void OnHelp();
afx_msg void OnQuit();
DECLARE_MESSAGE_MAP();
};
BEGIN_MESSAGE_MAP(CMyFrameWin, CFrameWnd)
ON_WM_CREATE()
ON_COMMAND(IDM_ABOUT,OnAbout)
ON_COMMAND(IDM_RESULT,OnResult)
ON_COMMAND(IDM_OPEN,OnOpen)
ON_COMMAND(IDM_SAVE,OnSave)
ON_COMMAND(IDM_HELP,OnHelp)
ON_COMMAND(IDM_RUN,OnRun)
ON_COMMAND(IDM_QUIT,OnQuit)
END_MESSAGE_MAP();
static UINT indicators[] =
{
ID_SEPARATOR,
ID_INDICATOR_NUM,
ID_INDICATOR_CAPS,
ID_INDICATOR_SCRL,
};
CMyFrameWin::CMyFrameWin()
{
Create(NULL,"My Program",
WS_OVERLAPPEDWINDOW,rectDefault,NULL,
MAKEINTRESOURCE(IDR_MAINFRAME));
};
int CMyFrameWin::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD
| WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS
| CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1;
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1;
}
return 0;
}
void CMyFrameWin::OnResult()
{
HINSTANCE hDll;
char s[20];
hDll=::LoadLibrary("asmdll");
if(hDll==NULL)
MessageBox("File asmdll.dll not found","Error");
else
{
typedef float (*FUN)(int, int, int, int);
FUN func;
func=(FUN)::GetProcAddress(hDll, "calc");
y=(*func)(x, a, b, c);
sprintf(s,"%f", y);
MessageBox(s,"Result");
}
::FreeLibrary(hDll);
}
void CMyFrameWin::OnOpen()
{
char *s;
CString path;
CFileDialog
dlgOpen(TRUE,"txt","",OFN_HIDEREADONLY,
"*.txt|*.txt|*.*|*.*|",this);
if(dlgOpen.DoModal()==IDOK)
{
CStdioFile File(dlgOpen.GetPathName(),
CFile::modeRead | CFile::typeBinary);
int Len = File.GetLength();
s = new char[Len + 1];
File.Read(s, Len);
s[Len] = 0;
FileContents FC(s);
FC.DoModal();
delete [] s;
}
}
void CMyFrameWin::OnSave()
{
char s[20];
sprintf(s,"%f", y);
CFileDialog dlgSave(FALSE,"txt","data",OFN_HIDEREADONLY,
"Data (*.txt)|*.txt|All Files(*.*)|*.*|",this);
if(dlgSave.DoModal()==IDOK)
{
CStdioFile
File(dlgSave.GetPathName(),
CFile::modeCreate | CFile::modeWrite);
File.WriteString(LPCSTR(s));
}
}
void CMyFrameWin::OnAbout()
{
::MessageBox(NULL,"Програмама була створена на замовлення ВНТУ \r\n в якості курсової роботи по предмету СПЗ \r\n Виконана студентом групи КІ-07 Олійник Р.І. ","About",MB_OK|
MB_ICONEXCLAMATION);
}
void CMyFrameWin::OnRun()
{
CMyDialog dialog;
dialog.DoModal();
}
void CMyFrameWin::OnHelp()
{
::MessageBox(NULL,"Для введення даних в прогруму натисніть Run\nДля обчислення - натисніть Result","Help",MB_OK|
MB_ICONEXCLAMATION);
}
void CMyFrameWin::OnQuit()
{
SendMessage(WM_CLOSE);
}
class CMyApp:public CWinApp
{
public:
virtual BOOL InitInstance();
};
BOOL
CMyApp::InitInstance()
{
CMyFrameWin *pMainWnd=new CMyFrameWin;
m_pMainWnd=pMainWnd;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
};
CMyApp app;
