?? listdlg.cpp
字號:
// listDlg.cpp : implementation file
//
#include "stdafx.h"
#include "list.h"
#include "listDlg.h"
#include "AppFace.h"
#include <math.h>
#include <malloc.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
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()
/////////////////////////////////////////////////////////////////////////////
// CListDlg dialog
CListDlg::CListDlg(CWnd* pParent /*=NULL*/)
: CDialog(CListDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CListDlg)
m_e1 = 0;
m_e3 = 0;
m_e4 = 0;
m_e5 = 0;
m_e2 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CListDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CListDlg)
DDX_Text(pDX, IDC_EDIT1, m_e1);
DDX_Text(pDX, IDC_EDIT3, m_e3);
DDX_Text(pDX, IDC_EDIT4, m_e4);
DDX_Text(pDX, IDC_EDIT5, m_e5);
DDX_Text(pDX, IDC_EDIT2, m_e2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CListDlg, CDialog)
//{{AFX_MSG_MAP(CListDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit3)
ON_EN_CHANGE(IDC_EDIT4, OnChangeEdit4)
ON_EN_CHANGE(IDC_EDIT5, OnChangeEdit5)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CListDlg message handlers
BOOL CListDlg::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 CListDlg::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 CListDlg::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
{ CRect rect;
CPaintDC dc(this);
GetClientRect(rect);
dc.FillSolidRect(rect,RGB(230,250,250));
CDialog::OnPaint();
}
}
HBRUSH CListDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
//CWnd* wnd = (CWnd*)GetDlgItem(IDC_EDIT1) ;
//HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
//SetTextColor(pDC->GetSafeHdc(), RGB(255, 0, 100));
return hbr;
return hbr;
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CListDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
///////////////////////////////////////////////////////////
////////////////////// My Code ////////////////////////////
///////////////////////////////////////////////////////////
# define dan 1
# define xun 2
# define shuang 3
# define OK 1
# define ERROR 0
# define R 18
int e[100];
int i=0;
int delet;
int Pos;
int length;
int inSert;
CString st;
typedef struct LNode{
int data;
LNode *next;
LNode *pror;
}LNode,*LinkList;
LinkList L,L2,L3;
int kind;
void CListDlg::OnChangeEdit1()
{
// TODO: Add your control notification handler code here
UpdateData(true);
length=m_e1;
}
void CListDlg::OnChangeEdit2()
{
// TODO: Add your control notification handler code here
UpdateData(true);
st=m_e2;
}
void CListDlg::OnChangeEdit3()
{
// TODO: Add your control notification handler code here
UpdateData(true);
Pos=m_e3;
}
void CListDlg::OnChangeEdit4()
{
// TODO: Add your control notification handler code here
UpdateData(true);
inSert=m_e4;
}
void CListDlg::OnChangeEdit5()
{
// TODO: Add your control notification handler code here
UpdateData(true);
delet=m_e5;
}
/////////////////////////////////////////////////////////////////
// 畫曲線
void CListDlg::DrawArc(CPoint p1,CPoint p2,int lr)
{
int n=8;
CPoint p[4];
CDC *pDC = GetDC();
p[0].x=p1.x;
p[0].y=p1.y;
p[3].x=p2.x;
p[3].y=p2.y;
if (p[3].x > p[0].x) p[3].x -= n;
else p[3].x += n;
double len = sqrt((p[0].x - p[3].x) * (p[0].x - p[3].x) + (p[0].y - p[3].y) * (p[0].y - p[3].y));
int con = (int)len / 3;
p[0].x += n / 2 * lr; p[0].y += (int)((double)n * sqrt(3.0) / 2.0);
p[1].x = p[0].x; p[1].y = p[0].y + 60;
CPoint cp((p[0].x + p[3].x) / 2, (p[0].y + p[3].y) / 2);
p[2] = cp;
p[2].x = cp.x + con; p[2].y = cp.y + con;
if (lr < 0) p[2].x -= 2 * con; if (p[0].x < p[3].x) p[2].y -= 2 * con;
CPen pen;
pen.CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
pDC->SelectObject(pen);
pDC->PolyBezier(p, 4);
ReleaseDC(pDC);
}
//////////////////////////////////////////////////////////////
// CString TO int
void StringToInt(CString source)
{ int j=0;
char *buff = source.GetBuffer(source.GetLength());
for(j;j<length;j++,i++)
{
e[i]=atoi(buff);
if(e[i]<10)buff+=2;
else if(e[i]<100)buff+=3;
else if(e[i]<1000)buff+=4;
else if(e[i]<10000)buff+=5;
else if(e[i]<100000)buff+=6;
else buff+=7;
}
source.ReleaseBuffer();
}
//////////////////////////////////////////////////////////////
// 單鏈表操作
void CreateList_L(LinkList &L)
{ LinkList p;int i;
int j=0;
StringToInt(st);
L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
for (i=0;i<length;i++){
p=(LinkList)malloc(sizeof(LNode));
p->data=e[j++];
p->next=L->next;L->next=p;
}
}
int ListInsert_L(LinkList &L,int i,int e)
{
LinkList p,s;p=L;int j=0;
if(i>length+1||i<1)
{MessageBox(NULL,"插入錯誤!!超出范圍,請重新輸入!!","插入錯誤!!超出范圍,請重新輸入!!",MB_OK);
return ERROR;
}
while(p&&j<i-1){p=p->next;j++;}
if(!p||j>i-1){MessageBox(NULL,"插入錯誤!!超出范圍,請重新輸入!!","插入錯誤!!超出范圍,請重新輸入!!",MB_OK);
return ERROR;}
s=(LinkList)malloc(sizeof(LNode));
s->data=e;s->next=p->next;
p->next=s;
length++;
return OK;
}
int ListDelete_L(LinkList &L,int i)
{ int e;
LinkList p,q;p=L;int j=0;
if(i<1||i>length)
{MessageBox(NULL,"刪除錯誤!!超出范圍,請重新輸入!!","刪除錯誤!!超出范圍,請重新輸入!!",MB_OK);return ERROR;
}
while(p->next&&j<i-1){p=p->next;++j;}
if(!(p->next)||j>i-1)
{MessageBox(NULL,"刪除錯誤!!超出范圍,請重新輸入!!","刪除錯誤!!超出范圍,請重新輸入!!",MB_OK);return ERROR;}
else
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -