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 function has six parameters, among them, nFlag, lprectParam and lpRectClient all have default<br />

values. When we called this function in the previous step, all the default values were used. This will pass<br />

CWnd::reposDefault to parameter nFlag, which will cause the default layout to be performed. If we pass<br />

CWnd::reposQuery to parameter nFlag, we can prepare a CRect type object and pass its address to<br />

lpRectParam to receive the new client area dimension (The client area is calculated with the consideration<br />

of control bars, their sizes are deducted from the original dimension of the client area). This operation will<br />

not let the layout be actually carried out. Based on the retrieved size, we can adjust the size of the dialog<br />

box and move the controls so that we can leave enough room to accommodate the tool bar and the status<br />

bar.<br />

The following is the updated implementation of function CDBDlg::OnInitDialog():<br />

……<br />

BOOL CDBDlg::OnInitDialog()<br />

{<br />

CRect rectOld;<br />

CRect rectNew;<br />

CRect rect;<br />

CPoint ptOffset;<br />

CWnd *pWndCtrl;<br />

GetClientRect(rectOld);<br />

if<br />

(<br />

)<br />

{<br />

}<br />

if<br />

(<br />

)<br />

{<br />

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

!m_wndToolBar.LoadToolBar(IDD)<br />

TRACE0("Failed to create toolbar\n");<br />

return -1;<br />

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

!m_wndStatusBar.SetIndicators<br />

(<br />

indicators,<br />

sizeof(indicators)/sizeof(UINT)<br />

)<br />

TRACE0("Failed to create status bar\n");<br />

return -1;<br />

}<br />

m_wndStatusBar.SetPaneInfo<br />

(<br />

0,<br />

m_wndStatusBar.GetItemID(0),<br />

SBPS_STRETCH,<br />

NULL<br />

);<br />

m_wndToolBar.SetBarStyle<br />

(<br />

m_wndToolBar.GetBarStyle() |<br />

CBRS_TOOLTIPS | CBRS_FLYBY<br />

);<br />

RepositionBars<br />

(<br />

AFX_IDW_CONTROLBAR_FIRST,<br />

AFX_IDW_CONTROLBAR_LAST,<br />

0,<br />

CWnd::reposQuery,<br />

rectNew<br />

);<br />

ptOffset.x=rectNew.left-rectOld.left;<br />

ptOffset.y=rectNew.top-rectOld.top;<br />

162

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

Saved successfully!

Ooh no, something went wrong!