NoPassword.cpp
上传用户:chenhai826
上传日期:2007-04-11
资源大小:72k
文件大小:5k
- // NoPassword.cpp : Defines the class behaviors for the application.
- //
- #include "stdafx.h"
- #include "NoPassword.h"
- #include "MainFrm.h"
- #include "NPDoc.h"
- #include "NPView.h"
- #include "MySocket.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CNPApp
- BEGIN_MESSAGE_MAP(CNPApp, CWinApp)
- //{{AFX_MSG_MAP(CNPApp)
- ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- // Standard file based document commands
- ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
- ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CNPApp construction
- CNPApp::CNPApp()
- {
- }
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CNPApp object
- CNPApp theApp;
- CString CNPApp::m_strSaveFile;
- int CNPApp::m_Scale;
- int CNPApp::m_Sampling;
- BOOL CNPApp::m_bAutoShutDown;
- /////////////////////////////////////////////////////////////////////////////
- // CNPApp initialization
- BOOL CNPApp::InitInstance()
- {
- WSADATA sock_init;
- if(WSAStartup(MAKEWORD(1,1),&sock_init))
- {
- AfxMessageBox("套节字初始化失败!");
- return FALSE;
- }
- AfxEnableControlContainer();
- #ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
- #else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
- #endif
- SetRegistryKey(_T("LML software"));
- LoadStdProfileSettings(); // Load standard INI file options (including MRU)
- if(!LoadSettings())
- {
- m_bAutoShutDown = FALSE;
- m_Sampling = 4;
- m_Scale = 20;
- m_strSaveFile = "C:\NoPassLog.txt";
- SaveSettings();
- }
- CSingleDocTemplate* pDocTemplate;
- pDocTemplate = new CSingleDocTemplate(
- IDR_MAINFRAME,
- RUNTIME_CLASS(CNPDoc),
- RUNTIME_CLASS(CMainFrame), // main SDI frame window
- RUNTIME_CLASS(CNPView));
- AddDocTemplate(pDocTemplate);
- // Enable DDE Execute open
- EnableShellOpen();
- RegisterShellFileTypes(TRUE);
- // 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();
- // Enable drag/drop open
- m_pMainWnd->DragAcceptFiles();
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // 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)
- virtual BOOL OnInitDialog();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- void CNPApp::SaveSettings(void)
- {
- char *section = _T("Settings");
- WriteProfileString(section,_T("LogFilePathName"),m_strSaveFile);
- WriteProfileInt(section,_T("Sampling"),m_Sampling);
- WriteProfileInt(section,_T("Scale"),m_Scale);
- WriteProfileInt(section,_T("AutoShutDown"),m_bAutoShutDown);
- }
- bool CNPApp::LoadSettings(void)
- {
- char *section = _T("Settings");
- m_strSaveFile = GetProfileString(section,_T("LogFilePathName"));
- m_Sampling = GetProfileInt(section,_T("Sampling"),-1);
- m_Scale = GetProfileInt(section,_T("Scale"),-1);
- m_bAutoShutDown = GetProfileInt(section,_T("AutoShutDown"),0);
- return m_Sampling != -1;
- }
- 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 CNPApp::OnAppAbout()
- {
- CAboutDlg aboutDlg;
- aboutDlg.DoModal();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CNPApp message handlers
- BOOL CAboutDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- CFile file;
- if(file.Open("Readme.txt",CFile::modeRead|CFile::typeBinary))
- {
- int size = file.GetLength();
- char *buf = new char [size + 1];
- memset(buf,0,size+1);
- size = file.Read(buf,size);
- SetDlgItemText(IDC_EDIT1,buf);
- delete buf;
- }
- else
- {
- SetDlgItemText(IDC_EDIT1,"找不到Readme.txt文件!");
- }
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }