友情提示:如果本网页打开太慢或显示不完整,请尝试鼠标右键“刷新”本网页!阅读过程发现任何错误请告诉我们,谢谢!! 报告错误
一世书城 返回本书目录 我的书架 我的书签 TXT全本下载 进入书吧 加入书签

深入浅出MFC第2版(PDF格式)-第200章

按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!






#0008 

#0009  class CTipDlg : public CDialog 

#0010  { 

#0011  // Construction 

#0012  public: 

#0013          CTipDlg(CWnd* pParent = NULL);   // standard constructor 

#0014 

#0015  // Dialog Data 

#0016          //{{AFX_DATA(CTipDlg) 

#0017          // enum { IDD = IDD_TIP }; 

#0018          BOOL    m_bStartup; 

#0019          CString m_strTip; 

#0020          //}}AFX_DATA 

#0021 

#0022          FILE* m_pStream; 

#0023 

#0024  // Overrides 

#0025          // ClassWizard generated virtual function overrides 

#0026          //{{AFX_VIRTUAL(CTipDlg) 

#0027          protected: 

#0028          virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support 

#0029          //}}AFX_VIRTUAL 

#0030 

#0031  // Implementation 

#0032  public: 

#0033          virtual ~CTipDlg(); 

#0034 

#0035  protected: 

#0036      // Generated message map functions 

#0037      //{{AFX_MSG(CTipDlg) 

#0038      afx_msg void OnNextTip(); 

#0039      afx_msg HBRUSH OnCtlColor(CDC* pDC; CWnd* pWnd; UINT nCtlColor); 

#0040      virtual void OnOK(); 

#0041      virtual BOOL OnInitDialog(); 

#0042      afx_msg void OnPaint(); 

#0043      //}}AFX_MSG 

#0044      DECLARE_MESSAGE_MAP() 

#0045 

#0046      void GetNextTipString(CString& strNext); 

#0047  }; 

#0048 

#0049  #endif // !defined(TIPDLG_H_INCLUDED_) 



TIPDLG。CPP (全新內容 ) 



#0001  #include 〃stdafx。h〃 



                                                                                              813 


…………………………………………………………Page 876……………………………………………………………

                   第篇    深入  MFC  程式設計 



                   #0002  #include 〃resource。h〃 

                   #0003 

                   #0004  // CG: This file added by 'Tip of the Day' ponent。 

                   #0005 

                   #0006  #include  

                   #0007  #include  

                   #0008  #include  

                   #0009 

                   #0010  #ifdef _DEBUG 

                   #0011  #define new DEBUG_NEW 

                   #0012  #undef THIS_FILE 

                   #0013  static char THIS_FILE'' = __FILE__; 

                   #0014  #endif 

                   #0015 

                   #0016  ///////////////////////////////////////////////////////////////// 

                   #0017  // CTipDlg dialog 

                   #0018 

                   #0019  #define MAX_BUFLEN 1000 

                   #0020 

                   #0021  static const TCHAR szSection'' = _T(〃Tip〃); 

                   #0022  static const TCHAR szIntFilePos'' = _T(〃FilePos〃); 

                   #0023  static const TCHAR szTimeStamp'' = _T(〃TimeStamp〃); 

                   #0024  static const TCHAR szIntStartup'' = _T(〃StartUp〃); 

                   #0025 

                   #0026  CTipDlg::CTipDlg(CWnd* pParent /*=NULL*/) 

                   #0027          : CDialog(IDD_TIP; pParent) 

                   #0028  { 

                   #0029      //{{AFX_DATA_INIT(CTipDlg) 

                   #0030      m_bStartup = TRUE; 

                   #0031      //}}AFX_DATA_INIT 

                   #0032 

                   #0033      // We need to find out what the startup and file position parameters are 

                   #0034      // If startup does not exist; we assume that the Tips on startup is checked TRUE。 

                   #0035      CWinApp* pApp = AfxGetApp(); 

                   #0036      m_bStartup = !pApp…》GetProfileInt(szSection; szIntStartup; 0); 

                   #0037      UINT iFilePos = pApp…》GetProfileInt(szSection; szIntFilePos; 0); 

                   #0038 

                   #0039      // Now try to open the tips file 

                   #0040      m_pStream = fopen(〃tips。txt〃; 〃r〃); 

                   #0041      if (m_pStream == NULL) 

                   #0042      { 

                   #0043              m_strTip。LoadString(CG_IDS_FILE_ABSENT); 

                   #0044              return; 

                   #0045      } 

                   #0046 

                   #0047      // If the timestamp in the INI file is different from the timestamp of 



