1
1
// UseResourceDllView.cpp : implementation of the CUseResourceDllView class
2
//
3
4
#include "stdafx.h"
5
#include "UseResourceDll.h"
6
7
#include "UseResourceDllDoc.h"
8
#include "UseResourceDllView.h"
9
10
#include "Dll_Resource.h"//資源dll(原名:resource.dll,屬于工程resource_dll)
11
12
#ifdef _DEBUG
13
#define new DEBUG_NEW
14
#undef THIS_FILE
15
static char THIS_FILE[] = __FILE__;
16
#endif
17
18
/**////////////////////////////////////////////////////////////////////////////// 19
// CUseResourceDllView
20
21
IMPLEMENT_DYNCREATE(CUseResourceDllView, CView)
22
23
BEGIN_MESSAGE_MAP(CUseResourceDllView, CView)
24
//{{AFX_MSG_MAP(CUseResourceDllView)
25
ON_WM_LBUTTONDOWN()
26
//}}AFX_MSG_MAP
27
// Standard printing commands
28
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
29
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
30
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
31
END_MESSAGE_MAP()
32
33
/**////////////////////////////////////////////////////////////////////////////// 34
// CUseResourceDllView construction/destruction
35
36
CUseResourceDllView::CUseResourceDllView()
37
{
38
// TODO: add construction code here
39
40
}
41
42
CUseResourceDllView::~CUseResourceDllView()
43
{
44
}
45
46
BOOL CUseResourceDllView::PreCreateWindow(CREATESTRUCT& cs)
47
{
48
// TODO: Modify the Window class or styles here by modifying
49
// the CREATESTRUCT cs
50
51
return CView::PreCreateWindow(cs);
52
}
53
54
/**////////////////////////////////////////////////////////////////////////////// 55
// CUseResourceDllView drawing
56
57
void CUseResourceDllView::OnDraw(CDC* pDC)
58
{
59
CUseResourceDllDoc* pDoc = GetDocument();
60
ASSERT_VALID(pDoc);
61
pDC->TextOut (0,0,"請點擊這里改變系統菜單");
62
// TODO: add draw code for native data here
63
}
64
65
/**////////////////////////////////////////////////////////////////////////////// 66
// CUseResourceDllView printing
67
68
BOOL CUseResourceDllView::OnPreparePrinting(CPrintInfo* pInfo)
69
{
70
// default preparation
71
return DoPreparePrinting(pInfo);
72
}
73
74
void CUseResourceDllView::OnBeginPrinting(CDC* /**//*pDC*/, CPrintInfo* /**//*pInfo*/)
75
{
76
// TODO: add extra initialization before printing
77
}
78
79
void CUseResourceDllView::OnEndPrinting(CDC* /**//*pDC*/, CPrintInfo* /**//*pInfo*/)
80
{
81
// TODO: add cleanup after printing
82
}
83
84
/**////////////////////////////////////////////////////////////////////////////// 85
// CUseResourceDllView diagnostics
86
87
#ifdef _DEBUG
88
void CUseResourceDllView::AssertValid() const
89
{
90
CView::AssertValid();
91
}
92
93
void CUseResourceDllView::Dump(CDumpContext& dc) const
94
{
95
CView::Dump(dc);
96
}
97
98
CUseResourceDllDoc* CUseResourceDllView::GetDocument() // non-debug version is inline
99
{
100
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CUseResourceDllDoc)));
101
return (CUseResourceDllDoc*)m_pDocument;
102
}
103
#endif //_DEBUG
104
105
/**////////////////////////////////////////////////////////////////////////////// 106
// CUseResourceDllView message handlers
107
108
void CUseResourceDllView::OnLButtonDown(UINT nFlags, CPoint point)
109
{
110
//下面的代碼是顯式調入資源dll,當然你也可以隱式調入
111
HINSTANCE m_app=::AfxGetInstanceHandle ();//獲得句柄
112
HINSTANCE m_res_dll=::LoadLibrary ("resource_dll.dll");
113
114
AfxSetResourceHandle(m_res_dll);//把當前資源設置從resource_dll.dll中獲取
115
//使用
116
CMenu m_menu;
117
m_menu.LoadMenu (IDR_MENU1);
118
AfxGetMainWnd()->SetMenu (&m_menu);
119
m_menu.Detach ();
120
121
AfxSetResourceHandle(m_app);//還原系統資源
122
FreeLibrary(m_res_dll);//釋放庫
123
//若要響應資源dll中的菜單,你得手工添加消息響應函數
124
CView::OnLButtonDown(nFlags, point);
125
}

posted on 2007-04-24 12:00
喬棟 閱讀(593)
評論(0) 編輯 收藏 引用 所屬分類:
C++的健身房