📄 dlgdlg.cpp
字号:
// DLGDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DLG.h"
#include "DLGDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern Mapping errors,erasures;
extern unsigned char message[msgLEN], code[codeLEN];
extern CString msg;
extern int parityNum;
extern CDLGApp theApp;
/////////////////////////////////////////////////////////////////////////////
// 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)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDLGDlg dialog
CDLGDlg::CDLGDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDLGDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDLGDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_skin = 0;
}
void CDLGDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDLGDlg)
DDX_Control(pDX, IDC_TAB2, m_Tab);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDLGDlg, CDialog)
//{{AFX_MSG_MAP(CDLGDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB2, OnSelchangeTab2)
ON_BN_CLICKED(IDBACK, OnBack)
ON_BN_CLICKED(IDNEXT, OnNext)
ON_COMMAND(ID_HELP, OnHelp)
ON_COMMAND(ID_MENU_NEW, OnMenuNew)
ON_COMMAND(ID_CLOSE, OnClose)
ON_COMMAND(ID_MENU_PASTE, OnMenuPaste)
ON_COMMAND(ID_MENU_COPY, OnMenuCopy)
ON_COMMAND(ID_MENU_CUT, OnMenuCut)
ON_COMMAND(ID_MENU_SKIN, OnMenuSkin)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDLGDlg message handlers
BOOL CDLGDlg::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
MFCInit();
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CDLGDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CDLGDlg::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 CDLGDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDLGDlg::MFCInit()
{
m_Tab.InsertItem(0,"Message");
m_Tab.InsertItem(1,"Configuration");
m_Tab.InsertItem(2,"Result");
m_PageB.Create(IDD_PROPPAGE_B,&m_Tab);
m_PageE.Create(IDD_PROPPAGE_RS,&m_Tab);
m_PageR.Create(IDD_PROPPAGE_Result,&m_Tab);
m_PageB.ShowWindow(SW_SHOW);
m_PageE.ShowWindow(SW_HIDE);
m_PageR.ShowWindow(SW_HIDE);
CButton * pButB = (CButton*)this->GetDlgItem(IDBACK);
pButB->EnableWindow(FALSE);
CEdit * pEd = (CEdit *)m_PageE.GetDlgItem(IDC_NPAR);
pEd->SetWindowText("");
}
void CDLGDlg::OnSelchangeTab2(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CButton * pButN = (CButton*)this->GetDlgItem(IDNEXT);
CButton * pButB = (CButton*)this->GetDlgItem(IDBACK);
m_PageB.ShowWindow(SW_HIDE);
m_PageE.ShowWindow(SW_HIDE);
m_PageR.ShowWindow(SW_HIDE);
switch(m_Tab.GetCurSel())
{
case 0:
pButB->EnableWindow(FALSE);
pButN->SetWindowText("Next");
pButN->EnableWindow(TRUE);
m_PageB.ShowWindow(SW_SHOW);
break;
case 1:
pButB->EnableWindow(TRUE);
pButN->SetWindowText("Next");
pButN->EnableWindow(TRUE);
m_PageE.ShowWindow(SW_SHOW);
break;
case 2:
pButB->EnableWindow(FALSE);
pButN->SetWindowText("CORRECT");
pButN->EnableWindow(TRUE);
m_PageR.ShowWindow(SW_SHOW);
break;
}
*pResult = 0;
}
void CDLGDlg::OnBack()
{
// TODO: Add your control notification handler code here
switch(m_Tab.GetCurFocus())
{
case 0:
m_Tab.SetCurFocus(0);
break;
case 1:
m_Tab.SetCurFocus(0);
break;
case 2:
m_Tab.SetCurFocus(1);
break;
}
}
void CDLGDlg::OnNext()
{
// TODO: Add your control notification handler code here
switch(m_Tab.GetCurFocus())
{
case 0:
m_Tab.SetCurFocus(1);
break;
case 1:
m_Tab.SetCurFocus(2);
break;
case 2:
m_Tab.SetCurFocus(2);
m_PageR.Correct();
break;
}
}
void CDLGDlg::OnHelp()
{
// TODO: Add your command handler code here
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
void CDLGDlg::OnMenuNew()
{
// TODO: Add your command handler code here
msg.Empty();
erasures.clear();
errors.clear();
parityNum = 0;
for (int i = 0; i < codeLEN; i++)
code[i] = '\0';
for (i = 0; i < msgLEN; i++)
message[i] = '\0';
// PageB
CEdit * pEd=(CEdit*)m_PageB.GetDlgItem(IDC_EDIT_MSG);
pEd->SetWindowText(msg);
pEd=(CEdit*)m_PageB.GetDlgItem(IDC_EDIT_CODE);
pEd->SetWindowText(msg);
// PageE
CString temp;
temp.Empty();
pEd = (CEdit *)m_PageE.GetDlgItem(IDC_Bytes);
pEd->SetWindowText(temp);
pEd = (CEdit *)m_PageE.GetDlgItem(IDC_NPAR);
pEd->SetWindowText(temp);
pEd = (CEdit *)m_PageE.GetDlgItem(IDC_EDIT_P1);
pEd->SetWindowText(temp);
pEd->EnableWindow(FALSE);
pEd = (CEdit *)m_PageE.GetDlgItem(IDC_EDIT_P2);
pEd->SetWindowText(temp);
pEd->EnableWindow(FALSE);
pEd = (CEdit *)m_PageE.GetDlgItem(IDC_EDIT_D1);
pEd->SetWindowText(temp);
pEd->EnableWindow(FALSE);
pEd = (CEdit *)m_PageE.GetDlgItem(IDC_EDIT_D2);
pEd->SetWindowText(temp);
pEd->EnableWindow(FALSE);
CListBox * pLB=(CListBox*)m_PageE.GetDlgItem(IDC_LIST1);
i = pLB->GetCount();
while (i > 0) {
pLB->DeleteString(--i);
}
pLB->EnableWindow(FALSE);
pLB=(CListBox*)m_PageE.GetDlgItem(IDC_LIST2);
i = pLB->GetCount();
while (i > 0) {
pLB->DeleteString(--i);
}
pLB->EnableWindow(FALSE);
CButton * pCLB = (CButton*)m_PageE.GetDlgItem(IDC_CHECK1);
pCLB->SetCheck(0);
pCLB = (CButton*)m_PageE.GetDlgItem(IDC_CHECK2);
pCLB->SetCheck(0);
// PageR
pEd = (CEdit *)m_PageR.GetDlgItem(IDC_EDIT_TEXT);
pEd->SetWindowText(temp);
pEd = (CEdit *)m_PageR.GetDlgItem(IDC_EDIT_BINARY);
pEd->SetWindowText(temp);
pEd = (CEdit *)m_PageR.GetDlgItem(IDC_EDIT_CODE);
pEd->SetWindowText(temp);
}
void CDLGDlg::OnClose()
{
// TODO: Add your command handler code here
CDialog::OnOK();
}
void CDLGDlg::OnMenuPaste()
{
// TODO: Add your command handler code here
HWND hEdit = (this->GetFocus())->GetSafeHwnd();
::SendMessage((HWND)hEdit,WM_PASTE,0,0);
}
void CDLGDlg::OnMenuCopy()
{
// TODO: Add your command handler code here
HWND hEdit = (this->GetFocus())->GetSafeHwnd();
::SendMessage((HWND)hEdit,WM_COPY,0,0);
}
void CDLGDlg::OnMenuCut()
{
// TODO: Add your command handler code here
HWND hEdit = (this->GetFocus())->GetSafeHwnd();
::SendMessage((HWND)hEdit,WM_CUT,0,0);
}
void CDLGDlg::OnMenuSkin()
{
// TODO: Add your command handler code here
switch(m_skin) {
case 0:
LoadSkin(_T("Minimized.ssk"));
m_skin = 1;
break;
case 1:
LoadSkin(_T("dogmax.ssk"));
m_skin = 0;
break;
default:
LoadSkin(_T("dogmax.ssk"));
m_skin = 0;
break;
;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -