⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resinfodlg.cpp

📁 Resource editor base speadrum Chinese mobile
💻 CPP
字号:
// ResInfoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "resourceeditor.h"
#include "ResInfoDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CResInfoDlg dialog


CResInfoDlg::CResInfoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CResInfoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CResInfoDlg)
	m_strAddr = _T("");
	m_strBuild = _T("");
	m_strMajorVer = _T("");
	m_strMinorVer = _T("");
	m_nLimit = 0;
	m_bIsOffset = FALSE;
//	m_bBigEndian = FALSE;
	//}}AFX_DATA_INIT
}


void CResInfoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CResInfoDlg)
	DDX_Text(pDX, IDC_EDT_ADDR, m_strAddr);
	DDX_Text(pDX, IDC_EDT_BUILD, m_strBuild);
	DDX_Text(pDX, IDC_EDT_MAJORVER, m_strMajorVer);
	DDX_Text(pDX, IDC_EDT_MINORVER, m_strMinorVer);
	DDX_Text(pDX, IDC_EDT_LIMIT, m_nLimit);
	DDX_Check(pDX, IDC_CHK_OFFSET, m_bIsOffset);
//	DDX_Check(pDX, IDC_CHK_BIGENDIAN, m_bBigEndian);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CResInfoDlg, CDialog)
	//{{AFX_MSG_MAP(CResInfoDlg)
	ON_BN_CLICKED(ID_BTN_LATER, OnBtnLater)
	ON_EN_UPDATE(IDC_EDT_ADDR, OnUpdateEdtAddr)
	ON_EN_UPDATE(IDC_EDT_LIMIT, OnUpdateEdtLimit)
	ON_EN_UPDATE(IDC_EDT_MAJORVER, OnUpdateEdtMajorver)
	ON_EN_UPDATE(IDC_EDT_MINORVER, OnUpdateEdtMinorver)
	ON_EN_UPDATE(IDC_EDT_BUILD, OnUpdateEdtBuild)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CResInfoDlg message handlers

void CResInfoDlg::OnBtnLater() 
{
	// TODO: Add your control notification handler code here
    CDialog::OnCancel();
}

BOOL CResInfoDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
    CEdit * pAddr  = (CEdit *)GetDlgItem(IDC_EDT_ADDR);     _ASSERTE( pAddr  != NULL );
    CEdit * pLimit = (CEdit *)GetDlgItem(IDC_EDT_LIMIT);    _ASSERTE( pLimit != NULL );
    CEdit * pMajor = (CEdit *)GetDlgItem(IDC_EDT_MAJORVER); _ASSERTE( pMajor != NULL );
    CEdit * pMinor = (CEdit *)GetDlgItem(IDC_EDT_MINORVER); _ASSERTE( pMinor != NULL );
    CEdit * pBuild = (CEdit *)GetDlgItem(IDC_EDT_BUILD);    _ASSERTE( pBuild != NULL );
    CWnd  * pOffset = (CEdit *)GetDlgItem(IDC_CHK_OFFSET);  _ASSERTE( pOffset != NULL );
    //CWnd  * pEndian = (CEdit *)GetDlgItem(IDC_CHK_BIGENDIAN);  _ASSERTE( pEndian != NULL );

    if( !g_theApp.IsSuperUser() )
    {
        pAddr->EnableWindow(FALSE);
        pLimit->EnableWindow(FALSE);
        pOffset->EnableWindow(FALSE);
       // pEndian->EnableWindow(FALSE);
    }

    pAddr->SetLimitText(8);
    pLimit->SetLimitText(10);
    pMajor->SetLimitText(3);
    pMinor->SetLimitText(3);
    pBuild->SetLimitText(3);

    TOOL_USED_INFO_T &tui = g_theApp.m_MMIRes.m_Resource.ToolUsedInfo;
    m_strAddr.Format(_T("%08x"), tui.nStartAddress);
    m_nLimit = tui.nMaxLimitSize;
    
    m_strMajorVer.Format(_T("%03d"), tui.nMajorVersion);
    m_strMinorVer.Format(_T("%03d"), tui.nMinorVersion);
    m_strBuild.Format(_T("%03d"), tui.nBuildNumber);
    
    m_bIsOffset  = tui.bAddrIsOffset;
//    m_bBigEndian = tui.bBigEndian;

    UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BOOL CResInfoDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	//
    CWnd * pFocus = GetFocus();
    if( pMsg->message == WM_CHAR && pFocus != NULL )
    {
        CWnd * pAddr  = GetDlgItem(IDC_EDT_ADDR);     _ASSERTE( pAddr  != NULL );
        CWnd * pLimit = GetDlgItem(IDC_EDT_LIMIT);    _ASSERTE( pLimit != NULL );
        CWnd * pMajor = GetDlgItem(IDC_EDT_MAJORVER); _ASSERTE( pMajor != NULL );
        CWnd * pMinor = GetDlgItem(IDC_EDT_MINORVER); _ASSERTE( pMinor != NULL );
        CWnd * pBuild = GetDlgItem(IDC_EDT_BUILD);    _ASSERTE( pBuild != NULL );
   
        _TCHAR cChar = pMsg->wParam;
        if( pFocus->m_hWnd == pAddr->m_hWnd )
        {
            if( cChar != VK_BACK && !CharIsHexChar(cChar) )
                return TRUE;

            if( cChar >= _T('a') && cChar <= _T('f') )
                pMsg->wParam -= 32;
        }
        else if( pFocus->m_hWnd == pLimit->m_hWnd || pFocus->m_hWnd == pMajor->m_hWnd || 
                 pFocus->m_hWnd == pMinor->m_hWnd || pFocus->m_hWnd == pBuild->m_hWnd )
        {
            if( cChar != VK_BACK && !CharIsNumber(cChar) )
                return TRUE;            
        }
    }

	return CDialog::PreTranslateMessage(pMsg);
}

