Private Declare Function apiChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As ChooseColorType) As Long
Private Enum CommDialogFlags
'ChooseColor flags ------------------*
cc_RGBInit = &H1& 'Causes the dialog box to use the color specified in the rgbResult member as the initial color selection.
cc_FullOpen = &H2& 'Causes the dialog box to display the additional controls that allow the user to create custom colors. If this flag is not set, the user must click the Define Custom Color button to display the custom color controls.
cc_PreventFullOpen = &H4& 'Disables the Define Custom Colors button.
cc_ShowHelp = &H8& 'Causes the dialog box to display the Help button. The hwndOwner member must specify the window to receive the HELPMSGSTRING registered messages that the dialog box sends when the user clicks the Help button.
cc_EnableHook = &H10& 'Enables the hook procedure specified in the lpfnHook member of this structure. This flag is used only to initialize the dialog box.
cc_EnableTemplate = &H20& 'Indicates that the hInstance and lpTemplateName members specify a dialog box template to use in place of the default template. This flag is used only to initialize the dialog box.
cc_EnableTemplateHandle = &H40& 'Indicates that the hInstance member identifies a data block that contains a preloaded dialog box template. The system ignores the lpTemplateName member if this flag is specified. This flag is used only to initialize the dialog box.
cc_SolidColor = &H80& 'Causes the dialog box to display only solid colors in the set of basic colors.
cc_AnyColor = &H100& 'Causes the dialog box to display all available colors in the set of basic colors.
'ChooseFont flags -------------------*
cf_ScreenFonts = &H1& 'Causes the dialog box to list only the screen fonts supported by the system.
cf_PrinterFonts = &H2& 'Causes the dialog box to list only the fonts supported by the printer associated with the device context (or information context) identified by the hDC member.
cf_Both = cf_ScreenFonts Or cf_PrinterFonts
cf_ShowHelp = &H4& 'Causes the dialog box to display the Help button. The hwndOwner member must specify the window to receive the HELPMSGSTRING registered messages that the dialog box sends when the user clicks the Help button.
cf_EnableHook = &H8& 'Enables the hook procedure specified in the lpfnHook member of this structure.
cf_EnableTemplate = &H10& 'Indicates that the hInstance and lpTemplateName members specify a dialog box template to use in place of the default template.
cf_EnableTemplateHandle = &H20& 'Indicates that the hInstance member identifies a data block that contains a preloaded dialog box template. The system ignores the lpTemplateName member if this flag is specified.
cf_InitToLOGFONTStruct = &H40& 'Specifies that ChooseFont should use the LOGFONT structure pointed to by the lpLogFont member to initialize the dialog box controls.
cf_UseStyle = &H80& 'Specifies that the lpszStyle member points to a buffer that contains style data that ChooseFont should use to initialize the Font Style combo box. When the user closes the dialog box, ChooseFont copies style data for the user's selection to this buffer.
cf_Effects = &H100& 'Causes the dialog box to display the controls that allow the user to specify strikeout, underline, and text color options. If this flag is set, you can use the rgbColors member to specify the initial text color. You can use the lfStrikeOut and lfUnderline members of the LOGFONT structure pointed to by lpLogFont to specify the initial settings of the strikeout and underline check boxes. ChooseFont can use these members to return the user's selections.
cf_Apply = &H200& 'Causes the dialog box to display the Apply button. You should provide a hook procedure to process WM_COMMAND messages for the Apply button. The hook procedure can send the WM_CHOOSEFONT_GETLOGFONT message to the dialog box to retrieve the address of the LOGFONT structure that contains the current selections for the font.
cf_ANSIOnly = &H400& 'This flag is obsolete. To limit font selections to all scripts except those that use the OEM or Symbol character sets, use CF_SCRIPTSONLY. To get the Windows 3.1 CF_ANSIONLY behavior, use CF_SELECTSCRIPT and specify ANSI_CHARSET in the lfCharSet member of the LOGFONT structure pointed to by lpLogFont.
cf_ScriptsOnly = cf_ANSIOnly 'Specifies that ChooseFont should allow selection of fonts for all non-OEM and Symbol character sets, as well as the ANSI character set. This supersedes the CF_ANSIONLY value.
cf_NoVectorFonts = &H800& 'Specifies that ChooseFont should not allow vector font selections.
cf_NoOEMFonts = cf_NoVectorFonts 'Same as the CF_NOVECTORFONTS flag.
cf_NoSimulations = &H1000& 'Specifies that ChooseFont should not allow graphics device interface (GDI) font simulations.
cf_LimitSize = &H2000& 'Specifies that ChooseFont should select only font sizes within the range specified by the nSizeMin and nSizeMax members.
cf_FixedPitchOnly = &H4000& 'Specifies that ChooseFont should select only fixed-pitch fonts.
cf_WYSIWYG = &H8000& 'Specifies that ChooseFont should allow only the selection of fonts available on both the printer and the display. If this flag is specified, the CF_BOTH and CF_SCALABLEONLY flags should also be specified.
cf_ForceFontExist = &H10000 'Specifies that ChooseFont should indicate an error condition if the user attempts to select a font or style that does not exist.
cf_ScalableOnly = &H20000 'Specifies that ChooseFont should allow only the selection of scalable fonts. (Scalable fonts include vector fonts, scalable printer fonts, TrueType fonts, and fonts scaled by other technologies.)
cf_TTOnly = &H40000 'Specifies that ChooseFont should only enumerate and allow the selection of TrueType fonts.
cf_NoFaceSel = &H80000 'When using a LOGFONT structure to initialize the dialog box controls, use this flag to selectively prevent the dialog box from displaying an initial selection for the font name combo box. This is useful when there is no single font name that applies to the text selection.
cf_NoStyleSel = &H100000 'When using a LOGFONT structure to initialize the dialog box controls, use this flag to selectively prevent the dialog box from displaying an initial selection for the font style combo box. This is useful when there is no single font style that applies to the text selection.
cf_NoSizeSel = &H200000 'When using a LOGFONT structure to initialize the dialog box controls, use this flag to selectively prevent the dialog box from displaying an initial selection for the font size combo box. This is useful when there is no single font size that applies to the text selection.
cf_SelectScript = &H400000 'When specified on input, only fonts with the character set identified in the lfCharSet member of the LOGFONT structure are displayed. The user will not be allowed to change the character set specified in the Scripts combo box.
cf_NoScriptSel = &H800000 'Disables the Script combo box. When this flag is set, the lfCharSet member of the LOGFONT structure is set to DEFAULT_CHARSET when ChooseFont returns. This flag is used only to initialize the dialog box.
cf_NoVertFonts = &H1000000 'Causes the Font dialog box to list only horizontally oriented fonts.
'OpenFileName flags -----------------*
co_ReadOnly = &H1& 'Causes the Read Only check box to be checked initially when the dialog box is created. This flag indicates the state of the Read Only check box when the dialog box is closed.
co_OverwritePrompt = &H2& 'Causes the Save As dialog box to generate a message box if the selected file already exists. The user must confirm whether to overwrite the file.
co_HideReadOnly = &H4& 'Hides the Read Only check box.
co_NoChangeDir = &H8& 'Restores the current directory to its original value if the user changed the directory while searching for files.
co_ShowHelp = &H10& 'Causes the dialog box to display the Help button. The hwndOwner member must specify the window to receive the HELPMSGSTRING registered messages that the dialog box sends when the user clicks the Help button.
co_EnableHook = &H20& 'Enables the hook function specified in the lpfnHook member.
co_EnableTemplate = &H40& 'Indicates that the lpTemplateName member points to the name of a dialog template resource in the module identified by the hInstance member.
co_EnableTemplateHandle = &H80& 'Indicates that the hInstance member identifies a data block that contains a preloaded dialog box template. The system ignores the lpTemplateName if this flag is specified.
co_NoValidate = &H100& 'Specifies that the common dialog boxes allow invalid characters in the returned file name. Typically, the calling application uses a hook procedure that checks the file name by using the FILEOKSTRING message. If the text box in the edit control is empty or contains nothing but spaces, the lists of files and directories are updated. If the text box in the edit control contains anything else, nFileOffset and nFileExtension are set to values generated by parsing the text. No default extension is added to the text, nor is text copied to the buffer specified by lpstrFileTitle.
co_AllowMultiSelect = &H200& 'Specifies that the File Name list box allows multiple selections. If you also set the co_EXPLORER flag, the dialog box uses the Explorer-style user interface; otherwise, it uses the old-style user interface.
co_ExtensionDifferent = &H400& 'Specifies that the user typed a file name extension that differs from the extension specified by lpstrDefExt. The function does not use this flag if lpstrDefExt is NULL.
co_PathMustExist = &H800& 'Specifies that the user can type only valid paths and filenames. If this flag is used and the user types an invalid path and file name in the File Name entry field, the dialog box function displays a warning in a message box.
co_FileMustExist = &H1000& 'Specifies that the user can type only names of existing files in the File Name entry field. If this flag is specified and the user enters an invalid name, the dialog box procedure displays a warning in a message box. If this flag is specified, the co_PATHMUSTEXIST flag is also used.
co_CreatePrompt = &H2000& 'If the user specifies a file that does not exist, this flag causes the dialog box to prompt the user for permission to create the file. If the user chooses to create the file, the dialog box closes and the function returns the specified name; otherwise, the dialog box remains open. If you use this flag with the co_ALLOWMULTISELECT flag, the dialog box allows the user to specify only one nonexistent file.
co_ShareAware = &H4000& 'Specifies that if a call to the OpenFile function fails because of a network sharing violation, the error is ignored and the dialog box returns the selected file name.
co_NoReadOnlyReturn = &H8000& 'Specifies that the returned file does not have the Read Only check box checked and is not in a write-protected directory.
co_NoTestFileCreate = &H10000 'Specifies that the file is not created before the dialog box is closed. This flag should be specified if the application saves the file on a create-nonmodify network share. When an application specifies this flag, the library does not check for write protection, a full disk, an open drive door, or network protection. Applications using this flag must perform file operations carefully, because a file cannot be reopened once it is closed.
co_NoNetworkButton = &H20000 'Hides and disables the Network button.
co_NoLongNames = &H40000 'For old-style dialog boxes, this flag causes the dialog box to use short filenames (8.3 format).
co_Explorer = &H80000 'Indicates that any customizations made to the Open or Save As dialog box use the new Explorer-style customization methods. For more information, see Explorer-Style Hook Procedures and Explorer-Style Custom Templates.
co_NodeReferenceLinks = &H100000 'Directs the dialog box to return the path and file name of the selected shortcut (.LNK) file. If this value is not given, the dialog box returns the path and file name of the file referenced by the shortcut.
co_LongNames = &H200000 'For old-style dialog boxes, this flag causes the dialog box to use long filenames. If this flag is not specified, or if the co_ALLOWMULTISELECT flag is also set, old-style dialog boxes use short filenames (8.3 format) for filenames with spaces.
co_EnableIncludeNotify = &H400000 'Windows 2000: Causes the dialog box to send CDN_INCLUDEITEM notification messages to your OFNHookProc hook procedure when the user opens a folder. The dialog box sends a notification for each item in the newly opened folder. These messages enable you to control which items the dialog box displays in the folder's item list.
co_EnableSizing = &H800000 'Windows 2000, Windows 98: Enables the Explorer-style dialog box to be resized using either the mouse or the keyboard. By default, the Explorer-style Open and Save As dialog boxes allow the dialog box to be resized regardless of whether this flag is set. This flag is necessary only if you provide a hook procedure or custom template. The old-style dialog box does not permit resizing.
co_UseMonikers 'Windows 2000: Indicates that you want to identify items by monikers rather than file system paths. If this flag is set, the rgpMonikers member must point to an array of one or more IMoniker pointers that receive the monikers of the item or items selected by the user. In this case, the lpstrFile and lpstrFileTitle buffers are not used. If this flag is not set, rgpMonikers is not used, and lpstrFile and lpstrFileTitle return information about the user's selection.
co_DontAddToRecent 'Windows 2000: Prevents the system from adding a link to the selected file in the file system directory that contains the user's most recently used documents. To retrieve the location of this directory, call the SHGetSpecialFolderLocation function with the CSIDL_RECENT flag.
'PrintDlg flags ---------------------*
cp_AllPages = &H0& 'The default flag that indicates that the All radio button is initially selected. This flag is used as a placeholder to indicate that the PD_PAGENUMS and PD_SELECTION flags are not specified.
cp_Selection = &H1& 'If this flag is set, the Selection radio button is selected. If neither PD_PAGENUMS nor PD_SELECTION is set, the All radio button is selected.
cp_PageNums = &H2& 'If this flag is set, the Pages radio button is selected. If this flag is set when the PrintDlg function returns, the nFromPage and nFromPage members indicate the starting and ending pages specified by the user.
cp_NoSelection = &H4& 'Disables the Selection radio button.
cp_NoPageNums = &H8& 'Disables the Pages radio button and the associated edit controls.
cp_Collate = &H10& 'If this flag is set, the Collate check box is checked. If this flag is set when the PrintDlg function returns, the application must simulate collation of multiple copies. For more information, see the description of the cp_USEDEVMODECOPIESANDCOLLATE flag.
cp_PrintToFile = &H20& 'If this flag is set, the Print to File check box is selected. If this flag is set when the PrintDlg function returns, the offset indicated by the wOutputOffset member of the DEVNAMES structure contains the string "FILE:". When you call the StartDoc function to start the printing operation, specify this "FILE:" string in the lpszOutput member of the DOCINFO structure. Specifying this string causes the print subsystem to query the user for the name of the output file.
cp_PrintSetup = &H40& 'Causes the system to display the Print Setup dialog box rather than the Print dialog box.
cp_NoWarning = &H80& 'Prevents the warning message from being displayed when there is no default printer.
cp_ReturnDC = &H100& 'Causes PrintDlg to return a device context matching the selections the user made in the dialog box. The device context is returned in hDC.
cp_ReturnIC = &H200& 'Similar to the PD_RETURNDC flag, except this flag returns an information context rather than a device context. If neither PD_RETURNDC nor PD_RETURNIC is specified, hDC is undefined on output.
cp_ReturnDefault = &H400& 'If this flag is set, the PrintDlg function does not display the dialog box. Instead, it sets the hDevNames and hDevMode members to handles to DEVMODE and DEVNAMES structures that are initialized for the system default printer. Both hDevNames and hDevMode must be NULL, or PrintDlg returns an error. If the system default printer is supported by an old printer driver (earlier than Windows version 3.0), only hDevNames is returned; hDevMode is NULL.
cp_ShowHelp = &H800& 'Causes the dialog box to display the Help button. The hwndOwner member must specify the window to receive the HELPMSGSTRING registered messages that the dialog box sends when the user clicks the Help button.
cp_EnablePrintHook = &H1000& 'Enables the hook procedure specified in the lpfnPrintHook member. This enables the hook procedure for the Print dialog box.
cp_EnableSetupHook = &H2000& 'Enables the hook procedure specified in the lpfnSetupHook member. This enables the hook procedure for the Print Setup dialog box.
cp_EnablePrintTemplate = &H4000& 'Indicates that the hInstance and lpPrintTemplateName members specify a replacement for the default Print dialog box template.
cp_EnableSetupTemplate = &H8000& 'Indicates that the hInstance and lpSetupTemplateName members specify a replacement for the default Print Setup dialog box template.
cp_EnablePrintTemplateHandle = &H10000 'Indicates that the hPrintTemplate member identifies a data block that contains a preloaded dialog box template. This template replaces the default template for the Print dialog box. The system ignores the lpPrintTemplateName member if this flag is specified.
cp_EnableSetupTemplateHandle = &H20000 'Indicates that the hSetupTemplate member identifies a data block that contains a preloaded dialog box template. This template replaces the default template for the Print Setup dialog box. The system ignores the lpSetupTemplateName member if this flag is specified.
cp_UseDevModeCopies = &H40000 'Same as cp_USEDEVMODECOPIESANDCOLLATE.
cp_UseDevModeCopiesAndCollate = &H40000 'This flag indicates whether your application supports multiple copies and collation. Set this flag on input to indicate that your application does not support multiple copies and collation. In this case, the nCopies member of the PRINTDLG structure always returns 1, and PD_COLLATE is never set in the Flags member.
cp_DisablePrintToFile = &H80000 'Disables the Print to File check box.
cp_HidePrintToFile = &H100000 'Hides the Print to File check box.
cp_NoNetworkButton = &H200000 'Hides and disables the Network button.
End Enum
Private Type ChooseColorType
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As String
flags As CommDialogFlags
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Sub ShowColor()
Dim ret As Long, clr As ChooseColorType, CC() As Byte
With clr
.hwndOwner = 0
.hInstance = App.hInstance
.rgbResult = Color
.flags = cc_RGBInit
End With
clr.lpCustColors = StrConv(CC, vbUnicode)
clr.lStructSize = Len(clr)
ret = apiChooseColor(clr)
If ret <> 0 Then
Color = clr.rgbResult
CC = StrConv(clr.lpCustColors, vbFromUnicode)
Else
End If
End Sub
skiperski писал(а):Подскажите как в программе реализовать выбор цвета. Стандартый диалог, гад, всегда по умолчанию выбирает чёрный цвет, даже при прямом указании Color = <color>. Как его забороть? Или может другой какой компонент есть?
With CommonDialog1
.Color = vbGreen
.Flags = cdlCCRGBInit
.ShowColor
End With
.Flags = cdlCCRGBInit
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 11