33. How to get a pointer to a dialog control
There are two ways. First, call CWnd:: getdlgitem, get a CWND * pointer call member function. The following example calls getdlgitem, pass the return value to a cspinbuttonctrl * to call CSPinButtonCtrl:: setPOS function:
Bool Csampledialog:: OnInitdialog ()
{
CDIALOG:: OnInitDialog ();
// Get Pointer to Spin Button.
CSPinButtonCtrl * pspin - (cspinbuttonctrl *) getdlgitem (IDC_SPIN);
Assert_ Valid (PSPIN);
// set spin button's default position.
PSPIN-> SetPOS (10);
Return True;
}
Second, you can use ClassWizard to link controls and member variables. Simply select the MEMBER VARIABLES tab in ClassWizard and select the Add Variable ... button. If you press the CTRL key and double-click the control in the dialog resource editor and you can go to the Add Member Variable conversation.
34. How to prohibit and enable controls
The control is also a window, so you can call CWnd:: EnableWindow enable and disable controls.
// disable button controls.
M_Wndok.enableWindow (FALSE);
m_wndapply.enableWindow (false);
35, how to change the font of the control
Since the control is also a window, the user can call CWnd:: setFont Specifies the new font. This function uses a CFont pointer to ensure that the font object cannot be revoked before the control is canceled. The following example will change the font of the lower pressure button to 8 points Arial font:
// Declare Font Object In Class Declaration (.h file).
Private:
CFont M_Font;
// SET FONT IN Class Implementation (.cpp file). Note M_WndButton IS A
// Member Variable Added by classwizard.ddx routines hook the member
// Variable to a dialog button.
Bool Csampledialog:: OnInitdialog ()
{
...
// Create An 8-Point Arial Font
M_Font. CreateFont (MULDIV (8, -PDC-> GetDeviceCaps (Logpixelsy), 72).
0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSER, OUT_STROKE_PRECIS,
CLIP_STROKE _PRECIS, Draft _Quality
Variable_pitch | ff_swiss, _t ("arial));
// set font for push button.
M_WndButton. setfont (& m _font);
...
}
36. How to use the OLE_COLOR data type in the OLE control
For functions such as Colecontrol:: GetFortColor and ColeControl:: GetBackColor returns the color of the OLE _COLOR data type, while the GDI object is used by the ColorRef data type, calling ColeControl:: TranslateColor can easily change the OLE_COLOR type to ColorRef Type . The following example creates a brush of a current background color: Void CsampleControl:: OnDraw (CDC * PDC
Const CRECT & RCBOUNDS, Const CRECT & RCINVALID
{
// Create a brush of the cuttent background color.
CBRUSH brushback (TranslateColor (GetBackColor ()));
// Paint The Background Using The Current Background Color.
PDC-> FillRect (rcbounds, & brushback);
// Other Drawign Commands
...
}
37. How to display a list of files without using a universal file open dialog
Call CWnd:: DLGDIRLIST or CWND:: DLGDIRLISTCOMBOBOX, Windows will automatically populate the available drive names or files in the list box or combo box, the next example populates the files in the Windows directory in the combo box:
Bool csampledig:: oninitdialog ()
{
CDIALOG:: OnInitDialog ()
Tchar Szpath [MAX_PATH] = {"C: // Windows"};
Int nreslt = dlgdirlistcomboBox (Szpath, IDC_COMBO, IDC_CURIDIR,
DDL_ReadWrite | DDL_READOONLY | DDL_HIDDEN |
DDL_SYSTEM | DDL_ARCHIVE);
Return True;
}
38, why rotating button controls look forward
Need to call CSPINCTRL:: SetRan Set the range of rotation button controls, the default upper limit of the rotation button control is 0, the default lower limit is 100, which means that the value of rotation according to the control is generated from 0 to zer. The following example sets the range of rotation button controls to 0 to 100:
Bool caboutdlg:: OnInitDialog ()
{
CDIALOG:: OnInitDialog ()
// set the lower and upper limited of the spin button
M_Wndspin. SetRange (0, 100);
Return True;
}
The COPISE rotation button control in the Visual C 4.0 PRINT dialog is also the same problem: the number of copies when the UP button is pressed, and the number of copies when the DOWN button is pressed.
39 Why is the rotation button control not automatically updates the following editing control?
If the autu buddy feature of the rotating button is used, the Buddy window must be guaranteed to the rotation button control in the marking order of the conversation. Select Tab ORDER menu items from the Layout menu (or press CRTL D) to set the tag order of the dialog.
40. How to display the lower pressure button with a bitmap
The Windows 95 button has several new creation styles, especially BS_bitmap, and BS_ICON. To have a bitmap button, create a button and call CButton:: setBitmap or CButton:: Seticon To specify the BS_bitmap or BS_ICON style. First, set the icon properties of the button.
Then, call CButton when the dialog is initialized:: Seticon. Note: The next example uses icons to replace the bitmap. Be careful when using a bitmap, because you don't know all colors - not everyone uses light gray.
Bool csampledlg:: oninitdialog ()
{
CDIALOG:: OnInitDialog ();
// set the images for the push button.
m_wndbutton1.seticon (AFXGetApp () -> Loadicon (IDi _ iption1))
m_wndbutton2.seticon (AFXGetApp () -> Loadicon (IDi _ iption2))
m_wndbutton3.seticon (AFXGetApp () -> Loadicon (IDi _ iption3))
Return True;
}