ID Number: Q84068
1.00
WINDOWS
Summary:
The Flags property of a Common Dialog control can be read by examining
individual bit values of the Flag property and comparing them with
the predefined constant values in CONST2.TXT. This applies to the
following Visual Basic Common Dialogs:
- File Open Dialog
- File Save Dialog
- Color Dialog
- Choose Font Dialog
- Print Dialog
This information applies to the Common Dialog custom control supplied
with Microsoft Professional Toolkit for Microsoft Visual Basic
programming system version 1.0 for Windows.
More Information:
The Flags property can be set at design time or run time.
To set the value of the Flags property, assign it a value. This is
most commonly done using a predefined constant (found in CONST2.TXT).
For example, to set the PRINTTOFILE flag on the Print Dialog, use the
following code:
CMDialog1.Flags = PD_PRINTTOFILE
To set more that one flag, OR the two flags (the pipe [|] character
acts the same as the OR statement):
CMDialog1.Flags = PD_PRINTTOFILE | PD_SHOWHELP
The settings of the Flags property can also be changed at run time by
the user making various selections in the dialog box. When a selection
is made, or the status of a check box or option button is changed, the
Flags property reflects this change. You can then read the value of
the Flags property and determine if a specific flag has been set.
For example, in the above sample code, two flags are set in the Flags
property. The value of PD_PRINTTOFILE = &H00000020& and the value of
PD_SHOWHELP = &H00000800&.
The binary equivalent of the two is the following:
PD_PRINTTOFILE = 00000000000000000000000000100000
PD_SHOWHELP = 00000000000000000000100000000000
Thus the value:
Flags = 00000000000000000000100000100000
Note how each flag setting has its own bit setting within the Flags
property.
To determine if a specific flag is set, you only need to AND that flag
with the Flags property. If the result is 0, that flag is not set; if
the result is the same as the flag value, that flag is set.
For example:
Form1.Print (CMDialog1.Flags AND PD_PRINTTOFILE)
The output is decimal 32. Thus, broken down:
Flags = 00000000000000000000100000100000
AND
PD_PRINTTOFILE = 00000000000000000000000000100000
----------------------------------
Result = 00000000000000000000000000100000
Thus, the flag for PRINTTOFILE is one of the flags that are set in the
Flags property:
If (CMDialog1.Flags AND PD_PRINTTOFILE) Then
'Code for printing to file goes here.
Else
'Code for printing to printer goes here.
End If
Additional reference words: 1.00