使用 Visual C++ 2008 功能包加强 Windows 应用程序
来源:互联网 发布:以撒的结合mac破解版 编辑:程序博客网 时间:2024/05/21 10:01
- Microsoft 基础类库更新
- 使用 C++ 对功能区进行编程
- 使用 C++ 实现选项卡式 MDI
- 多态函数和智能指针
Visual Studio 2008,MFC
选项卡式多文档界面
标准 C++ 库中的新功能
多态函数对象
智能指针
class Application : public CWinAppEx
{
public:
virtual BOOL InitInstance();
};
BOOL Application::InitInstance()
{
SetRegistryKey(L"SampleCompany//SampleProduct");
m_pMainWnd = new MainWindow;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
class MainWindow : public CFrameWndEx
{
DECLARE_MESSAGE_MAP()
public:
MainWindow();
private:
int OnCreate(CREATESTRUCT* createStruct);
CMFCRibbonBar m_ribbon;
CMFCRibbonApplicationButton m_appButton;
};
BEGIN_MESSAGE_MAP(MainWindow, CFrameWndEx)
ON_WM_CREATE()
END_MESSAGE_MAP()
MainWindow::MainWindow()
{
Create(0, // class name
L"MFC Ribbon Sample Application");
}
int MainWindow::OnCreate(CREATESTRUCT* createStruct)
{
if (-1 == __super::OnCreate(createStruct))
{
return -1;
}
if (-1 == m_ribbon.Create(this))
{
return -1;
}
m_appButton.SetImage(IDB_APP_BUTTON);
m_ribbon.SetApplicationButton(&m_appButton,
CSize(45, 45));
CMFCRibbonMainPanel* appButtonMenu =
m_ribbon.AddMainCategory(L"Menu",
IDB_APP_BUTTON_MENU_SMALL,
IDB_APP_BUTTON_MENU_LARGE);
appButtonMenu->Add(new CMFCRibbonButton(ID_FILE_NEW,
L"&New",
0, // small image index
0)); // large image index
appButtonMenu->Add(new CMFCRibbonButton(ID_FILE_OPEN,
L"&Open...",
1, // small image index
1)); // large image index
appButtonMenu->AddToBottom(new CMFCRibbonMainPanelButton(ID_APP_EXIT,
L"E&xit",
15));
//small image index
CMFCRibbonCategory* category = m_ribbon.AddCategory(L"Home",
IDB_RIBBON_CAT_HOME_SMALL,
IDB_RIBBON_CAT_HOME_LARGE);
CMFCRibbonPanel* panel = category->AddPanel(L"Clipboard");
panel->Add(new CMFCRibbonButton(ID_EDIT_PASTE,
L"Paste",
0, // small image index
0)); // large image index
panel->Add(new CMFCRibbonButton(ID_EDIT_CUT, L"Cut", 1));
panel->Add(new CMFCRibbonButton(ID_EDIT_COPY, L"Copy", 2));
panel->Add(new CMFCRibbonButton(ID_EDIT_SELECT_ALL,
L"Select All", -1));
m_ribbon.AddCategory(L"Insert",
IDB_RIBBON_CAT_HOME_SMALL,
IDB_RIBBON_CAT_HOME_LARGE);
CMFCVisualManager::SetDefaultManager(
RUNTIME_CLASS(CMFCVisualManagerOffice
2007));
CMFCVisualManagerOffice2007::SetStyle
(CMFCVisualManagerOffice2007::Office
2007_LunaBlue);
return 0;
}
class Application : public CWinAppEx
{
DECLARE_MESSAGE_MAP()
public:
virtual BOOL InitInstance();
};
BEGIN_MESSAGE_MAP(Application, CWinAppEx)
ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew)
END_MESSAGE_MAP()
BOOL Application::InitInstance()
{
SetRegistryKey(L"SampleCompany//SampleProduct");
VERIFY(InitContextMenuManager());
AddDocTemplate(new CMultiDocTemplate(IDR_CHILDFRAME,
RUNTIME_CLASS(Document),
RUNTIME_CLASS(CMDIChildWndEx),
RUNTIME_CLASS(View)));
MainWindow* mainWindow = new MainWindow();
VERIFY(mainWindow->LoadFrame(IDR_MAINFRAME));
m_pMainWnd = mainWindow;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
class MainWindow : public CMDIFrameWndEx
{
DECLARE_DYNCREATE(MainWindow)
DECLARE_MESSAGE_MAP()
private:
int OnCreate(CREATESTRUCT* createStruct);
};
IMPLEMENT_DYNCREATE(MainWindow, CMDIFrameWndEx)
BEGIN_MESSAGE_MAP(MainWindow, CMDIFrameWndEx)
ON_WM_CREATE()
END_MESSAGE_MAP()
int MainWindow::OnCreate(CREATESTRUCT* createStruct)
{
if (-1 == __super::OnCreate(createStruct))
{
return -1;
}
CMDITabInfo tabInfo;
tabInfo.m_bAutoColor = true;
tabInfo.m_bDocumentMenu = true;
EnableMDITabbedGroups(true, tabInfo);
return 0;
}
int Add(int x, int y)
{
return x + y;
}
int result = Add(4, 5);
ASSERT(4 + 5 == result);
class AddFunctor
{
public:
int operator()(int x, int y) const
{
return x + y;
}
};
AddFunctor fo;
int result = fo(4, 5);
ASSERT(4 + 5 == result);
class Adder
{
public:
int Add(int x, int y) const
{
return x + y;
}
};
Adder adder;
int result = adder.Add(4, 5);
ASSERT(4 + 5 == result);
typedef int (*FunctionPointerType)(int x, int y);
FunctionPointerType fp = &Add;
int result = fp(4, 5);
ASSERT(4 + 5 == result);
Adder adder;
typedef int (Adder::*MemberFunctionPointerType)(int x, int y);
MemberFunctionPointerType mfp = &Adder::Add;
int result = (adder.*mfp)(4, 5);
ASSERT(4 + 5 == result);
function<int (int x, int y)> f = &Add;
int result = f(4, 5);
ASSERT(4 + 5 == result);
function<int (int x, int y)> f = AddFunctor();
function<int (int x, int y)> f = bind(&Adder::Add, &adder, _1, _2);
function<int (int x, int y)> f;
ASSERT(0 == f);
f = &Add;
ASSERT(0 != f);
f = bind(&Adder::Add, &adder, _1, _2);
function<int (int)> square = bind(multiplies<int>(), _1, _1);
int result = square(3);
ASSERT(9 == result);
function<int (int x, int y)> f = // initialize
int result = accumulate(numbers.begin(),
numbers.end(),
0, // initial value
f);
class Surface
{
//...
};
class Shape
{
public:
void Draw(Surface& surface) const;
};
Surface surface = // initialize
for_each(shapes.begin(),
shapes.end(),
bind(&Shape::Draw, _1, surface)); // wrong
for_each(shapes.begin(),
shapes.end(),
bind(&Shape::Draw, _1, ref(surface)));
auto_ptr<int> ap(new int(123));
ASSERT(0 != ap.get());
// transfer ownership from ap to ap2
auto_ptr<int> ap2(ap);
ASSERT(0 != ap2.get());
ASSERT(0 == ap.get());
shared_ptr<int> sp(new int(123));
ASSERT(0 != sp);
// increase reference count of shared object
shared_ptr<int> sp2(sp);
ASSERT(0 != sp2);
ASSERT(0 != sp);
shared_ptr<int> sp(new int(123));
ASSERT(sp.unique());
shared_ptr<int> sp2(sp);
ASSERT(!sp.unique());
ASSERT(!sp2.unique());
shared_ptr<int> sp;
ASSERT(0 == sp.use_count());
sp.reset(new int(123));
ASSERT(1 == sp.use_count());
shared_ptr<int> sp2(sp);
ASSERT(2 == sp.use_count());
ASSERT(2 == sp2.use_count());
Surface surface;
shared_ptr<Shape> sp(new Shape);
ASSERT(1 == sp.use_count());
weak_ptr<Shape> wp(sp);
ASSERT(1 == sp.use_count()); // still 1
// arbitrary application logic...
if (shared_ptr<Shape> sp2 = wp.lock())
{
sp2->Draw(surface);
}
- 使用 Visual C++ 2008 功能包加强 Windows 应用程序
- 使用 Visual C++ 2008 功能包加强 Windows 应用程序
- 使用 Visual C++ 2008 功能包加强 Windows 应用程序
- 使用 Visual C++ 2008 功能包加强 Windows 应用程序
- 使用 Visual C++ 2008 功能包加强 Windows 应用程序
- 使用 Visual C++ 2008 功能包加强 Windows 应用程序
- 使用 Visual C++ 2008 功能包加强 Windows 应用程序
- 使用 Visual C++ 2008 功能包加强 Windows 应用程序
- C++ Plus使用 Visual C++ 2008 功能包加强 Windows 应用程序
- C++ Plus 使用 Visual C++ 2008 功能包加强 Windows 应用程序
- 使用Visual C++2008功能包增强Windows应用程序
- 使用 Windows Phone 应用程序中的相机功能
- 使用Visual Studio 2010来部署Windows应用程序
- Visual Studio C/C++ windows编程代码提示功能
- Visual C# 应用程序开发 之 使用代码段 (C#)
- Windows Longhorn,图形功能大幅加强
- visual studio 2008开发windows mobile应用程序之环境篇
- 函数内部静态变量,( \\Visual C++\\ CLR \\ windows窗体应用程序 编写C++)
- 键盘回车事件导致页面刷新的问题
- 清除数据库中被注入的脚本
- Ext grid 中文排序
- 两本教子书
- Service 的生命周期
- 使用 Visual C++ 2008 功能包加强 Windows 应用程序
- SQL Server存储引擎(3) - 日志
- java request url中包含#
- Asp.net 之备份、恢复数据库
- 最简单的Java调用Orcale存储过程进行批量操作
- 换链接,群发和伪原创何时是尽头
- XFire中的安全验证and自定义WSDL文档的参数名
- PNG透明处理问题。。感激不尽--仅作备份
- 给web.py加点仿TG的功能