-
Notifications
You must be signed in to change notification settings - Fork 0
/
Birds.cpp
executable file
·67 lines (53 loc) · 1.46 KB
/
Birds.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Birds.cpp : 定义应用程序的类行为。
//
#include "stdafx.h"
#include "Birds.h"
#include "BirdsDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CBirdsApp
BEGIN_MESSAGE_MAP(CBirdsApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// CBirdsApp 构造
CBirdsApp::CBirdsApp() :m_randEng((unsigned int)time(0))
{
m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
}
CBirdsApp theApp;
BOOL CBirdsApp::InitInstance()
{
srand((unsigned)time(0));
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
CBirdsDlg dlg;
m_pMainWnd = &dlg;
dlg.DoModal();
return FALSE;
}
int CBirdsApp::ExitInstance()
{
GdiplusShutdown(m_gdiplusToken);
return CWinApp::ExitInstance();
}
BOOL CBirdsApp::ImageFromIDResource(UINT nID, LPCTSTR sTR, Image *&pImg)
{
HINSTANCE hInst = AfxGetResourceHandle();
HRSRC hRsrc = ::FindResource(hInst, MAKEINTRESOURCE(nID), sTR);
if (!hRsrc) return FALSE;
DWORD len = SizeofResource(hInst, hRsrc);
BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
if (!lpRsrc) return FALSE;
HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, len);
BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
memcpy(pmem, lpRsrc, len);
GlobalUnlock(m_hMem);
IStream* pstm;
CreateStreamOnHGlobal(m_hMem, FALSE, &pstm);
pImg = Gdiplus::Image::FromStream(pstm);
pstm->Release();
FreeResource(lpRsrc);
GlobalFree(m_hMem);
return TRUE;
}