11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 6. Dialog Box<br />

The tool bar contains four buttons, whose IDs are ID_BUTTON_YELLOW, ID_BUTTON_GREEN,<br />

ID_BUTTON_RED and ID_BUTTON_BLUE, and they are painted with yellow, green, red and blue colors<br />

respectively. Four string resources are also added to the application, they will be used to implement tool<br />

tips and flybys:<br />

Resource ID<br />

String<br />

ID_BUTTON_YELLOW This is yellow button\nYellow Button<br />

ID_BUTTON_GREEN This is green button\nGreen Button<br />

ID_BUTTON_RED This is red button\nRed Button<br />

ID_BUTTON_BLUE This is blue button\nBlue Button<br />

The sub-string before character ‘\n’ will be used to implement flyby, and the sub-string after that will<br />

be used to implement tool tip. We will see that by letting the control and the string resource share a same<br />

ID, it is easier for us to implement both flybys and tool tips.<br />

New CToolBar and CStatusBar type variables are declared in class CDBDlg:<br />

……<br />

……<br />

……<br />

class CDBDlg : public CDialog<br />

{<br />

protected:<br />

};<br />

CStatusBar m_wndStatusBar;<br />

CToolBar m_wndToolBar;<br />

Status Bar<br />

A status bar is divided into several panes, each pane displays a different type of information. We can<br />

create as many panes as we like. When implementing a status bar, we must provide each pane with an ID.<br />

We can use these IDs to access each individual pane, and output text or graphic objects. Usually these IDs<br />

are stored in a global integer array. In the sample, the following array is declared for the status bar:<br />

static UINT indicators[] =<br />

{<br />

AFX_IDS_IDLEMESSAGE,<br />

IDS_MESSAGE<br />

};<br />

The status bar will have only two panes. Usually the first pane of the status bar is used to display<br />

flybys (In the idle state, “Ready” will be displayed in it). One property of status bar is that if we implement<br />

a string resource whose ID is the same with the ID of a pane contained in a status bar, the string will be<br />

automatically displayed in it when the application is idle. So here we can add two string resources whose<br />

IDs are AFX_IDS_IDLEMESSAGE and IDS_MESSAGE respectively. Since Developer Studio does not allow us to<br />

add a string resource starting with “AFX_”, we may copy this string resource from any standard SDI<br />

application (An SDI application has string resource AFX_IDS_IDLEMESSAGE if it is generated by Application<br />

Wizard).<br />

Adding Control Bars to Dialog Box<br />

In function CDBDlg::OnInitDialog(), the following code is added for creating both tool bar and status<br />

bar:<br />

……<br />

BOOL CDBDlg::OnInitDialog()<br />

{<br />

if<br />

(<br />

!m_wndToolBar.Create(this) ||<br />

!m_wndToolBar.LoadToolBar(IDD)<br />

160

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!