MFCJCK

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

ChromiumFrame的入口函数在main.cpp中,打开main.cpp.
中包含3个类和_tWinMain函数。
_tWinMain就是我们要找的入口函数。我做了部分注释:

 1 int APIENTRY _tWinMain(HINSTANCE hInstance,
 2                        HINSTANCE hPrevInstance,
 3                        LPTSTR    lpCmdLine,
 4                        int       nCmdShow)
 5 {
 6     // 1. 支持OLE,退出管理机制,GDIPlus 初始化,本地资源管理(new)
 7     HRESULT hRes = OleInitialize(NULL);
 8     base::AtExitManager exit_manager;
 9     gfx::GdiplusInitializer gdiplus_initializer;
10     gdiplus_initializer.Init();
11     ResourceBundle::InitSharedInstance(base::FilePath());
12     ResourceBundle::GetSharedInstance().SetIdConveter(new AppIdConveter());
13     
14     // 2. 创建窗口(包含WNDCLASS注册)
15     view::AcceleratorHandler handler;
16     MessageLoop loop(MessageLoop::TYPE_UI);
17     MainWindowDelegate delegate;
18     view::Window::CreateNativeWindow(NULL, gfx::Rect(), &delegate);
19     delegate.window()->SetWindowBounds(gfx::Rect(0, 0, 500, 500), NULL);
20     delegate.window()->Show();
21 
22     // 3. 启动消息循环 
23     MessageLoopForUI::current()->Run(&handler);
24 
25     // 4. 退出处理(new)
26     ResourceBundle::CleanupSharedInstance();
27     gdiplus_initializer.UnInit();
28     OleUninitialize();
29 }

参考注释,发现这里只比1.1中提到win32典型程序的WinMain多了 支持OLE,退出管理机制,GDIPlus 初始化,本地资源管理。

1.1文中提到的1. WNDCLASS注册   2. 窗口的创建   3. 启动消息循环也被包装后,在这里都有调用。骨架未变,只是包装上了华丽的Message framework。

注册WNDCLASS和创建窗口在这里:

1 view::Window::CreateNativeWindow(NULL, gfx::Rect(), &delegate);

消息循环在这里:

1 MessageLoopForUI::current()->Run(&handler);

3个类分别是MainView / MainWindowDelegate / AppIdConveter

1. 最重要的就是MainWindowDelegate类,MainWindowDelegate继承自WindowDelegate,WindowDelegate是窗口类一个委托类,通过在MainWindowDelegate重载虚函数,从而达到控制窗口的行为。需要提一下的是,google这里是完全的面向对象,而非MFC中使用set方式来设置窗口的行为。这样的方式在chromium中比比皆是。不要被弄的晕头转向才好。
2. AppIdConveter类,系统资源ID与chromium内部使用的ID转换辅助类。

3. MainView控制窗口中view的行为,这里只是告知了view的大小。在MainWindowDelegate中告知窗口的包含view就是MainView,窗口的大小也就跟随了包含view的大小。(其中关系并非这么简单,但暂时可以这么理解)

 

接下来就由_tWinMain出发了解view framework.

posted on 2015-06-08 12:01  MFCJCK  阅读(1252)  评论(0编辑  收藏  举报