How to use dialog boxes? Translator: Xu Jing Zhou (original: vgirish)
Q: How to join the toolbar in the dialog box to add the following code in OnInitDialog:
Bool cyordlg :: oninitdialog ()
{
CDIALOG :: OnInitdialog ();
// Create the Toolbar. To understand the meaning of the styles buy, you
// CAN Take a look at the msdn for the create function of the ctoolbar class.
Toolbar.create (this, ws_child | ws_visible | cbrs_top | CBRS_Tooltips | CBRS_FLYBY | CBRS_BORDER_BOTTOM);
// i Have Assumed That You Have Named Your Toolbar's Resource AS iDR_Toolbar1.
// if you have given it a different name, change the line bellow to accessate
// That by changing the parameter for the loadtoolbar function.
Toolbar.LoadToolbar (IDR_Toolbar1);
CRECT RCCLIENTSTART;
CRECT RCCLIENTNOW;
GetClientRect (rcclientstart);
// to reposition and resize the control bar
Repositionbars (AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, REPOSQUERY, RCCLIENTNOW);
Cpoint ptoffset (RcClientst, RcClientStart.Left, RcClientnow.top-rcclientstart.top);
CRECT RCCHILD;
CWND * PWNDCHILD = GetWindow (GW_CHILD);
While (PWNDCHILD)
{
PWNDCHILD-> GetWindowRect (rcchild);
ScreenToClient (RCCHILD);
RcChild.offsetRect (PTOFFSET);
PWNDCHILD-> MoveWindow (RcChild, False);
PWNDCHILD = PWNDCHILD-> getNextWindow ();
}
CRECT RCWINDOW;
GetWindowRect (rcwindow);
RcWindow.right = rcclientstart.width () - rcclientnow.width ();
RcWindow.bottom = rcclientstart.height () - rcclientnow.Height ();
MoveWindow (RCWindow, False);
// and position the control bars
Repositionbars (AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
Return True; // Return True UnsS you set the focus to a control
}
Q: How to change the shape of the dialog? Available in some of the following: CreatePolygonRGN CreateRectrGN CreateroundRectRGN et al. CRGN M_RGN; // Put this in your dialog's header file. I. A Member Variable
// this gets the size of the dialog: this basce of code is to be placed in the
// OnInitdialog Function of Your Dialog.
CRECT RCDIALOG
GetClientRect (rcdialog);
// the folowing code creates the area and assigns it to your dialog. Item / ASSIGNS IT TO YOROG
M_Rgn.createellLipTicRGN (0, 0, RcDialog.width (), RCDialogHeight ());
SetwindowRgn (GetSafehWnd (), (hrgn) m_RGN, TRUE);
Q: How do I achieve non-customer movement? Use the following two methods:
// Handler for WM_LButtondown Message
Void CyourDialog :: ONLBUTTONDOWN (uint nflags, cpoint point)
{
CDIALOG :: ONLBUTTONDOWN (NFLAGS, POINT);
Postmessage (WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM (Point.x, Point.y);
}
// Handler for WM_NCHITTEST MESSAGE
Long cyoRDialog :: Onnchnittest (Uint Uparam, Long Lparam)
{
INT xpos = loword (lparam);
Int Ypos = HiWord (LPARAM);
Uint nhittest = cdialog :: ONNCHITTEST (CSIZE (XPOS, YPOS));
Return (nhittest == htclient)? htcaption: nhittest;
}
Q: How to make the dialog initially minimize the state? Add the following code in OnInitDialog:
SendMessage (WM_SYSCOMMAND, SC_MAXIMIZE, NULL);
Q: How to limit the dialog size range? Add the following code in WM_SIZING:
Void CyourDialog :: Onsizing (uint fwside, lprect prect)
{
IF (prect-> right - prect-> left <= 200)
Prect-> Right = prect-> left 200;
IF (prect-> bottom - prect-> TOP <= 200)
prect-> bottom = prect-> top 200;
CDIALOG :: Onsizing (fwside, prect);
}
Q: How do I join the status bar in the dialog? Define the cstatusbar variable:
CSTATUSBAR M_STATUSBAR;
Define status bar specified:
Static uint based_code indeicators [] =
{
ID_indicator_caps,
ID_indicator_num
}
Add the following code in OnInitDialog: m_statusbar.createex (this, sbt_tooltips, ws_child | ws_visible | cbrs_bottom, afx_idw_status_bar);
// set the indeicators namely caps and nums loc status
m_statusbar.setindicators (Indicators, Sizeof (Indicators) / SizeOf (UINT));
CRECT RECT;
GetClientRect (& RECT);
M_StatusBar.SetPaneInfo (0, ID_indicator_caps, sbps_normal, reference.width () / 2);
m_statusbar.SetPaneInfo (1, ID_indicator_num, sbps_stretch, rect.width () / 2);
Repositionbars (AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, ID_IDICATOR_NUM);
m_statusbar.getStatusbarCtrl (). setbkcolor (RGB (180, 180, 180));