📄 elecdemo.cpp
字号:
// ElecDemo.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "ElecDemo.h"
#include "ElecDemoDlg.h"
#include "mjsplash.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CElecDemoApp
BEGIN_MESSAGE_MAP(CElecDemoApp, CWinApp)
//{{AFX_MSG_MAP(CElecDemoApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CElecDemoApp construction
CElecDemoApp::CElecDemoApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CElecDemoApp object
CElecDemoApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CElecDemoApp initialization
BOOL CElecDemoApp::InitInstance()
{
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
SetRegistryKey(_T("MJSOFT"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
CMJSplash splash;
CString str;
str=getPath()+"splash.jpg";
splash.SetSplash(str);
splash.AddSplashString(" 模拟电子多媒体教学");
splash.AddSplashString(" 策 划:何召兰");
splash.AddSplashString(" 程序编写:何召兰 郭瑞杰");
splash.AddSplashString(" 动 画:何召兰 叶宏 ");
splash.AddSplashString(" 其他成员:王竹萍 黄昆 ");
splash.AddSplashString(" 王军 景方 ");
splash.SetXPos(80);
splash.Show();
CElecDemoDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
CString getPath()
{
TCHAR Path[MAX_PATH];
::GetModuleFileName(NULL,Path,MAX_PATH);
CString sPath(Path);
TCHAR szPath[_MAX_PATH];
LPTSTR lpszName;
GetFullPathName(sPath, _MAX_PATH, szPath, &lpszName);
CString mPath = szPath;
int p = mPath.Find(lpszName, 0);
if (p > -1)
{
mPath.Delete(p, strlen(lpszName));
}
p = mPath.GetLength() - 1;
if(mPath.GetAt(p) == '\\')
mPath.Delete(p, 1);
return mPath + '\\';
}
BOOL LoadPictureFile( LPCTSTR szFile, CBitmap* pBitmap, CSize& mSize)
{
// open file
HANDLE hFile = CreateFile(szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if(INVALID_HANDLE_VALUE == hFile)
{
return FALSE;
/*CString str;
str.Format("载入图片:%s时出错!",szFile);
AfxMessageBox(str);
AfxGetApp()->GetMainWnd()->SendMessage(WM_CLOSE);*/
}
// get file size
DWORD dwFileSize = GetFileSize(hFile, NULL);
if(-1 == dwFileSize)
{
return FALSE;
/*CString str;
str.Format("载入图片:%s时出错!",szFile);
AfxMessageBox(str);
AfxGetApp()->GetMainWnd()->SendMessage(WM_CLOSE);*/
}
LPVOID pvData = NULL;
// alloc memory based on file size
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
if(NULL == hGlobal)
{
/* CString str;
str.Format("载入图片:%s时出错!",szFile);
AfxMessageBox(str);
AfxGetApp()->GetMainWnd()->SendMessage(WM_CLOSE);*/
return FALSE;
}
pvData = GlobalLock(hGlobal);
_ASSERTE(NULL != pvData);
DWORD dwBytesRead = 0;
// read file and store in global memory
BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);
_ASSERTE(FALSE != bRead);
GlobalUnlock(hGlobal);
CloseHandle(hFile);
LPSTREAM pstm = NULL;
// create IStream* from global memory
HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);
_ASSERTE(SUCCEEDED(hr) && pstm);
// Create IPicture from image file
LPPICTURE gpPicture;
hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID *)&gpPicture);
_ASSERTE(SUCCEEDED(hr) && gpPicture);
pstm->Release();
OLE_HANDLE m_picHandle;
gpPicture->get_Handle(&m_picHandle);
pBitmap->DeleteObject();
pBitmap->Attach((HGDIOBJ) m_picHandle);
BITMAP bm;
GetObject(pBitmap->m_hObject, sizeof(bm), &bm);
mSize.cx = bm.bmWidth; //nWidth;
mSize.cy = bm.bmHeight; //nHeight;
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -