八宝书库 > 文学其他电子书 > 深入浅出MFC第2版(PDF格式) >

第158部分

深入浅出MFC第2版(PDF格式)-第158部分

小说: 深入浅出MFC第2版(PDF格式) 字数: 每页4000字

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




#0010          // NOTE the ClassWizard will add and remove mapping macros here。 

#0011          //    DO NOT EDIT what you see in these blocks of generated code! 

#0012      //}}AFX_MSG_MAP 

#0013      // Standard file based document mands 

#0014      ON_MAND(ID_FILE_NEW; CWinApp::OnFileNew) 

#0015      ON_MAND(ID_FILE_OPEN; CWinApp::OnFileOpen) 

#0016      // Standard print setup mand 

#0017      ON_MAND(ID_FILE_PRINT_SETUP; CWinApp::OnFilePrintSetup) 

#0018  END_MESSAGE_MAP() 

#0019 

#0020  BOOL CTestApp::InitInstance() 

#0021  { 

#0022      // CG: The following block was added by the Splash Screen ponent。 



                                                                                             803 


…………………………………………………………Page 866……………………………………………………………

                   第篇    深入  MFC  程式設計 



                   #0023      { 

                   #0024         CmandLineInfo cmdInfo; 

                   #0025         ParsemandLine(cmdInfo); 

                   #0026         CSplashWnd::EnableSplashScreen(cmdInfo。m_bShowSplash); 

                   #0027      } 

                   #0028 

                   #0029      AfxEnableControlContainer(); 

                   #0030      。。。 

                   #0031 

                   #0032      // CG: This line inserted by 'Tip of the Day' ponent。 

                   #0033      ShowTipAtStartup(); 

                   #0034 

                   #0035      return TRUE; 

                   #0036  } 

                   #0037  。。。 

                   #0038  BOOL CTestApp::PreTranslateMessage(MSG* pMsg) 

                   #0039  { 

                   #0040      // CG: The following lines were added by the Splash Screen ponent。 

                   #0041      if (CSplashWnd::PreTranslateAppMessage(pMsg)) 

                   #0042          return TRUE; 

                   #0043 

                   #0044      return CWinApp::PreTranslateMessage(pMsg); 

                   #0045  } 

                   #0046 

                   #0047  BOOL CAboutDlg::OnInitDialog() 

                   #0048  { 

                   #0049      CDialog::OnInitDialog();  // CG: This was added by System Info ponent。 

                   #0050 

                   #0051      // CG: Following block was added by System Info ponent。 

                   #0052      { 

                   #0053          CString strFreeDiskSpace; 

                   #0054          CString strFreeMemory; 

                   #0055          CString strFmt; 

                   #0056 

                   #0057          // Fill available memory 

                   #0058          MEMORYSTATUS MemStat; 

                   #0059          MemStat。dwLength = sizeof(MEMORYSTATUS); 

                   #0060          GlobalMemoryStatus(&MemStat); 

                   #0061          strFmt。LoadString(CG_IDS_PHYSICAL_MEM); 

                   #0062          strFreeMemory。Format(strFmt; MemStat。dwTotalPhys / 1024L); 

                   #0063 

                   #0064          //TODO: Add a static control to your About Box to receive the memory 

                   #0065          //      information。  Initialize the control with code like this: 

                   #0066          // SetDlgItemText(IDC_PHYSICAL_MEM; strFreeMemory); 

                   #0067 

                   #0068          // Fill disk free information 



804 


…………………………………………………………Page 867……………………………………………………………

                            16                            ponents & ActiveX Controls 

                         第 章 站眾的肩膀 使用 



#0069          struct _diskfree_t diskfree; 

#0070          int nDrive = _getdrive(); // use current default drive 

#0071          if (_getdiskfree(nDrive; &diskfree) == 0) 

#0072          { 

#0073              strFmt。LoadString(CG_IDS_DISK_SPACE); 

#0074              strFreeDiskSpace。Format(strFmt; 

#0075                      (DWORD)diskfree。avail_clusters * 

#0076                      (DWORD)diskfree。sectors_per_cluster * 

#0077                      (DWORD)diskfree。bytes_per_sector / (DWORD)1024L; 

#0078                      nDrive…1 + _T('A')); 

#0079          } 

#0080          else 

#0081              strFreeDiskSpace。LoadString(CG_IDS_DISK_SPACE_UNAVAIL); 

#0082 

#0083          //TODO: Add a static control to your About Box to receive the memory 

#0084          //      information。  Initialize the control with code like this: 

#0085          // SetDlgItemText(IDC_DISK_SPACE; strFreeDiskSpace); 

#0086      } 

#0087 

#0088      return TRUE;    // CG:  This was added by System Info ponent。 

#0089  } 



TEST。RC           (阴影部份为新增内容) 



IDB_SPLASH  BITMAP  DISCARDABLE  〃Splsh16。bmp〃 

。。。 

IDD_TIP DIALOG DISCARDABLE  0; 0; 231; 164 

STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU 

CAPTION 〃Tip of the Day〃 

FONT 8; 〃MS Sans Serif〃 

