// dDlg.cpp : implementation file
//
#include "stdafx.h"
#include "d.h"
#include "dDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CDDlg dialog
CDDlg::CDDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDDlg)
m_str = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestrSourceoyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDDlg)
DDX_Control(pDX, IDC_EDIT1, m_edit);
DDX_Text(pDX, IDC_EDIT1, m_str);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDDlg, CDialog)
//{{AFX_MSG_MAP(CDDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_CONVERT, OnConvert)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDDlg message handlers
void CDDlg::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 CDDlg::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 CDDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
#include <math.h>
int strHexToInt(char* strSource)
{
int nTemp=0;
CString strTemp;
strTemp=strSource;
for(char cc='G',dd='g'; cc<='Z',dd<='z'; cc++,dd++) //判断输入的字符串是否合法
{
if(strTemp.Find(cc,0) !=-1 || strTemp.Find(dd,0) !=-1)
{
::MessageBox(NULL,"请输入正确的16进制字符串!","输入错误",MB_ICONEXCLAMATION);
return -1;
}
}
for(int i = 0; i<(int)::strlen(strSource); i++)
{
int nDecNum;
switch(strSource[i])
{
case 'a':
case 'A': nDecNum = 10; break;
case 'b':
case 'B': nDecNum = 11; break;
case 'c':
case 'C': nDecNum = 12; break;
case 'd':
case 'D': nDecNum = 13; break;
case 'e':
case 'E': nDecNum = 14; break;
case 'f':
case 'F': nDecNum = 15; break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': nDecNum = strSource[i] - '0'; break;
default: return 0;
}
nTemp += nDecNum * (int)::pow(16,::strlen(strSource)-i -1);
}
return nTemp;
}
void CDDlg::OnConvert()
{
UpdateData();
if(strHexToInt((LPSTR)(LPCTSTR)m_str) !=-1)
{
CString str;
str.Format("%d",strHexToInt((LPSTR)(LPCTSTR)m_str));
SetDlgItemText(IDC_STATE,str);
}
m_edit.SetWindowText("");
m_edit.SetFocus();
}
BOOL CDDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_font.CreateFont(48, 0,0,0,FW_BOLD, 0,0,0,
DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "times new roman");
GetDlgItem(IDC_STATE)->SetFont(&m_font);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
评论0