814 


…………………………………………………………Page 877……………………………………………………………

                            16                            ponents & ActiveX Controls 

                          第 章 站眾的肩膀 使用 



#0048      // the tips file; then we know that the tips file has been modified 

#0049      // Reset the file position to 0 and write the latest timestamp to the 

#0050      // ini file 

#0051      struct _stat buf; 

#0052      _fstat(_fileno(m_pStream); &buf); 

#0053      CString strCurrentTime = ctime(&buf。st_ctime); 

#0054      strCurrentTime。TrimRight(); 

#0055      CString strStoredTime = 

#0056              pApp…》GetProfileString(szSection; szTimeStamp; NULL); 

#0057      if (strCurrentTime != strStoredTime) 

#0058      { 

#0059              iFilePos = 0; 

#0060              pApp…》WriteProfileString(szSection; szTimeStamp; strCurrentTime); 

#0061      } 

#0062 

#0063      if (fseek(m_pStream; iFilePos; SEEK_SET) != 0) 

#0064      { 

#0065              AfxMessageBox(CG_IDP_FILE_CORRUPT); 

#0066      } 

#0067      else 

#0068      { 

#0069              GetNextTipString(m_strTip); 

#0070      } 

#0071  } 

#0072 

#0073  CTipDlg::~CTipDlg() 

#0074  { 

#0075      // This destructor is executed whether the user had pressed the escape key 

#0076      // or clicked on the close button。 If the user had pressed the escape key; 

#0077      // it is still required to update the filepos in the ini file with the 

#0078      // latest position so that we don't repeat the tips! 

#0079 

#0080      // But make sure the tips file existed in the first place。。。。 

#0081      if (m_pStream != NULL) 

#0082      { 

#0083              CWinApp* pApp = AfxGetApp(); 

#0084              pApp…》WriteProfileInt(szSection; szIntFilePos; ftell(m_pStream)); 

#0085              fclose(m_pStream); 

#0086      } 

#0087  } 

#0088 

#0089  void CTipDlg::DoDataExchange(CDataExchange* pDX) 

#0090  { 

#0091      CDialog::DoDataExchange(pDX); 

#0092      //{{AFX_DATA_MAP(CTipDlg) 

#0093      DDX_Check(pDX; IDC_STARTUP; m_bStartup); 



                                                                                                815 


…………………………………………………………Page 878……………………………………………………………

                    第篇    深入  MFC  程式設計 



                    #0094      DDX_Text(pDX; IDC_TIPSTRING; m_strTip); 

                    #0095      //}}AFX_DATA_MAP 

                    #0096  } 

                    #0097 

                    #0098  BEGIN_MESSAGE_MAP(CTipDlg; CDialog) 

                    #0099      //{{AFX_MSG_MAP(CTipDlg) 

                    #0100      ON_BN_CLICKED(IDC_NEXTTIP; OnNextTip) 

                    #0101      ON_WM_CTLCOLOR() 

                    #0102      ON_WM_PAINT() 

                    #0103      //}}AFX_MSG_MAP 

                    #0104  END_MESSAGE_MAP() 

                    #0105 

                    #0106  ///////////////////////////////////////////////////////////////// 

                    #0107  // CTipDlg message handlers 

                    #0108 

                    #0109  void CTipDlg::OnNextTip() 

                    #0110  { 

                    #0111      GetNextTipString(m_strTip); 

                    #0112      UpdateData(FALSE); 

                    #0113  } 

                    #0114 

                    #0115  void CTipDlg::GetNextTipString(CString& strNext) 

                    #0116  { 

                    #0117      LPTSTR lpsz = strNext。GetBuffer(MAX_BUFLEN); 

                    #0118 

                    #0119      // This routine identifies the next string that needs to be 

                    #0120      // read from the tips file 

                    #0121      BOOL bStop = FALSE; 
返回目录 上一页 下一页 回到顶部 0 1
未阅读完?加入书签已便下次继续阅读!
温馨提示: 温看小说的同时发表评论,说出自己的看法和其它小伙伴们分享也不错哦!发表书评还可以获得积分和经验奖励,认真写原创书评 被采纳为精评可以获得大量金币、积分和经验奖励哦!