?? minidatabase.cpp.txt
字號:
// MiniDatabase.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "MiniDatabase.h"
#include "MainFrm.h"
#include "MiniDatabaseDoc.h"
#include "TextView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
MY_VIEW g_MyViews[MY_VIEW_NUM] =
{
{_T("數據庫文件"), _T("編輯數據庫文件")},
{_T("比較數據庫"), _T("比較數據庫文件")},
{_T("數據庫文本"), _T("")}
};
static char my_db_last_error[400];
extern "C" void tool_save_error(char *fmt, char *func, uint ln, uint r)
{
sprintf(my_db_last_error, fmt, func, ln, r);
}
char *my_get_last_error()
{
return my_db_last_error;
}
// 一些公用函數
BOOL CheckKeyName(CString strKey)
{
int nCount = strKey.GetLength();
if (!isalpha(strKey[0]) && strKey[0] != '_')
return FALSE;
for (int i = 0; i < nCount; i++)
{
int c = strKey[i];
if (!isalnum(c) && c != '_')
return FALSE;
}
return TRUE;
}
ULONG StringToULong(char *str, char **stopped)
{
ulong v;
/* 判斷是否16進制 */
if (str[0] == '0' && toupper(str[1]) == 'X')
v = strtoul(&str[2], stopped, 16);
else /* 10進制 */
v = strtoul(str, stopped, 10);
return v;
}
BOOL IsFitNumber(LPCTSTR pszChars, int nLength)
{
if (nLength > 2 && pszChars[0] == '0' && pszChars[1] == 'x')
{
for (int I = 2; I < nLength; I++)
{
if (isdigit(pszChars[I]) || (pszChars[I] >= 'A' && pszChars[I] <= 'F') ||
(pszChars[I] >= 'a' && pszChars[I] <= 'f'))
continue;
return FALSE;
}
return TRUE;
}
if (! isdigit(pszChars[0]))
return FALSE;
for (int I = 1; I < nLength; I++)
{
if (! isdigit(pszChars[I]) && pszChars[I] != '+' &&
pszChars[I] != '-' && pszChars[I] != '.' && pszChars[I] != 'e' &&
pszChars[I] != 'E')
return FALSE;
}
return TRUE;
}
int ReadArrayValue(CString strValues, void **ptr, int *vcnt, int nFieldType)
{
BYTE *tmp_val = (BYTE *)MY_MALLOC(MAX_BLOCK_SIZE, 0);
int val_count = 0;
UINT cp_size = 0;
#define set_array_value(type, val, array, at) \
do { \
switch (type) \
{ \
case FIELD_TYPE_BYTE: \
((byte *)array)[at] = (byte)val; \
break; \
case FIELD_TYPE_SHORT: \
((short *)array)[at] = (short)val; \
break; \
case FIELD_TYPE_WORD: \
((word *)array)[at] = (word)val; \
break; \
case FIELD_TYPE_INT: \
((int *)array)[at] = (int)val; \
break; \
case FIELD_TYPE_UINT: \
((uint *)array)[at] = (uint)val; \
break; \
default: \
FREE_RETURN(DBE_UNKNOW_DATA_TYPE); \
} \
at++; \
} while(0)
if (!tmp_val)
return(DBE_NO_MEMORY_BLOCK);
#define FREE_RETURN(r) do {my_free(tmp_val, 0); return(r);} while(0)
if (vcnt == NULL)
FREE_RETURN(DBE_ARRAY_COUNT_NULL);
strValues.TrimLeft();
strValues.TrimRight();
while (!strValues.IsEmpty())
{
int nPos;
CString strV;
if ((nPos = strValues.Find(',')) >= 0)
{
strV = strValues.Left(nPos);
strValues = strValues.Right(strValues.GetLength() - nPos - 1);
strValues.TrimLeft();
}
else if (!strValues.IsEmpty())
{
strV = strValues;
strValues.Empty();
}
else
break;
if (!IsFitNumber(strV, strV.GetLength()))
FREE_RETURN(DBE_ILLEGAL_NUMBER);
char *szStopped;
ULONG v = StringToULong((char *)(LPCTSTR)strV, &szStopped);
set_array_value(nFieldType, v, tmp_val, val_count);
}
if (val_count > *vcnt)
FREE_RETURN(DBE_RDA_COUNT_OVERFLOW);
switch (nFieldType)
{
case FIELD_TYPE_CHAR:
case FIELD_TYPE_BYTE:
cp_size = sizeof(char);
break;
case FIELD_TYPE_SHORT:
case FIELD_TYPE_WORD:
cp_size = sizeof(short);
break;
case FIELD_TYPE_INT:
case FIELD_TYPE_UINT:
cp_size = sizeof(int);
break;
default:
FREE_RETURN(DBE_UNKNOW_DATA_TYPE);
}
if (*ptr == NULL)
{
*ptr = new BYTE[cp_size * (*vcnt)];
memset(*ptr, 0, cp_size * (*vcnt));
}
memcpy(*ptr, tmp_val, cp_size * val_count);
if (vcnt)
*vcnt = val_count;
#undef FREE_RETURN
my_free(tmp_val, 0);
return(DB_SUCCESS);
}
/////////////////////////////////////////////////////////////////////////////
// CMiniDatabaseApp
BEGIN_MESSAGE_MAP(CMiniDatabaseApp, CWinApp)
//{{AFX_MSG_MAP(CMiniDatabaseApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMiniDatabaseApp construction
CMiniDatabaseApp::CMiniDatabaseApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMiniDatabaseApp object
CMiniDatabaseApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CMiniDatabaseApp initialization
BOOL CMiniDatabaseApp::InitInstance()
{
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
// initialized OLE 2.0 libraries
if (!AfxOleInit())
{
AfxMessageBox(IDS_OLE_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(0); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMiniDatabaseDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
NULL);
AddDocTemplate(pDocTemplate);
// Enable DDE Execute open
EnableShellOpen();
RegisterShellFileTypes(TRUE);
init_memory_mgr();
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();
return TRUE;
}
int CMiniDatabaseApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
end_memory_mgr();
return CWinApp::ExitInstance();
}
UINT CMiniDatabaseApp::GetActiveViewID()
{
CMainFrame *frm = (CMainFrame *)m_pMainWnd;
if (frm)
return frm->GetViewID(frm->GetActiveView());
else
return MY_VIEW_NUM;
}
/////////////////////////////////////////////////////////////////////////////
// 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()
// App command to run the dialog
void CMiniDatabaseApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CMiniDatabaseApp message handlers
void CMiniDatabaseApp::OnFileNew()
{
// TODO: Add your command handler code here
CMainFrame *frm = (CMainFrame *)m_pMainWnd;
UINT nID = GetActiveViewID();
switch (nID)
{
case EDB_VIEW_ID:
if (frm)
frm->PostMessage(WM_FILE_NEW, 0, nID);
break;
case CMP_VIEW_ID:
if (frm)
frm->PostMessage(WM_FILE_NEW, 0, nID);
break;
case TEXT_VIEW_ID: // 打開文本
default: // 第一次調用
CWinApp::OnFileNew();
break;
}
}
void CMiniDatabaseApp::OnFileOpen()
{
// TODO: Add your command handler code here
CMainFrame *frm = (CMainFrame *)m_pMainWnd;
UINT nID = GetActiveViewID();
switch (nID)
{
case EDB_VIEW_ID:
if (frm)
frm->PostMessage(WM_FILE_OPEN, 0, nID);
break;
case CMP_VIEW_ID:
if (frm)
frm->PostMessage(WM_FILE_OPEN, 0, nID);
break;
case TEXT_VIEW_ID: // 打開文本
default: // 第一次調用
CWinApp::OnFileOpen();
break;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -