1.1 Preface
The source code of notepad ++ 1.0 has been viewed in the past two days. After reading the program for a long time, I finally figured out the relationship between the window of the program. Now I want to write the main points of its organization here, hoping to help you.
1.2 relationship between elements in a window
Notepad ++ mainly has the following window elements (see ).
Notepad_plus is the main window of the program. Others: toolbar, status bar, Primary and Secondary editing window, Primary and Secondary tab window, and dialog box window are subwindows of the main window.
_ Maindoctl and _ subdoctl are classes: the member _ pview of doctabview points to _ maineditview and _ subeditview respectively, which are two editing windows. This makes it easy to change the window size by re-layout the window. See the following section.
1.3 window layout
The window layout starts with the message processing program of notepad_plus:
Case wm_size: // The window size is changed by relayout {rect RC; getmainclientrect (RC); // exclude statusbar and toolbar area _ pmainwindow-> resizeTo (RC ); getstatusbarclientrect (RC); _ statusbar. resizeTo (RC); Return true ;}
After the size of the window is changed, the main window is reconfigured.
1. getmainclientrect (RC); // exclude statusbar and toolbar Area
Calculate the customer area (excluding the rectangular window area of the toolbar and status bar ).
2. _ pmainwindow-> resizeTo (RC );
Here, _ pmainwindow (when there is no split edit window, that is, only one edit window) is a pointer to _ maindoct4. Expand the function call as follows:
virtual void DocTabView::reSizeTo(RECT & rc){TabBar::reSizeTo(rc);rc.left += marge;rc.top += marge;rc.right -= 5;rc.bottom -= 10;_pView->reSizeTo(rc);};
The key here is the call of the function tabbar: resizeTo (RC. Expand it as follows:
void TabBar::reSizeTo(RECT & rc2Ajust){// Important to do that!// Otherwise, the window(s) it contains will take all the resouce of CPU// We don‘t need to resiz the contained windows if they are even invisible anyway!display(rc2Ajust.right > 10);Window::reSizeTo(rc2Ajust);TabCtrl_AdjustRect(_hSelf, FALSE, &rc2Ajust);}
Here, tabbar fills the window with the areas of the toolbar and status bar. Then call tabctrl_adjustrect (_ hself, false, & rc2ajust); return to the customer of the tab (out of the rectangle of the label)
After calling these layers, we will return:
virtual void DocTabView::reSizeTo(RECT & rc){TabBar::reSizeTo(rc);rc.left += marge;rc.top += marge;rc.right -= 5;rc.bottom -= 10;_pView->reSizeTo(rc);};
At this time, RC is the customer area of the tab, and _ pview is the pointer to the editing window. It calls the resizeTo function to adjust its window to a proper position,
3. getstatusbarclientrect (RC );
_ Statusbar. resizeTo (RC );
The last two sentences, as the name implies, are used to adjust the position of the status bar.
The preceding figure shows the window layout of notepad ++ 1.0.