BEGIN 

    CONTROL           〃〃;…1;〃Static〃;SS_BLACKFRAME;12;11;207;123 

    LTEXT               〃Some String〃;IDC_TIPSTRING;28;63;177;60 

    CONTROL           〃&Show Tips on StartUp〃;IDC_STARTUP;〃Button〃; 

                        BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP;13;146;85;10 

    PUSHBUTTON       〃&Next Tip〃;IDC_NEXTTIP;109;143;50;14;WS_GROUP 

    DEFPUSHBUTTON    〃&Close〃;IDOK;168;143;50;14;WS_GROUP 

    CONTROL           〃〃;IDC_BULB;〃Static〃;SS_BITMAP;20;17;190;111 

END 

。。。 

STRINGTABLE DISCARDABLE 

BEGIN 

    CG_IDS_PHYSICAL_MEM             〃%lu KB〃 

    CG_IDS_DISK_SPACE               〃%lu KB Free on %c:〃 

    CG_IDS_DISK_SPACE_UNAVAIL  〃Unavailable〃 

    CG_IDS_TIPOFTHEDAY              〃Displays a Tip of the Day。〃 



                                                                                               805 


…………………………………………………………Page 868……………………………………………………………

                    第篇    深入  MFC  程式設計 



                        CG_IDS_TIPOFTHEDAYMENU        〃Ti&p of the Day。。。〃 

                        CG_IDS_DIDYOUKNOW             〃Did You Know。。。〃 

                    CG_IDS_FILE_ABSENT   〃Tips file does not exist in the prescribed directory! ¨ 

                    END 



                    STRINGTABLE DISCARDABLE 

                    BEGIN 

                        CG_IDP_FILE_CORRUPT     〃Trouble reading the tips file〃 

                        CG_IDS_TIPOFTHEDAYHELP  〃&Help〃 

                    END 



                    MA INFRM。H  (阴影部份为新增内容) 



                    class CMainFrame : public CMDIFrameWnd 

                    { 

                    。。。 

                    // Overrides 

                            // ClassWizard generated virtual function overrides 

                            //{{AFX_VIRTUAL(CMainFrame) 

                            virtual BOOL PreCreateWindow(CREATESTRUCT& cs); 

                            //}}AFX_VIRTUAL 

                    。。。 

                    // Generated message map functions 

                    protected: 

                            afx_msg void OnInitMenu(CMenu* pMenu); 

                            。。。 

                    }; 



                    MA INFRM。CPP  (阴影部份为新增内容) 



                    #0001  。。。 

                    #0002  #include 〃Splash。h〃 

                    #0003  。。。 

                    #0004  int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 

                    #0005  { 

                    #0006      。。。 

                    #0007      // CG: The following line was added by the Splash Screen ponent。 

                    #0008      CSplashWnd::ShowSplashScreen(this); 

                    #0009 

                    #0010      return 0; 

                    #0011  } 

                    #0012  。。。 

                    #0013  ///////////////////////////////////////////////////////////////// 

                    #0014  // CMainFrame message handlers 

                    #0015 



806 


…………………………………………………………Page 869……………………………………………………………

                             16                            ponents & ActiveX Controls 

                          第 章 站眾的肩膀 使用 



#0016  void CMainFrame::OnInitMenu(CMenu* pMenu) 

#0017  { 

#0018      CMDIFrameWnd::OnInitMenu(pMenu); 

#0019 

#0020      // CG: This block added by 'Tip of the Day' ponent。 

#0021      { 

#0022          // TODO: This code adds the 〃Tip of the Day〃 menu item 

#0023          // on the fly。  It may be removed after adding the menu 

#0024          // item to all applicable menu items using the resource 

#0025          // editor。 

#0026 

#0027          // Add Tip of the Day menu item on the fly! 

#0028          static CMenu* pSubMenu = NULL; 

#0029 

#0030          CString strHelp; strHelp。LoadString(CG_IDS_TIPOFTHEDAYHELP); 

#0031          CString strMenu; 

#0032          int nMenuCount = pMenu…》GetMenuItemCount(); 

#0033          BOOL bFound = FALSE; 

#0034          for (int i=0; i 《 nMenuCount; i++) 

#0035          { 

#0036              pMenu…》GetMenuString(i; strMenu; MF_BYPOSITION); 

#0037              if (strMenu == strHelp) 

#0038              { 

#0039                  pSubMenu = pMenu…》GetSubMenu(i); 

#0040                  bFound = TRUE; 

#0041                  ASSERT(pSubMenu != NULL); 

#0042              } 

#0043          } 

#0044 

#0045          CString strTipMenu; 

#0046          strTipMenu。LoadString(CG_IDS_TIPOFTHEDAYMENU); 

#0047          if (!bFound) 

#0048          { 

#0049              // Help menu is not available。 Please add it! 

#0050              if (pSubMenu == NULL) 

#0051              { 

#0052                  // The same pop…up menu is shared between mainfrm and 

frame 

#0053                  // with the doc。 

#0054                  static CMenu popUpMenu; 

#0055                  pSubMenu = &popUpMenu; 

#0056                  pSubMenu…》CreatePopupMenu(); 

#0057                

返回目录 上一页 下一页 回到顶部 0 0

你可能喜欢的