今天终于学会了在Status Bar 上写一个hello world.
刚大概看了下wxFrame的源代码,感觉还是那句话,源代码就是最好的文档。
嗯。。。
感觉 它没有我想的那么复杂。
整个wxFrame,似乎就是由Status Bar,Tool Bar,Menu构建而成的
对于每个组件(Status Bar,Tool Bar,Menu),都有相应的Create,OnCreate,Get,Set函数。
哈哈,我做的第一个全屏幕模式下的程序,哈哈,居然就这么简单?
frame->ShowFullScreen(true);
哈哈,开心!
原来wxWidget也不像我想的那么难啊
嗯,在windows下一行行的写wxWidget的界面,真是练基本功啊!非得一行行的去读它的源代码
在framecmn中找到这样一段代码
SetStatusBar(OnCreateStatusBar(number, style, id, name));
可以解释 OnCreateStatusBar和 CreateStatusBar的关系了,我之前还以为 OnCreateStatusBar是一个钩子呢。嗯,如果这样看来,应该算是其的实现吧。那么如果要加钩子,就应该重写的是CreateStatusBar函数。整个 CreateStatusBar除了return其实就两句话,
// the main status bar can only be created once (or else it should be
// deleted before calling CreateStatusBar() again)
wxCHECK_MSG( !m_frameStatusBar, (wxStatusBar *)NULL,
wxT("recreating status bar in wxFrame") );
SetStatusBar(OnCreateStatusBar(number, style, id, name));
return m_frameStatusBar;
估计在派生类中重写它的人很少能想到先调用wxCHECK_MSG检测是否有两个StatusBar.
那么这样的类库设计是不是不合理呢?难道每个使用它的人必须来看它的源代码吗?理论上来讲,封装就是让用户不用关心你如何去实现。嗯。。。其实,如果有足够的文档的话,如果给这些函数的语义都有足够的说明的话,这个问题也就不存在了。从某种意义上来讲,好的类库,更依赖于是否有好的文档,否则类库设计的再精妙也是枉然。
看来看源代码还是必要的,我得继续看。
但是问题是,这里面怎么没有Onfocus这样的函数?
wxStatusBar *wxFrameBase::OnCreateStatusBar(int number,
long style,
wxWindowID id,
const wxString& name)
{
wxStatusBar *statusBar = new wxStatusBar(this, id, style, name);
statusBar->SetFieldsCount(number);
return statusBar;
}
唉,终于体会到原来我看的是c++代码了,因为虽说我没有看见try-catch,但是我看见new了
于是,这就是一个新问题了
至今我依然对new心存警戒,看来防止资源泄露最简单的方式就是把函数写的尽量简单?
哈哈,黄金法则!
防止出错的最简单的方式,就是避免去做复杂的事。
天哪,注释这么多,文档写的这么规范,我不doxygen一次,我自己都觉得对不起自己!
哦,原来当代码分为好几个目录的时候必须手写Doxyfile啊
No way,generate nothing,because there is on file descript on the their heads.
手动改改doxyfile看看
嗯,不错,得到了所有我想要的。哈哈,还是中文啊,真是亲切
奇怪的是,还是有些类没有列出来,比如我正在看的wxFrameBase
嗯,注释写的的确是不错,不过看来doxygen对他是无能为力了,唉!可惜啊!
好吧!来做个简单的TextEditor
来学下如果用control
class TextFrame : public wxFrame{
public:
///Constructor,Creates a new TextFrame
TextFrame(const wxChar* title,int xpos,int ypos,int width,int height);
///The Destructor
~TextFrame();
private:
wxTextCtrl *m_pTextCtrl;
};
TextFrame::TextFrame(const wxChar* title,int xpos,int ypos,int width,int height):wxFrame((wxFrame*)NULL,-1,title,wxPoint(xpos,ypos),wxSize(width,height))
{
m_pTextCtrl= new wxTextCtrl(this,-1,wxString("Type some text here"),wxDefaultPosition,wxDefaultSize,wxTE_MULTILINE);
}
呵呵,ok
嗯,只需要new,不需要delete吗?
哈哈,那我应该在什么地方担心资源泄露呢?
嗯。。。如果必须要这样一行行代码的写控件的话,那么位置控制可是个大问题,难道就没有好点的可视化编辑器吗?Kdevelop中一定有,一会儿换linux下试试。cygwin下的Kdevelop还是不能用,郁闷!
作为这样的平台无关的库,我估计我以后开发的主要平台也是linux了,windows下会调试也就行了。
好了,去吃饭。