ورود

View Full Version : سوال: برنامه اي در mfc



samibala
دوشنبه 23 آذر 1388, 13:14 عصر
اين برنامه دربه صورت mfc نوشته شده توضيحي در بارش مي خوام نمي فهمم چي كار مي كنه:اشتباه:




// fixiDlg.cpp : implementation file
//
#include "stdafx.h"
#include "fixi.h"
#include "fixiDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

bool is_oprator( char ch )
{
if ( ch == '+' || ch == '-' || ch == '*' ||
ch == '/' || ch == '%' || ch == '^' )
return true;
else
return false;

}
int preference( char ch )
{
if( ch == '^' )
return 3;
else
if( ch == '*' || ch =='/' || ch == '%')
return 2;
else
if( ch == '+' || ch =='-' )
return 1;
else
return 0;
}
bool is_preference( char ch1 , char ch2 )
{
if ( preference( ch1 ) < preference ( ch2 ) )
return true;
else
return false;


}
/*void read()
{
UpdateData( true );

ifstream fin( "in.txt" );
char buff[128];
fin>>buff;
m_InputNot = buff;
UpdateData( false );
}*/
////////////////////////////////////
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFixiDlg dialog
CFixiDlg::CFixiDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFixiDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFixiDlg)
m_InputNot = _T("");
m_OutputNot = _T("");
m_ReadFile = FALSE;
m_WriteFile = FALSE;
m_PutParen = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFixiDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFixiDlg)
DDX_Text(pDX, IDC_InputNot, m_InputNot);
DDX_Text(pDX, IDC_OutputNot, m_OutputNot);
DDX_Check(pDX, IDC_ReadFile, m_ReadFile);
DDX_Check(pDX, IDC_WriteFile, m_WriteFile);
DDX_Check(pDX, IDC_PutParen, m_PutParen);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFixiDlg, CDialog)
//{{AFX_MSG_MAP(CFixiDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_EN_CHANGE(IDC_InputNot, OnChangeInputNot)
ON_BN_CLICKED(IDC_MakePre, OnMakePre)
ON_BN_CLICKED(IDC_MakePost, OnMakePost)
ON_BN_CLICKED(IDC_MakeIn, OnMakeIn)
//ON_BN_CLICKED(IDC_PutParen, OnPutParen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFixiDlg message handlers
BOOL CFixiDlg::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);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
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 CFixiDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CFixiDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (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 to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFixiDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFixiDlg::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.

// TODO: Add your control notification handler code here

}
void CFixiDlg::OnChangeInputNot()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.

// TODO: Add your control notification handler code here

}

//class stack methods
////////////////////////////////////
void stack::push( char temp )
{
Stack += temp;
// AfxMessageBox( Stack.c_str() );
}
////////////////////////////////////
char stack::pop()
{
int length = Stack.size();
char top_element = Stack[length-1];

Stack.resize( length-1 );
return top_element;
}
////////////////////////////////////
char stack::top()
{

if( Stack.size() == 0 )
return 0;
return Stack[ Stack.size() - 1 ];
}
////////////////////////////////////
void CFixiDlg::OnMakePost()
{
UpdateData ( true );
if( m_ReadFile )
{
ifstream fin( "in.txt" );
char buff[128];
fin>>buff;
m_InputNot = buff;
}
stack temp_stack;
stack output;
char temp_char;

int size = m_InputNot.GetLength();
for( int i=0; i<size ; i++ )
{
temp_char = m_InputNot[i];
if( is_oprator( temp_char ) )
{
if( is_preference( temp_stack.top() , temp_char ) )
temp_stack.push( temp_char );
else
{
while( !is_preference( temp_stack.top() , temp_char ) )
output.push( temp_stack.pop() );
temp_stack.push( temp_char );
}
}
else
output.push( temp_char );
}

while( temp_stack.top() != 0 )
{
output.push( temp_stack.pop() );
}

m_OutputNot = output.Stack.c_str();

if( m_WriteFile )
{
fstream fout( "out.txt" );
fout<<(LPCSTR)m_OutputNot;
}
UpdateData( false );
}
//////////////////////////////////////
void CFixiDlg::OnMakePre()
{
UpdateData( true );
if( m_ReadFile )
{
ifstream fin( "in.txt" );
char buff[128];
fin>>buff;
m_InputNot = buff;
}

stack temp_stack_oprator , temp_stack_operand;
char temp_char;
int size = m_InputNot.GetLength();
for( int i=size-1 ; i>=0 ; i-- )
{
temp_char = m_InputNot[i];
if( !is_oprator( temp_char ) )
{
temp_stack_operand.push( temp_char );
}
else
if( is_preference( temp_stack_oprator.top() , temp_char ) )
{
temp_stack_oprator.push( temp_char );
}
else
{
while( !is_preference( temp_stack_oprator.top() , temp_char ) )
temp_stack_operand.push( temp_stack_oprator.pop() );
temp_stack_oprator.push( temp_char );
}

}

while( temp_stack_oprator.top() != 0 )
{
temp_stack_operand.push( temp_stack_oprator.pop() );
}

stack output;
while( temp_stack_operand.top() != 0 )
{
output.push( temp_stack_operand.pop() );
}
m_OutputNot = output.Stack.c_str();
if( m_WriteFile )
{
fstream fout( "out.txt" );
fout<<(LPCSTR)m_OutputNot;
}
UpdateData( false );

}
/////////////////////////////////////
void CFixiDlg::OnMakeIn()
{
UpdateData( true );
if( m_ReadFile )
{
ifstream fin( "in.txt" );
char buff[128];
fin>>buff;
m_InputNot = buff;

}

m_OutputNot = m_InputNot;
if( m_WriteFile )
{
fstream fout( "out.txt" );
fout<<(LPCSTR)m_OutputNot;
}
UpdateData( false );
}

حامد مصافی
دوشنبه 23 آذر 1388, 16:07 عصر
اين برنامه دربه صورت mfc نوشته شده توضيحي در بارش مي خوام نمي فهمم چي كار مي كنه:اشتباه:
توضيح از كدام قسمت؟

samibala
دوشنبه 23 آذر 1388, 23:02 عصر
توضيح از كلش