__inline BOOL CResInfoDlg::CharIsNumber( _TCHAR cChar )
{
    return cChar >= _T('0') && cChar <= _T('9');
}

__inline BOOL CResInfoDlg::CharIsHexChar( _TCHAR cChar )
{
    if( !CharIsNumber(cChar) )
    {
        if( cChar >= _T('a') && cChar <= _T('f') )
            return TRUE;
        else if( cChar >= _T('A') && cChar <= _T('F') )
            return TRUE;
        else
            return FALSE;
    }

    return TRUE;
}

void CResInfoDlg::OnOK() 
{
	// TODO: Add extra validation here
    UpdateData();

    DWORD dwAddr = 0;
    if( !m_bIsOffset )
    {
	    if( m_strAddr.IsEmpty() )
        {
            AfxMessageBox(_T("The resource address isn't empty!"));
            return;
        }

        LPTSTR pStop = NULL;
        dwAddr = _tcstoul(m_strAddr.GetBuffer(0), &pStop, 16);
        if( dwAddr == 0 )
        {
            AfxMessageBox(_T("The resource address must be greater than 0!"));
            return;
        }
    }

    TOOL_USED_INFO_T &tui = g_theApp.m_MMIRes.m_Resource.ToolUsedInfo;
    tui.nBuildNumber  = _ttoi(m_strBuild);
    tui.nMajorVersion = _ttoi(m_strMajorVer);
    tui.nMaxLimitSize = m_nLimit;
    tui.nMinorVersion = _ttoi(m_strMinorVer);
    tui.nStartAddress = dwAddr;
    tui.bAddrIsOffset = m_bIsOffset;
//    tui.bBigEndian    = m_bBigEndian;

	CDialog::OnOK();
}

void CResInfoDlg::OnUpdateEdtAddr() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_UPDATE flag ORed into the lParam mask.
	
	// TODO: Add your control notification handler code here
	CString strText;
    CWnd * pWnd = GetDlgItem(IDC_EDT_ADDR);
    _ASSERTE( pWnd != NULL );

    pWnd->GetWindowText(strText);
    int nLen = strText.GetLength();
    for( int i = 0; i < nLen; ++i )
    {
        if( !CharIsHexChar(strText[i]) )
        {
            pWnd->SetWindowText(m_strAddr);
            pWnd->Invalidate();
            break;
        }
    }
    UpdateData();
}

void CResInfoDlg::OnUpdateEdtLimit() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_UPDATE flag ORed into the lParam mask.
	
	// TODO: Add your control notification handler code here
	CString strText;
    CWnd * pWnd = GetDlgItem(IDC_EDT_LIMIT);
    _ASSERTE( pWnd != NULL );

    pWnd->GetWindowText(strText);
    int nLen = strText.GetLength();
    for( int i = 0; i < nLen; ++i )
    {
        if( !CharIsNumber(strText[i]) )
        {
            strText.Format(_T("%d"), m_nLimit);
            pWnd->SetWindowText(strText);
            pWnd->Invalidate();
            break;
        }
    }
    UpdateData();
}

void CResInfoDlg::OnUpdateEdtMajorver() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_UPDATE flag ORed into the lParam mask.
	
	// TODO: Add your control notification handler code here
	CString strText;
    CWnd * pWnd = GetDlgItem(IDC_EDT_MAJORVER);
    _ASSERTE( pWnd != NULL );

    pWnd->GetWindowText(strText);
    int nLen = strText.GetLength();
    for( int i = 0; i < nLen; ++i )
    {
        if( !CharIsNumber(strText[i]) )
        {
            pWnd->SetWindowText(m_strMajorVer);
            pWnd->Invalidate();
            break;
        }
    }
    UpdateData();
}

void CResInfoDlg::OnUpdateEdtMinorver() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_UPDATE flag ORed into the lParam mask.
	
	// TODO: Add your control notification handler code here
	CString strText;
    CWnd * pWnd = GetDlgItem(IDC_EDT_MINORVER);
    _ASSERTE( pWnd != NULL );

    pWnd->GetWindowText(strText);
    int nLen = strText.GetLength();
    for( int i = 0; i < nLen; ++i )
    {
        if( !CharIsNumber(strText[i]) )
        {
            pWnd->SetWindowText(m_strMinorVer);
            pWnd->Invalidate();
            break;
        }
    }
    UpdateData();
}

void CResInfoDlg::OnUpdateEdtBuild() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_UPDATE flag ORed into the lParam mask.
	
	// TODO: Add your control notification handler code here
	CString strText;
    CWnd * pWnd = GetDlgItem(IDC_EDT_BUILD);
    _ASSERTE( pWnd != NULL );

    pWnd->GetWindowText(strText);
    int nLen = strText.GetLength();
    for( int i = 0; i < nLen; ++i )
    {
        if( !CharIsNumber(strText[i]) )
        {
            pWnd->SetWindowText(m_strBuild);
            pWnd->Invalidate();
            break;
        }
    }
    UpdateData();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -