www.pudn.com > OSDemo.rar > MainFrm.cpp


// MainFrm.cpp : implementation of the CMainFrame class 
// 
 
#include "stdafx.h" 
#include "OSDemo.h" 
 
#include "MainFrm.h" 
#include "Splash.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame 
 
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) 
 
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) 
	//{{AFX_MSG_MAP(CMainFrame) 
	ON_WM_CREATE() 
	ON_COMMAND(ID_MENU_EXER1, OnMenuExer1) 
	ON_COMMAND(ID_MENU_EXER2, OnMenuExer2) 
	ON_COMMAND(ID_MENU_EXER3, OnMenuExer3) 
	ON_COMMAND(ID_MENU_EXER4, OnMenuExer4) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
static UINT indicators[] = 
{ 
	ID_SEPARATOR,           // status line indicator 
	ID_INDICATOR_CAPS, 
	ID_INDICATOR_NUM, 
	ID_INDICATOR_SCRL, 
}; 
 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame construction/destruction 
 
CMainFrame::CMainFrame() 
{ 
	// TODO: add member initialization code here 
} 
 
CMainFrame::~CMainFrame() 
{ 
} 
 
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{ 
	CSplashWnd::ShowSplashScreen(this); 
	Sleep(1500); 
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	ShowWindow(SW_MAXIMIZE); 
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP 
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || 
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) 
	{ 
		TRACE0("Failed to create toolbar\n"); 
		return -1;      // fail to create 
	} 
 
	if (!m_wndStatusBar.Create(this) || 
		!m_wndStatusBar.SetIndicators(indicators, 
		  sizeof(indicators)/sizeof(UINT))) 
	{ 
		TRACE0("Failed to create status bar\n"); 
		return -1;      // fail to create 
	} 
     
	m_ilTB.Create(32, 32, TRUE | ILC_COLOR8, 4, 0); 
	HICON hIcon = NULL; 
    
	hIcon = (HICON)::LoadImage(::AfxGetInstanceHandle(),  
		MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 32, 32, 0); 
	m_ilTB.Add(hIcon); 
 
	hIcon = (HICON)::LoadImage(::AfxGetInstanceHandle(),  
		MAKEINTRESOURCE(IDI_ICON2), IMAGE_ICON, 32, 32, 0); 
	m_ilTB.Add(hIcon); 
 
	hIcon = (HICON)::LoadImage(::AfxGetInstanceHandle(),  
		MAKEINTRESOURCE(IDI_ICON3), IMAGE_ICON, 32, 32, 0); 
	m_ilTB.Add(hIcon); 
 
	hIcon = (HICON)::LoadImage(::AfxGetInstanceHandle(),  
		MAKEINTRESOURCE(IDI_ICON4), IMAGE_ICON, 32, 32, 0); 
	m_ilTB.Add(hIcon); 
 
	m_wndToolBar.GetToolBarCtrl().SetImageList(&m_ilTB); 
	// TODO: Delete these three lines if you don't want the toolbar to 
	//  be dockable 
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); 
    
	EnableDocking(CBRS_ALIGN_ANY); 
	DockControlBar(&m_wndToolBar); 
     
	// CG: The following line was added by the Splash Screen component.
	 
	return 0; 
} 
 
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	if( !CFrameWnd::PreCreateWindow(cs) ) 
		return FALSE; 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return TRUE; 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame diagnostics 
 
#ifdef _DEBUG 
void CMainFrame::AssertValid() const 
{ 
	CFrameWnd::AssertValid(); 
} 
 
void CMainFrame::Dump(CDumpContext& dc) const 
{ 
	CFrameWnd::Dump(dc); 
} 
 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame message handlers 
 
 
void CMainFrame::OnMenuExer1()  
{ 
	// TODO: Add your command handler code here 
	ShowJob(1); 
} 
 
void CMainFrame::OnMenuExer2()  
{ 
	// TODO: Add your command handler code here 
	ShowJob(2); 
} 
 
void CMainFrame::OnMenuExer3()  
{ 
	// TODO: Add your command handler code here 
	ShowJob(3); 
} 
 
void CMainFrame::OnMenuExer4()  
{ 
	// TODO: Add your command handler code here 
	ShowJob(4); 
} 
 
void CMainFrame::ShowJob(int n) 
{ 
       CFile f;  
	   char pTempPath[64]; 
	   GetTempPath(sizeof(pTempPath),pTempPath); 
       char* pFileName = "实验内容.doc"; 
	   strcat(pTempPath,pFileName); 
       if( !f.Open( pTempPath, CFile::modeCreate | CFile::modeWrite, NULL ) ) 
       { 
              AfxMessageBox("Can not create file!"); 
       } 
       CString path = f.GetFilePath(); 
       HGLOBAL hRes; 
       HRSRC hResInfo; 
     //获取应用实例   
       HINSTANCE insApp = AfxGetInstanceHandle(); 
     //寻找EXE资源名 
       hResInfo = FindResource(insApp,(LPCSTR)IDR_EXER1+n-1,"EXER1"); 
       hRes = LoadResource(insApp,hResInfo );   // Load it 
       DWORD dFileLength = SizeofResource( insApp, hResInfo );  //计算EXE文件大小  
       f.WriteHuge((LPSTR)hRes,dFileLength);  //写入临时文件  
       f.Close(); 
       HINSTANCE HINSsd = ShellExecute(NULL,"open",path, NULL, NULL, SW_SHOWNORMAL); 
} 
 
 
 
void CMainFrame::ApplySkin(int n) 
{ 
       CFile f;  
	   char pSkinFile[64]; 
	   GetTempPath(sizeof(pSkinFile),pSkinFile); 
       char* pFileName = "myskin.smf"; 
	   strcat(pSkinFile,pFileName); 
	   DeleteFile(pFileName); 
       if( !f.Open( pSkinFile, CFile::modeCreate | CFile::modeWrite, NULL ) ) 
       { 
              AfxMessageBox("Can not create file!"); 
       } 
       CString path = f.GetFilePath(); 
       HGLOBAL hRes; 
       HRSRC hResInfo; 
       HINSTANCE insApp = AfxGetInstanceHandle(); 
       hResInfo = FindResource(insApp,(LPCSTR)IDR_SHELL1,"SHELL"); 
       hRes = LoadResource(insApp,hResInfo );   // Load it 
       DWORD dFileLength = SizeofResource( insApp, hResInfo );  //计算EXE文件大小  
       f.WriteHuge((LPSTR)hRes,dFileLength);  //写入临时文件  
       f.Close(); 
	   LoadSkinFile(pSkinFile); 
}     
 
 
 
void CMainFrame::OnMnuNoshell()  
{ 
    RemoveWindowSkin( m_hWnd ); 
	RemoveDialogSkin();	 
}