📄 stockrefer.cpp
字号:
// StockRefer.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "StockRefer.h"
#include "MainFrm.h"
#include "StockReferDoc.h"
#include "StockReferView.h"
#include "StaticEx.h"
#include "SerialNum.h"
#include "DiskSerialNumber.h"
#include "Splash.h"
#include "HttpDown.h"
#include "DlgDownload.h"
#include "CmdWaitDlg.h"
#include "TipDlg.h"
#include "Verinfo.h"
#include "UpdateDlg.h"
#include "RegDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStockReferApp
BEGIN_MESSAGE_MAP(CStockReferApp, CWinApp)
//{{AFX_MSG_MAP(CStockReferApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_HELP_TIP, OnHelpTip)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStockReferApp construction
CStockReferApp::CStockReferApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CStockReferApp object
CStockReferApp theApp;
BOOL HAS_REG = FALSE;
int iCurSel = 0;
/////////////////////////////////////////////////////////////////////////////
// CStockReferApp initialization
BOOL CStockReferApp::InitInstance()
{
if(!m_singleInstance.Create(IDR_MAINFRAME))
return FALSE;
CSerialNum num;
long id = num.GetDiskSerialNo();
m_strUpdateUrl.Format(UPDATE_URL,id,REG_TAG);
m_strAppPath = GetAppPath();
if(m_strAppPath.IsEmpty())
{
AfxMessageBox(IDS_SYSINIT_ERROR,MB_ICONSTOP);
return FALSE;
}
m_strSer = num.GetReg();
CString sdate = num.GetReg(0);
if(m_strSer.IsEmpty() && sdate != _T("1.0.0.1"))
{
if(sdate != _T("1.0.0.0"))
{
sdate = num.Encrypt(200130196);
num.SetReg(sdate);
num.SetReg(_T("1.0.0.0"),0);
}
else
num.SetReg(_T("1.0.0.1"),0);
}
// CG: The following block was added by the Splash Screen component.
{
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
}
// Initialize OLE libraries
if(!AfxOleInit())
{
AfxMessageBox(IDP_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(REG_KEY);
//First free the string allocated by MFC at CWinApp startup.
//The string is allocated before InitInstance is called.
free((void*)m_pszProfileName);
//Change the name of the .INI file.
//The CWinApp destructor will free the memory.
m_pszProfileName=_tcsdup(_T(""));
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(CStockReferDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CStockReferView));
AddDocTemplate(pDocTemplate);
// 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_SHOW);
m_pMainWnd->UpdateWindow();
CString m_strSoftVer = GetMainVer();
if(m_strSoftVer.IsEmpty() || searchver.IsEmpty())
{
AfxMessageBox(IDS_NOFIND_DATA,MB_ICONSTOP);
return FALSE;
}
if(m_strSoftVer != SOFT_VER)
{
m_strSoftVer.LoadString(IDS_OLDVER_FIND);
m_strSoftVer = m_strSoftVer + NEWSEARCH_HOME;
AfxMessageBox(m_strSoftVer,MB_ICONSTOP);
return FALSE;
}
if(!RegisterCheck()) return FALSE;
// CG: This line inserted by 'Tip of the Day' component.
ShowTipAtStartup();
OldVerCheck();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CStatic m_build;
CEdit m_edUser;
CCJHyperLink m_URL;
CStaticEx m_strver;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
void GetRegInfo(LPCTSTR lpszValueName, CString &strRegInfo);
//{{AFX_MSG(CAboutDlg)
virtual BOOL OnInitDialog();
afx_msg void OnButtonSysinfo();
afx_msg void OnButtonTechnic();
//}}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)
DDX_Control(pDX, IDC_STATIC_BUILD, m_build);
DDX_Control(pDX, IDC_EDIT_USER, m_edUser);
DDX_Control(pDX, IDC_STATIC_URL, m_URL);
DDX_Control(pDX, IDC_STATICVER, m_strver);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_BN_CLICKED(IDC_BUTTON_SYSINFO, OnButtonSysinfo)
ON_BN_CLICKED(IDC_BUTTON_TECHNIC, OnButtonTechnic)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CStockReferApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CStockReferApp message handlers
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString m_sver,m_strv,m_stru;
m_strv.LoadString(AFX_IDS_APP_TITLE);
if(HAS_REG)
{
CString strUser,strOrg,strRegNum;
CSerialNum num;
GetRegInfo(_T("UserName"),strUser);
GetRegInfo(_T("Organize"),strOrg);
m_sver.LoadString(IDS_ABOUT_HASREG);
strUser = strUser + _T("\r\n") + strOrg;
strRegNum.LoadString(IDS_REG_NUMBER);
strRegNum = strRegNum + num.GetReg();
strUser = strUser + _T("\r\n") + strRegNum;
m_edUser.SetWindowText(strUser);
}
else
{
m_stru.LoadString(IDS_UNREG_USER);
m_sver.LoadString(IDS_ABOUT_UNREG);
m_edUser.SetWindowText(m_stru);
}
m_strver.SetFontBold(TRUE);
m_strver.SetWindowText(m_strv);
m_strv.Format(_T("(%s %s)"),m_sver,BUILD_VER);
m_build.SetWindowText(m_strv);
m_URL.SetURL(NEWSEARCH_HOME);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CAboutDlg::OnButtonSysinfo()
{
// TODO: Add your control notification handler code here
HKEY hSysKey;
LONG res = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
_T("SOFTWARE\\Microsoft\\Shared Tools\\MSInfo"),
0L,KEY_ALL_ACCESS,&hSysKey);
if (res == ERROR_SUCCESS)
{
DWORD bufsize = _MAX_PATH;
char msinfo[_MAX_PATH];
res = RegQueryValueEx(hSysKey,_T("Path"),0L,0,(LPBYTE)msinfo,
(LPDWORD)&bufsize);
RegCloseKey(hSysKey);
if (res == ERROR_SUCCESS) WinExec(msinfo, SW_SHOW);
}
}
void CStockReferApp::HelpUpdate()
{
// TODO: Add your command handler code here
if(!HAS_REG)
{
AfxMessageBox(_T("您的软件还没有注册,该功能只对注册用户开放。"));
return;
}
CHttpDown news;
CWaitDialog waitdlg;
waitdlg.Show();
CString cont = news.GetHttpFileGet(m_strUpdateUrl);
waitdlg.Close();
RunUpdate(cont);
}
void CStockReferApp::OnHelpTip()
{
// TODO: Add your command handler code here
CTipDlg dlg;
dlg.DoModal();
}
BOOL CStockReferApp::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
// CG: The following lines were added by the Splash Screen component.
if (CSplashWnd::PreTranslateAppMessage(pMsg))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -