آموزش توابع API ویندوز گروه: Common Dialogs
منبع: انجمن تخصصی برنامه نویسان ایران
ChooseColor, ChooseFont, CommDlgExtendedError, GetOpenFileName, GetSaveFileName,
'This project needs 6 command buttons
Option Explicit
Const FW_NORMAL = 400
Const DEFAULT_CHARSET = 1
Const OUT_DEFAULT_PRECIS = 0
Const CLIP_DEFAULT_PRECIS = 0
Const DEFAULT_QUALITY = 0
Const DEFAULT_PITCH = 0
Const FF_ROMAN = 16
Const CF_PRINTERFONTS = &H2
Const CF_SCREENFONTS = &H1
Const CF_BOTH = (CF_SCREENFONTS Or CF_PRINTERFONTS)
Const CF_EFFECTS = &H100&
Const CF_FORCEFONTEXIST = &H10000
Const CF_INITTOLOGFONTSTRUCT = &H40&
Const CF_LIMITSIZE = &H2000&
Const REGULAR_FONTTYPE = &H400
Const LF_FACESIZE = 32
Const CCHDEVICENAME = 32
Const CCHFORMNAME = 32
Const GMEM_MOVEABLE = &H2
Const GMEM_ZEROINIT = &H40
Const DM_DUPLEX = &H1000&
Const DM_ORIENTATION = &H1&
Const PD_PRINTSETUP = &H40
Const PD_DISABLEPRINTTOFILE = &H80000
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Type PAGESETUPDLG
lStructSize As Long
hwndOwner As Long
hDevMode As Long
hDevNames As Long
flags As Long
ptPaperSize As POINTAPI
rtMinMargin As RECT
rtMargin As RECT
hInstance As Long
lCustData As Long
lpfnPageSetupHook As Long
lpfnPagePaintHook As Long
lpPageSetupTemplateName As String
hPageSetupTemplate As Long
End Type
Private Type CHOOSECOLOR
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As String
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Type LOGFONT
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName As String * 31
End Type
Private Type CHOOSEFONT
lStructSize As Long
hwndOwner As Long ' caller's window handle
hDC As Long ' printer DC/IC or NULL
lpLogFont As Long ' ptr. to a LOGFONT struct
iPointSize As Long ' 10 * size in points of selected font
flags As Long ' enum. type flags
rgbColors As Long ' returned text color
lCustData As Long ' data passed to hook fn.
lpfnHook As Long ' ptr. to hook function
lpTemplateName As String ' custom template name
hInstance As Long ' instance handle of.EXE that
' contains cust. dlg. template
lpszStyle As String ' return the style field here
' must be LF_FACESIZE or bigger
nFontType As Integer ' same value reported to the EnumFonts
' call back with the extra FONTTYPE_
' bits added
MISSING_ALIGNMENT As Integer
nSizeMin As Long ' minimum pt size allowed &
nSizeMax As Long ' max pt size allowed if
' CF_LIMITSIZE is used
End Type
Private Type PRINTDLG_TYPE
lStructSize As Long
hwndOwner As Long
hDevMode As Long
hDevNames As Long
hDC As Long
flags As Long
nFromPage As Integer
nToPage As Integer
nMinPage As Integer
nMaxPage As Integer
nCopies As Integer
hInstance As Long
lCustData As Long
lpfnPrintHook As Long
lpfnSetupHook As Long
lpPrintTemplateName As String
lpSetupTemplateName As String
hPrintTemplate As Long
hSetupTemplate As Long
End Type
Private Type DEVNAMES_TYPE
wDriverOffset As Integer
wDeviceOffset As Integer
wOutputOffset As Integer
wDefault As Integer
extra As String * 100
End Type
Private Type DEVMODE_TYPE
dmDeviceName As String * CCHDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCHFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Private Declare Function CHOOSECOLOR Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Declare Function PrintDialog Lib "comdlg32.dll" Alias "PrintDlgA" (pPrintdlg As PRINTDLG_TYPE) As Long
Private Declare Function PAGESETUPDLG Lib "comdlg32.dll" Alias "PageSetupDlgA" (pPagesetupdlg As PAGESETUPDLG) As Long
Private Declare Function CHOOSEFONT Lib "comdlg32.dll" Alias "ChooseFontA" (pChoosefont As CHOOSEFONT) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
Dim OFName As OPENFILENAME
Dim CustomColors() As Byte
Private Sub Command1_Click()
Dim sFile As String
sFile = ShowOpen
If sFile <> "" Then
MsgBox "You chose this file: " + sFile
Else
MsgBox "You pressed cancel"
End If
End Sub
Private Sub Command2_Click()
Dim sFile As String
sFile = ShowSave
If sFile <> "" Then
MsgBox "You chose this file: " + sFile
Else
MsgBox "You pressed cancel"
End If
End Sub
Private Sub Command3_Click()
Dim NewColor As Long
NewColor = ShowColor
If NewColor <> -1 Then
Me.BackColor = NewColor
Else
MsgBox "You chose cancel"
End If
End Sub
Private Sub Command4_Click()
MsgBox ShowFont
End Sub
Private Sub Command5_Click()
ShowPrinter Me
End Sub
Private Sub Command6_Click()
ShowPageSetupDlg
End Sub
Private Sub Form_Load()
ReDim CustomColors(0 To 16 * 4 - 1) As Byte
Dim i As Integer
For i = LBound(CustomColors) To UBound(CustomColors)
CustomColors(i) = 0
Next i
'Set the captions
Command1.Caption = "ShowOpen"
Command2.Caption = "ShowSave"
Command3.Caption = "ShowColor"
Command4.Caption = "ShowFont"
Command5.Caption = "ShowPrinter"
Command6.Caption = "ShowPageSetupDlg"
End Sub
Private Function ShowColor() As Long
Dim cc As CHOOSECOLOR
Dim Custcolor(16) As Long
Dim lReturn As Long
'set the structure size
cc.lStructSize = Len(cc)
'Set the owner
cc.hwndOwner = Me.hwnd
'set the application's instance
cc.hInstance = App.hInstance
'set the custom colors (converted to Unicode)
cc.lpCustColors = StrConv(CustomColors, vbUnicode)
'no extra flags
cc.flags = 0
'Show the 'Select Color'-dialog
If CHOOSECOLOR(cc) <> 0 Then
ShowColor = cc.rgbResult
CustomColors = StrConv(cc.lpCustColors, vbFromUnicode)
Else
ShowColor = -1
End If
End Function
Private Function ShowOpen() As String
'Set the structure size
OFName.lStructSize = Len(OFName)
'Set the owner window
OFName.hwndOwner = Me.hwnd
'Set the application's instance
OFName.hInstance = App.hInstance
'Set the filet
OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
'Create a buffer
OFName.lpstrFile = Space$(254)
'Set the maximum number of chars
OFName.nMaxFile = 255
'Create a buffer
OFName.lpstrFileTitle = Space$(254)
'Set the maximum number of chars
OFName.nMaxFileTitle = 255
'Set the initial directory
OFName.lpstrInitialDir = "C:\"
'Set the dialog title
OFName.lpstrTitle = "Open File - KPD-Team 1998"
'no extra flags
OFName.flags = 0
'Show the 'Open File'-dialog
If GetOpenFileName(OFName) Then
ShowOpen = Trim$(OFName.lpstrFile)
Else
ShowOpen = ""
End If
End Function
Private Function ShowFont() As String
Dim cf As CHOOSEFONT, lfont As LOGFONT, hMem As Long, pMem As Long
Dim fontname As String, retval As Long
lfont.lfHeight = 0 ' determine default height
lfont.lfWidth = 0 ' determine default width
lfont.lfEscapement = 0 ' angle between baseline and escapement vector
lfont.lfOrientation = 0 ' angle between baseline and orientation vector
lfont.lfWeight = FW_NORMAL ' normal weight i.e. not bold
lfont.lfCharSet = DEFAULT_CHARSET ' use default character set
lfont.lfOutPrecision = OUT_DEFAULT_PRECIS ' default precision mapping
lfont.lfClipPrecision = CLIP_DEFAULT_PRECIS ' default clipping precision
lfont.lfQuality = DEFAULT_QUALITY ' default quality setting
lfont.lfPitchAndFamily = DEFAULT_PITCH Or FF_ROMAN ' default pitch, proportional with serifs
lfont.lfFaceName = "Times New Roman" & vbNullChar ' string must be null-terminated
' Create the memory block which will act as the LOGFONT structure buffer.
hMem = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(lfont))
pMem = GlobalLock(hMem) ' lock and get pointer
CopyMemory ByVal pMem, lfont, Len(lfont) ' copy structure's contents into block
' Initialize dialog box: Screen and printer fonts, point size between 10 and 72.
cf.lStructSize = Len(cf) ' size of structure
cf.hwndOwner = Form1.hwnd ' window Form1 is opening this dialog box
cf.hDC = Printer.hDC ' device context of default printer (using VB's mechanism)
cf.lpLogFont = pMem ' pointer to LOGFONT memory block buffer
cf.iPointSize = 120 ' 12 point font (in units of 1/10 point)
cf.flags = CF_BOTH Or CF_EFFECTS Or CF_FORCEFONTEXIST Or CF_INITTOLOGFONTSTRUCT Or CF_LIMITSIZE
cf.rgbColors = RGB(0, 0, 0) ' black
cf.nFontType = REGULAR_FONTTYPE ' regular font type i.e. not bold or anything
cf.nSizeMin = 10 ' minimum point size
cf.nSizeMax = 72 ' maximum point size
' Now, call the function. If successful, copy the LOGFONT structure back into the structure
' and then print out the attributes we mentioned earlier that the user selected.
retval = CHOOSEFONT(cf) ' open the dialog box
If retval <> 0 Then ' success
CopyMemory lfont, ByVal pMem, Len(lfont) ' copy memory back
' Now make the fixed-length string holding the font name into a "normal" string.
ShowFont = Left(lfont.lfFaceName, InStr(lfont.lfFaceName, vbNullChar) - 1)
Debug.Print ' end the line
End If
' Deallocate the memory block we created earlier. Note that this must
' be done whether the function succeeded or not.
retval = GlobalUnlock(hMem) ' destroy pointer, unlock block
retval = GlobalFree(hMem) ' free the allocated memory
End Function
Private Function ShowSave() As String
'Set the structure size
OFName.lStructSize = Len(OFName)
'Set the owner window
OFName.hwndOwner = Me.hwnd
'Set the application's instance
OFName.hInstance = App.hInstance
'Set the filet
OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
'Create a buffer
OFName.lpstrFile = Space$(254)
'Set the maximum number of chars
OFName.nMaxFile = 255
'Create a buffer
OFName.lpstrFileTitle = Space$(254)
'Set the maximum number of chars
OFName.nMaxFileTitle = 255
'Set the initial directory
OFName.lpstrInitialDir = "C:\"
'Set the dialog title
OFName.lpstrTitle = "Save File - KPD-Team 1998"
'no extra flags
OFName.flags = 0
'Show the 'Save File'-dialog
If GetSaveFileName(OFName) Then
ShowSave = Trim$(OFName.lpstrFile)
Else
ShowSave = ""
End If
End Function
Private Function ShowPageSetupDlg() As Long
Dim m_PSD As PAGESETUPDLG
'Set the structure size
m_PSD.lStructSize = Len(m_PSD)
'Set the owner window
m_PSD.hwndOwner = Me.hwnd
'Set the application instance
m_PSD.hInstance = App.hInstance
'no extra flags
m_PSD.flags = 0
'Show the pagesetup dialog
If PAGESETUPDLG(m_PSD) Then
ShowPageSetupDlg = 0
Else
ShowPageSetupDlg = -1
End If
End Function
Public Sub ShowPrinter(frmOwner As Form, Optional PrintFlags As Long)
'-> Code by Donald Grover
Dim PrintDlg As PRINTDLG_TYPE
Dim DevMode As DEVMODE_TYPE
Dim DevName As DEVNAMES_TYPE
Dim lpDevMode As Long, lpDevName As Long
Dim bReturn As Integer
Dim objPrinter As Printer, NewPrinterName As String
' Use PrintDialog to get the handle to a memory
' block with a DevMode and DevName structures
PrintDlg.lStructSize = Len(PrintDlg)
PrintDlg.hwndOwner = frmOwner.hwnd
PrintDlg.flags = PrintFlags
On Error Resume Next
'Set the current orientation and duplex setting
DevMode.dmDeviceName = Printer.DeviceName
DevMode.dmSize = Len(DevMode)
DevMode.dmFields = DM_ORIENTATION Or DM_DUPLEX
DevMode.dmPaperWidth = Printer.Width
DevMode.dmOrientation = Printer.Orientation
DevMode.dmPaperSize = Printer.PaperSize
DevMode.dmDuplex = Printer.Duplex
On Error GoTo 0
'Allocate memory for the initialization hDevMode structure
'and copy the settings gathered above into this memory
PrintDlg.hDevMode = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(DevMode))
lpDevMode = GlobalLock(PrintDlg.hDevMode)
If lpDevMode > 0 Then
CopyMemory ByVal lpDevMode, DevMode, Len(DevMode)
bReturn = GlobalUnlock(PrintDlg.hDevMode)
End If
'Set the current driver, device, and port name strings
With DevName
.wDriverOffset = 8
.wDeviceOffset = .wDriverOffset + 1 + Len(Printer.DriverName)
.wOutputOffset = .wDeviceOffset + 1 + Len(Printer.Port)
.wDefault = 0
End With
With Printer
DevName.extra = .DriverName & Chr(0) & .DeviceName & Chr(0) & .Port & Chr(0)
End With
'Allocate memory for the initial hDevName structure
'and copy the settings gathered above into this memory
PrintDlg.hDevNames = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(DevName))
lpDevName = GlobalLock(PrintDlg.hDevNames)
If lpDevName > 0 Then
CopyMemory ByVal lpDevName, DevName, Len(DevName)
bReturn = GlobalUnlock(lpDevName)
End If
'Call the print dialog up and let the user make changes
If PrintDialog(PrintDlg) <> 0 Then
'First get the DevName structure.
lpDevName = GlobalLock(PrintDlg.hDevNames)
CopyMemory DevName, ByVal lpDevName, 45
bReturn = GlobalUnlock(lpDevName)
GlobalFree PrintDlg.hDevNames
'Next get the DevMode structure and set the printer
'properties appropriately
lpDevMode = GlobalLock(PrintDlg.hDevMode)
CopyMemory DevMode, ByVal lpDevMode, Len(DevMode)
bReturn = GlobalUnlock(PrintDlg.hDevMode)
GlobalFree PrintDlg.hDevMode
NewPrinterName = UCase$(Left(DevMode.dmDeviceName, InStr(DevMode.dmDeviceName, Chr$(0)) - 1))
If Printer.DeviceName <> NewPrinterName Then
For Each objPrinter In Printers
If UCase$(objPrinter.DeviceName) = NewPrinterName Then
Set Printer = objPrinter
'set printer toolbar name at this point
End If
Next
End If
On Error Resume Next
'Set printer object properties according to selections made
'by user
Printer.Copies = DevMode.dmCopies
Printer.Duplex = DevMode.dmDuplex
Printer.Orientation = DevMode.dmOrientation
Printer.PaperSize = DevMode.dmPaperSize
Printer.PrintQuality = DevMode.dmPrintQuality
Printer.ColorMode = DevMode.dmColor
Printer.PaperBin = DevMode.dmDefaultSource
On Error GoTo 0
End If
End Sub 'This project needs 6 command buttons
Option Explicit
Const FW_NORMAL = 400
Const DEFAULT_CHARSET = 1
Const OUT_DEFAULT_PRECIS = 0
Const CLIP_DEFAULT_PRECIS = 0
Const DEFAULT_QUALITY = 0
Const DEFAULT_PITCH = 0
Const FF_ROMAN = 16
Const CF_PRINTERFONTS = &H2
Const CF_SCREENFONTS = &H1
Const CF_BOTH = (CF_SCREENFONTS Or CF_PRINTERFONTS)
Const CF_EFFECTS = &H100&
Const CF_FORCEFONTEXIST = &H10000
Const CF_INITTOLOGFONTSTRUCT = &H40&
Const CF_LIMITSIZE = &H2000&
Const REGULAR_FONTTYPE = &H400
Const LF_FACESIZE = 32
Const CCHDEVICENAME = 32
Const CCHFORMNAME = 32
Const GMEM_MOVEABLE = &H2
Const GMEM_ZEROINIT = &H40
Const DM_DUPLEX = &H1000&
Const DM_ORIENTATION = &H1&
Const PD_PRINTSETUP = &H40
Const PD_DISABLEPRINTTOFILE = &H80000
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Type PAGESETUPDLG
lStructSize As Long
hwndOwner As Long
hDevMode As Long
hDevNames As Long
flags As Long
ptPaperSize As POINTAPI
rtMinMargin As RECT
rtMargin As RECT
hInstance As Long
lCustData As Long
lpfnPageSetupHook As Long
lpfnPagePaintHook As Long
lpPageSetupTemplateName As String
hPageSetupTemplate As Long
End Type
Private Type CHOOSECOLOR
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As String
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Type LOGFONT
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName As String * 31
End Type
Private Type CHOOSEFONT
lStructSize As Long
hwndOwner As Long ' caller's window handle
hDC As Long ' printer DC/IC or NULL
lpLogFont As Long ' ptr. to a LOGFONT struct
iPointSize As Long ' 10 * size in points of selected font
flags As Long ' enum. type flags
rgbColors As Long ' returned text color
lCustData As Long ' data passed to hook fn.
lpfnHook As Long ' ptr. to hook function
lpTemplateName As String ' custom template name
hInstance As Long ' instance handle of.EXE that
' contains cust. dlg. template
lpszStyle As String ' return the style field here
' must be LF_FACESIZE or bigger
nFontType As Integer ' same value reported to the EnumFonts
' call back with the extra FONTTYPE_
' bits added
MISSING_ALIGNMENT As Integer
nSizeMin As Long ' minimum pt size allowed &
nSizeMax As Long ' max pt size allowed if
' CF_LIMITSIZE is used
End Type
Private Type PRINTDLG_TYPE
lStructSize As Long
hwndOwner As Long
hDevMode As Long
hDevNames As Long
hDC As Long
flags As Long
nFromPage As Integer
nToPage As Integer
nMinPage As Integer
nMaxPage As Integer
nCopies As Integer
hInstance As Long
lCustData As Long
lpfnPrintHook As Long
lpfnSetupHook As Long
lpPrintTemplateName As String
lpSetupTemplateName As String
hPrintTemplate As Long
hSetupTemplate As Long
End Type
Private Type DEVNAMES_TYPE
wDriverOffset As Integer
wDeviceOffset As Integer
wOutputOffset As Integer
wDefault As Integer
extra As String * 100
End Type
Private Type DEVMODE_TYPE
dmDeviceName As String * CCHDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCHFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Private Declare Function CHOOSECOLOR Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As CHOOSECOLOR) As Long
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Declare Function PrintDialog Lib "comdlg32.dll" Alias "PrintDlgA" (pPrintdlg As PRINTDLG_TYPE) As Long
Private Declare Function PAGESETUPDLG Lib "comdlg32.dll" Alias "PageSetupDlgA" (pPagesetupdlg As PAGESETUPDLG) As Long
Private Declare Function CHOOSEFONT Lib "comdlg32.dll" Alias "ChooseFontA" (pChoosefont As CHOOSEFONT) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
Dim OFName As OPENFILENAME
Dim CustomColors() As Byte
Private Sub Command1_Click()
Dim sFile As String
sFile = ShowOpen
If sFile <> "" Then
MsgBox "You chose this file: " + sFile
Else
MsgBox "You pressed cancel"
End If
End Sub
Private Sub Command2_Click()
Dim sFile As String
sFile = ShowSave
If sFile <> "" Then
MsgBox "You chose this file: " + sFile
Else
MsgBox "You pressed cancel"
End If
End Sub
Private Sub Command3_Click()
Dim NewColor As Long
NewColor = ShowColor
If NewColor <> -1 Then
Me.BackColor = NewColor
Else
MsgBox "You chose cancel"
End If
End Sub
Private Sub Command4_Click()
MsgBox ShowFont
End Sub
Private Sub Command5_Click()
ShowPrinter Me
End Sub
Private Sub Command6_Click()
ShowPageSetupDlg
End Sub
Private Sub Form_Load()
ReDim CustomColors(0 To 16 * 4 - 1) As Byte
Dim i As Integer
For i = LBound(CustomColors) To UBound(CustomColors)
CustomColors(i) = 0
Next i
'Set the captions
Command1.Caption = "ShowOpen"
Command2.Caption = "ShowSave"
Command3.Caption = "ShowColor"
Command4.Caption = "ShowFont"
Command5.Caption = "ShowPrinter"
Command6.Caption = "ShowPageSetupDlg"
End Sub
Private Function ShowColor() As Long
Dim cc As CHOOSECOLOR
Dim Custcolor(16) As Long
Dim lReturn As Long
'set the structure size
cc.lStructSize = Len(cc)
'Set the owner
cc.hwndOwner = Me.hwnd
'set the application's instance
cc.hInstance = App.hInstance
'set the custom colors (converted to Unicode)
cc.lpCustColors = StrConv(CustomColors, vbUnicode)
'no extra flags
cc.flags = 0
'Show the 'Select Color'-dialog
If CHOOSECOLOR(cc) <> 0 Then
ShowColor = cc.rgbResult
CustomColors = StrConv(cc.lpCustColors, vbFromUnicode)
Else
ShowColor = -1
End If
End Function
Private Function ShowOpen() As String
'Set the structure size
OFName.lStructSize = Len(OFName)
'Set the owner window
OFName.hwndOwner = Me.hwnd
'Set the application's instance
OFName.hInstance = App.hInstance
'Set the filet
OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
'Create a buffer
OFName.lpstrFile = Space$(254)
'Set the maximum number of chars
OFName.nMaxFile = 255
'Create a buffer
OFName.lpstrFileTitle = Space$(254)
'Set the maximum number of chars
OFName.nMaxFileTitle = 255
'Set the initial directory
OFName.lpstrInitialDir = "C:\"
'Set the dialog title
OFName.lpstrTitle = "Open File - KPD-Team 1998"
'no extra flags
OFName.flags = 0
'Show the 'Open File'-dialog
If GetOpenFileName(OFName) Then
ShowOpen = Trim$(OFName.lpstrFile)
Else
ShowOpen = ""
End If
End Function
Private Function ShowFont() As String
Dim cf As CHOOSEFONT, lfont As LOGFONT, hMem As Long, pMem As Long
Dim fontname As String, retval As Long
lfont.lfHeight = 0 ' determine default height
lfont.lfWidth = 0 ' determine default width
lfont.lfEscapement = 0 ' angle between baseline and escapement vector
lfont.lfOrientation = 0 ' angle between baseline and orientation vector
lfont.lfWeight = FW_NORMAL ' normal weight i.e. not bold
lfont.lfCharSet = DEFAULT_CHARSET ' use default character set
lfont.lfOutPrecision = OUT_DEFAULT_PRECIS ' default precision mapping
lfont.lfClipPrecision = CLIP_DEFAULT_PRECIS ' default clipping precision
lfont.lfQuality = DEFAULT_QUALITY ' default quality setting
lfont.lfPitchAndFamily = DEFAULT_PITCH Or FF_ROMAN ' default pitch, proportional with serifs
lfont.lfFaceName = "Times New Roman" & vbNullChar ' string must be null-terminated
' Create the memory block which will act as the LOGFONT structure buffer.
hMem = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(lfont))
pMem = GlobalLock(hMem) ' lock and get pointer
CopyMemory ByVal pMem, lfont, Len(lfont) ' copy structure's contents into block
' Initialize dialog box: Screen and printer fonts, point size between 10 and 72.
cf.lStructSize = Len(cf) ' size of structure
cf.hwndOwner = Form1.hwnd ' window Form1 is opening this dialog box
cf.hDC = Printer.hDC ' device context of default printer (using VB's mechanism)
cf.lpLogFont = pMem ' pointer to LOGFONT memory block buffer
cf.iPointSize = 120 ' 12 point font (in units of 1/10 point)
cf.flags = CF_BOTH Or CF_EFFECTS Or CF_FORCEFONTEXIST Or CF_INITTOLOGFONTSTRUCT Or CF_LIMITSIZE
cf.rgbColors = RGB(0, 0, 0) ' black
cf.nFontType = REGULAR_FONTTYPE ' regular font type i.e. not bold or anything
cf.nSizeMin = 10 ' minimum point size
cf.nSizeMax = 72 ' maximum point size
' Now, call the function. If successful, copy the LOGFONT structure back into the structure
' and then print out the attributes we mentioned earlier that the user selected.
retval = CHOOSEFONT(cf) ' open the dialog box
If retval <> 0 Then ' success
CopyMemory lfont, ByVal pMem, Len(lfont) ' copy memory back
' Now make the fixed-length string holding the font name into a "normal" string.
ShowFont = Left(lfont.lfFaceName, InStr(lfont.lfFaceName, vbNullChar) - 1)
Debug.Print ' end the line
End If
' Deallocate the memory block we created earlier. Note that this must
' be done whether the function succeeded or not.
retval = GlobalUnlock(hMem) ' destroy pointer, unlock block
retval = GlobalFree(hMem) ' free the allocated memory
End Function
Private Function ShowSave() As String
'Set the structure size
OFName.lStructSize = Len(OFName)
'Set the owner window
OFName.hwndOwner = Me.hwnd
'Set the application's instance
OFName.hInstance = App.hInstance
'Set the filet
OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
'Create a buffer
OFName.lpstrFile = Space$(254)
'Set the maximum number of chars
OFName.nMaxFile = 255
'Create a buffer
OFName.lpstrFileTitle = Space$(254)
'Set the maximum number of chars
OFName.nMaxFileTitle = 255
'Set the initial directory
OFName.lpstrInitialDir = "C:\"
'Set the dialog title
OFName.lpstrTitle = "Save File - KPD-Team 1998"
'no extra flags
OFName.flags = 0
'Show the 'Save File'-dialog
If GetSaveFileName(OFName) Then
ShowSave = Trim$(OFName.lpstrFile)
Else
ShowSave = ""
End If
End Function
Private Function ShowPageSetupDlg() As Long
Dim m_PSD As PAGESETUPDLG
'Set the structure size
m_PSD.lStructSize = Len(m_PSD)
'Set the owner window
m_PSD.hwndOwner = Me.hwnd
'Set the application instance
m_PSD.hInstance = App.hInstance
'no extra flags
m_PSD.flags = 0
'Show the pagesetup dialog
If PAGESETUPDLG(m_PSD) Then
ShowPageSetupDlg = 0
Else
ShowPageSetupDlg = -1
End If
End Function
Public Sub ShowPrinter(frmOwner As Form, Optional PrintFlags As Long)
'-> Code by Donald Grover
Dim PrintDlg As PRINTDLG_TYPE
Dim DevMode As DEVMODE_TYPE
Dim DevName As DEVNAMES_TYPE
Dim lpDevMode As Long, lpDevName As Long
Dim bReturn As Integer
Dim objPrinter As Printer, NewPrinterName As String
' Use PrintDialog to get the handle to a memory
' block with a DevMode and DevName structures
PrintDlg.lStructSize = Len(PrintDlg)
PrintDlg.hwndOwner = frmOwner.hwnd
PrintDlg.flags = PrintFlags
On Error Resume Next
'Set the current orientation and duplex setting
DevMode.dmDeviceName = Printer.DeviceName
DevMode.dmSize = Len(DevMode)
DevMode.dmFields = DM_ORIENTATION Or DM_DUPLEX
DevMode.dmPaperWidth = Printer.Width
DevMode.dmOrientation = Printer.Orientation
DevMode.dmPaperSize = Printer.PaperSize
DevMode.dmDuplex = Printer.Duplex
On Error GoTo 0
'Allocate memory for the initialization hDevMode structure
'and copy the settings gathered above into this memory
PrintDlg.hDevMode = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(DevMode))
lpDevMode = GlobalLock(PrintDlg.hDevMode)
If lpDevMode > 0 Then
CopyMemory ByVal lpDevMode, DevMode, Len(DevMode)
bReturn = GlobalUnlock(PrintDlg.hDevMode)
End If
'Set the current driver, device, and port name strings
With DevName
.wDriverOffset = 8
.wDeviceOffset = .wDriverOffset + 1 + Len(Printer.DriverName)
.wOutputOffset = .wDeviceOffset + 1 + Len(Printer.Port)
.wDefault = 0
End With
With Printer
DevName.extra = .DriverName & Chr(0) & .DeviceName & Chr(0) & .Port & Chr(0)
End With
'Allocate memory for the initial hDevName structure
'and copy the settings gathered above into this memory
PrintDlg.hDevNames = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(DevName))
lpDevName = GlobalLock(PrintDlg.hDevNames)
If lpDevName > 0 Then
CopyMemory ByVal lpDevName, DevName, Len(DevName)
bReturn = GlobalUnlock(lpDevName)
End If
'Call the print dialog up and let the user make changes
If PrintDialog(PrintDlg) <> 0 Then
'First get the DevName structure.
lpDevName = GlobalLock(PrintDlg.hDevNames)
CopyMemory DevName, ByVal lpDevName, 45
bReturn = GlobalUnlock(lpDevName)
GlobalFree PrintDlg.hDevNames
'Next get the DevMode structure and set the printer
'properties appropriately
lpDevMode = GlobalLock(PrintDlg.hDevMode)
CopyMemory DevMode, ByVal lpDevMode, Len(DevMode)
bReturn = GlobalUnlock(PrintDlg.hDevMode)
GlobalFree PrintDlg.hDevMode
NewPrinterName = UCase$(Left(DevMode.dmDeviceName, InStr(DevMode.dmDeviceName, Chr$(0)) - 1))
If Printer.DeviceName <> NewPrinterName Then
For Each objPrinter In Printers
If UCase$(objPrinter.DeviceName) = NewPrinterName Then
Set Printer = objPrinter
'set printer toolbar name at this point
End If
Next
End If
On Error Resume Next
'Set printer object properties according to selections made
'by user
Printer.Copies = DevMode.dmCopies
Printer.Duplex = DevMode.dmDuplex
Printer.Orientation = DevMode.dmOrientation
Printer.PaperSize = DevMode.dmPaperSize
Printer.PrintQuality = DevMode.dmPrintQuality
Printer.ColorMode = DevMode.dmColor
Printer.PaperBin = DevMode.dmDefaultSource
On Error GoTo 0
End If
End Sub Const CDERR_DIALOGFAILURE = &HFFFF
Const CDERR_FINDRESFAILURE = &H6
Const CDERR_GENERALCODES = &H0
Const CDERR_INITIALIZATION = &H2
Const CDERR_LOADRESFAILURE = &H7
Const CDERR_LOADSTRFAILURE = &H5
Const CDERR_LOCKRESFAILURE = &H8
Const CDERR_MEMALLOCFAILURE = &H9
Const CDERR_MEMLOCKFAILURE = &HA
Const CDERR_NOHINSTANCE = &H4
Const CDERR_NOHOOK = &HB
Const CDERR_REGISTERMSGFAIL = &HC
Const CDERR_NOTEMPLATE = &H3
Const CDERR_STRUCTSIZE = &H1
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As Any) As Long
Private Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
Private Sub Form_Load()
GetOpenFileName ByVal 0&
Select Case CommDlgExtendedError
Case CDERR_DIALOGFAILURE
MsgBox "The dialog box could not be created."
Case CDERR_FINDRESFAILURE
MsgBox "The common dialog box function failed to find a specified resource."
Case CDERR_INITIALIZATION
MsgBox "The common dialog box function failed during initialization."
Case CDERR_LOADRESFAILURE
MsgBox "The common dialog box function failed to load a specified resource."
Case CDERR_LOADSTRFAILURE
MsgBox "The common dialog box function failed to load a specified string."
Case CDERR_LOCKRESFAILURE
MsgBox "The common dialog box function failed to lock a specified resource."
Case CDERR_MEMALLOCFAILURE
MsgBox "The common dialog box function was unable to allocate memory for internal structures."
Case CDERR_MEMLOCKFAILURE
MsgBox "The common dialog box function was unable to lock the memory associated with a handle."
Case CDERR_NOHINSTANCE
MsgBox "The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box, but you failed to provide a corresponding instance handle."
Case CDERR_NOHOOK
MsgBox "The ENABLEHOOK flag was set in the Flags member of the initialization structure for the corresponding common dialog box, but you failed to provide a pointer to a corresponding hook procedure."
Case CDERR_REGISTERMSGFAIL
MsgBox "The RegisterWindowMessage function returned an error code when it was called by the common dialog box function."
Case CDERR_NOTEMPLATE
MsgBox "The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box, but you failed to provide a corresponding template."
Case CDERR_STRUCTSIZE
MsgBox "The lStructSize member of the initialization structure for the corresponding common dialog box is invalid."
Case Else
MsgBox "Undefined error ..."
End Select
End Sub Use the Open File common dialog box to prompt the user for a *.txt file. The user's selection is then displayed (the filename, not the file itself). The dialog box opens when the user clicks button Command1. So, to use this example, place a command button named Command1 on a form window.
' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustomFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Const OFN_FILEMUSTEXIST = &H1000
Public Const OFN_HIDEREADONLY = &H4
Public Const OFN_PATHMUSTEXIST = &H800
Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (lpofn _
As OPENFILENAME) As Long
' *** Place the following code inside a form window.
Private Sub Command1_Click()
Dim filebox As OPENFILENAME ' open file dialog structure
Dim fname As String ' filename the user selected
Dim result As Long ' result of opening the dialog
' Configure how the dialog box will look
With filebox
' Size of the structure.
.lStructSize = Len(filebox)
' Handle to window opening the dialog.
.hwndOwner = Me.hWnd
' Handle to calling instance (not needed).
.hInstance = 0
' File filters to make available: Text Files and All Files
.lpstrFilter = "Text Files (*.txt)" & vbNullChar & "*.txt" & vbNullChar & _
"All Files (*.*)" & vbNullChar & "*.*" & vbNullChar & vbNullChar
'.lpstrCustomFilter is ignored -- unused string
.nMaxCustomFilter = 0
' Default filter is the first one (Text Files, in this case).
.nFilterIndex = 1
' No default filename. Also make room for received
' path and filename of the user's selection.
.lpstrFile = Space(256) & vbNullChar
.nMaxFile = Len(.lpstrFile)
' Make room for filename of the user's selection.
.lpstrFileTitle = Space(256) & vbNullChar
.nMaxFileTitle = Len(.lpstrFileTitle)
' Initial directory is C:\.
.lpstrInitialDir = "C:\" & vbNullChar
' Title of file dialog.
.lpstrTitle = "Select a File" & vbNullChar
' The path and file must exist; hide the read-only box.
.flags = OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY
' The rest of the options aren't needed.
.nFileOffset = 0
.nFileExtension = 0
'.lpstrDefExt is ignored -- unused string
.lCustData = 0
.lpfnHook = 0
'.lpTemplateName is ignored -- unused string
End With
' Display the dialog box.
result = GetOpenFileName(filebox)
If result <> 0 Then
' Remove null space from the file name.
fname = Left(filebox.lpstrFile, InStr(filebox.lpstrFile, vbNullChar) - 1)
Debug.Print "The selected file: "; fname
End If
End Sub Use the Save File common dialog box to prompt the user for a *.txt file. The user's selection is then displayed (the filename, not the file itself). The dialog box opens when the user clicks button Command1. So, to use this example, place a command button named Command1 on a form window.
' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustomFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Const OFN_HIDEREADONLY = &H4
Public Const OFN_OVERWRITEPROMPT = &H2
Public Const OFN_PATHMUSTEXIST = &H800
Public Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (lpofn _
As OPENFILENAME) As Long
' *** Place the following code inside a form window.
Private Sub Command1_Click()
Dim filebox As OPENFILENAME ' save file dialog structure
Dim fname As String ' filename the user selected
Dim result As Long ' result of opening the dialog
' Configure how the dialog box will look
With filebox
' Size of the structure.
.lStructSize = Len(filebox)
' Handle to window opening the dialog.
.hwndOwner = Me.hWnd
' Handle to calling instance (not needed).
.hInstance = 0
' File filters to make available: Text Files and All Files
.lpstrFilter = "Text Files (*.txt)" & vbNullChar & "*.txt" & vbNullChar & _
"All Files (*.*)" & vbNullChar & "*.*" & vbNullChar & vbNullChar
'.lpstrCustomFilter is ignored -- unused string
.nMaxCustomFilter = 0
' Default filter is the first one (Text Files, in this case).
.nFilterIndex = 1
' No default filename. Also make room for received
' path and filename of the user's selection.
.lpstrFile = Space(256) & vbNullChar
.nMaxFile = Len(.lpstrFile)
' Make room for filename of the user's selection.
.lpstrFileTitle = Space(256) & vbNullChar
.nMaxFileTitle = Len(.lpstrFileTitle)
' Initial directory is C:\.
.lpstrInitialDir = "C:\" & vbNullChar
' Title of file dialog.
.lpstrTitle = "Select a File" & vbNullChar
' The path must exist. Hide the read-only box.
' Warn if an existing file is selected.
.flags = OFN_PATHMUSTEXIST Or OFN_HIDEREADONLY Or OFN_OVERWRITEPROMPT
' The rest of the options aren't needed.
.nFileOffset = 0
.nFileExtension = 0
'.lpstrDefExt is ignored -- unused string
.lCustData = 0
.lpfnHook = 0
'.lpTemplateName is ignored -- unused string
End With
' Display the dialog box.
result = GetSaveFileName(filebox)
If result <> 0 Then
' Remove null space from the file name.
fname = Left(filebox.lpstrFile, InStr(filebox.lpstrFile, vbNullChar) - 1)
Debug.Print "The selected file: "; fname
End If
End Sub
نام تابع: ChooseColor
اعلان: Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (lpcc As CHOOSECOLOR_TYPE) As Long
سيستم عامل: NT , 2000 , 98 , 95 , CE
توضيحات: اين تابع جعبه انتخاب رنگ را باز ميكند.
مقدار بازگشتي: ---
پارامترها: ---
ثابتهاي مورد استفاده: ---
کتابخانه: ComDlg32
توابع مرتبط: ChooseFont
نکات: ---
کد نمونه:
اعلان: Declare Function ChooseFont Lib "comdlg32.dll" Alias "ChooseFontA" (lpcf As CHOOSEFONT_TYPE) As Long
سيستم عامل: NT , 2000 , 98 , 95
توضيحات: اين تابع جعبه ديالوگ مربوط به انتخاب فونت را باز ميكند.همه اطلاعات لازم جهت ساختن و ايجاد اين جعبه ديالوگ فونت ارسال شده به تابع در ساختار pChooseFont ذخيره ميگردد.براي فونت منطقي اطلاعات بايد در يك ساختار LOGFONT ذخيره شود كه امكان دسترسي به آن فراهم شود.
مقدار بازگشتي: اگر كاربر دكمه انصراف را فشار دهد يا سيستم دچار خطا گردد اين تابع مقدار صفر را برميگرداند (براي دانستن نوع خطا به تابع CommDlgExtendedError استفاده نماييد) در غير اين صورت و انتخاب يك فونت تابع مقدار غير صفر برميگرداند.
پارامترها: lpcf متغيري از نوع CHOOSEFONT_TYPE كه اطلاعات فونت قبل و بعد از انتخاب در آن ذخيره شده است قبل از صدا كرد تابع حتما بايد اين متغير را آماده سازي نمود(Initialize) و پس از آن كه تابع را فراخواني شد اطلاعات فونت را از آن دريافت نمود.
ثابتهاي مورد استفاده: ---
کتابخانه: ComDlg32
توابع مرتبط: ChooseColor
نکات: ---
کد نمونه:
اعلان: Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
سيستم عامل: NT , 98 , 95
توضيحات: اين تابع كد خطا را ازآخرين دياكوگ باكس برميگرداند. اين تابع براي توابع ديگر API ويندوز خطا را برنميگرداند و در عوض براي دانستن نوع خطا انجام شده از تابع GetLastError ميشود استفاده نمود.اگر در آخرين ديالوگ باكس انجام كار موفقيت آميز بود تابع مقدار تعريف نشده را برميگرداند و اگر خطايي صورت گرفته باشد تابع يكي از مقادير زير را برميگرداند. CDERR_DIALOGFAILURE = &HFFFF ديالوگ باكس باز نشده CDERR_FINDRESFAILURE = &H6 خطا در تابع در پيدا نشدن منابع خواسته ها CDERR_GENERALCODES = &H0 خطا در خواص جنرال تعريف شده براي ديالوگ باكس CDERR_INITIALIZATION = &H2 خطا در آماده سازي(initialization) –(احتمالا خطاي حافظه) CDERR_LOADRESFAILURE = &H7 خطا در تابع در بازخواني منابع خواسته ها CDERR_LOADSTRFAILURE = &H5 خطا در تابع در بازخواني خواسته استرينگ CDERR_LOCKRESFAILURE = &H8 خطا در تابع در قفل كردن منابع خواسته ها CDERR_MEMALLOCFAILURE = &H9 خطا در تعيين محل حافظه CDERR_MEMLOCKFAILURE = &HA خطا در قفل كردن محل حافظه CDERR_NOHINSTANCE = &H4 تابع با يك هندل آماده نبود.(اگر يكي مورد نياز باشد) CDERR_NOHOOK = &HB تابع با يك هندل ايجاد شده آماده نبوده(اگر يكي مورد نياز باشد) CDERR_NOTEMPLATE = &H3 تابع با يك الگو آماده نبود.(اگر يكي مورد نياز باشد) CDERR_REGISTERMSGFAIL = &HC خطا در رچيستر كردن پنجره خطا CDERR_STRUCTSIZE = &H1 اين تابع آماده بود با يك ساختار ناشناخته CFERR_CHOOSEFONTCODES = &H2000 خطا در انتخاب فونت نمايش ديالوگ باكس CFERR_MAXLESSTHANMIN = &H2002 اين تابع درحال آماده سازي با فونتي ميباشد كه سايز أن كمتر از حداقل سايز فونت مورد نظر ميباشد. CFERR_NOFONTS = &H2001 تابع نميتواند فونت موجود را پيدا نمايد FNERR_BUFFERTOOSMALL = &H3003 تابع أماده ميكند با يك بافر نام فايل بسيار كوچك FNERR_FILENAMECODES = &H3000 ايراد در باز كردن يا ذخيره كردن فايل ديالوگ باكس FNERR_INVALIDFILENAME = &H3002 تابع آماده بود يا دريافت كرده يك نام فايل غير موجود را FNERR_SUBCLASSFAILURE = &H3001 براي ليست باكس حافظه كافي موجود نبود FRERR_BUFFERLENGTHZERO = &H4001 تابع با يك بافر غير موجود آماده سازي شده. FRERR_FINDREPLACECODES = &H4000 اشكال در پيدا كردن و يا جابجا كردن در ديالوگ باكس PDERR_CREATEICFAILURE = &H100A خطا در ايجاد اطلاعات PDERR_DEFAULTDIFFERENT = &H100C تابع نياز به چاپ دارد ولي چاپگر پيش فرض تنظيماتي متفاوت دارد PDERR_DNDMMISMATCH = &H1009 اطلاعات با ساختار چاپگر متفاوت است PDERR_GETDEVMODEFAIL = &H1005 خرابي در ساختار اوليه تعريف چاپگر PDERR_INITFAILURE = &H1006 بروز اشكال در زمان آماده سازي PDERR_LOADDRVFAILURE = &H1004 بروز اشكال در بار گزاري يك ديوايس درايور PDERR_NODEFAULTPRN = &H1008 بروز اشكال در يافتن چاپگر پيش فرض PDERR_NODEVICES = &H1007 بروز اشكال در يافتن چاپگر PDERR_PARSEFAILURE = &H1002 بروز اشكال در مرتبط كردن اجزاي چاپگر با استرينگ آن در Win.ini (براي فهم بيشتر فايل Win.ini را اديت نماييد و به قسمت Printer Port مراجعه كنيد) PDERR_PRINTERCODES = &H1000 بروز اشكال در چاپگر مشترك PDERR_PRINTERNOTFOUND = &H100B بروز اشكال در پيدا كردن اطلاعات چاپگر مورد نياز در فايل Win.ini PDERR_SETUPFAILURE = &H1001 بروز اشكال در باز گذاري منابع
مقدار بازگشتي: CDERR_DIALOGFAILURE = &HFFFF ديالوگ باكس باز نشده CDERR_FINDRESFAILURE = &H6 خطا در تابع در پيدا نشدن منابع خواسته ها CDERR_GENERALCODES = &H0 خطا در خواص جنرال تعريف شده براي ديالوگ باكس CDERR_INITIALIZATION = &H2 خطا در آماده سازي(initialization) –(احتمالا خطاي حافظه) CDERR_LOADRESFAILURE = &H7 خطا در تابع در بازخواني منابع خواسته ها CDERR_LOADSTRFAILURE = &H5 خطا در تابع در بازخواني خواسته استرينگ CDERR_LOCKRESFAILURE = &H8 خطا در تابع در قفل كردن منابع خواسته ها CDERR_MEMALLOCFAILURE = &H9 خطا در تعيين محل حافظه CDERR_MEMLOCKFAILURE = &HA خطا در قفل كردن محل حافظه CDERR_NOHINSTANCE = &H4 تابع با يك هندل آماده نبود.(اگر يكي مورد نياز باشد) CDERR_NOHOOK = &HB تابع با يك هندل ايجاد شده آماده نبوده(اگر يكي مورد نياز باشد) CDERR_NOTEMPLATE = &H3 تابع با يك الگو آماده نبود.(اگر يكي مورد نياز باشد) CDERR_REGISTERMSGFAIL = &HC خطا در رچيستر كردن پنجره خطا CDERR_STRUCTSIZE = &H1 اين تابع آماده بود با يك ساختار ناشناخته CFERR_CHOOSEFONTCODES = &H2000 خطا در انتخاب فونت نمايش ديالوگ باكس CFERR_MAXLESSTHANMIN = &H2002 اين تابع درحال آماده سازي با فونتي ميباشد كه سايز أن كمتر از حداقل سايز فونت مورد نظر ميباشد. CFERR_NOFONTS = &H2001 تابع نميتواند فونت موجود را پيدا نمايد FNERR_BUFFERTOOSMALL = &H3003 تابع أماده ميكند با يك بافر نام فايل بسيار كوچك FNERR_FILENAMECODES = &H3000 ايراد در باز كردن يا ذخيره كردن فايل ديالوگ باكس FNERR_INVALIDFILENAME = &H3002 تابع آماده بود يا دريافت كرده يك نام فايل غير موجود را FNERR_SUBCLASSFAILURE = &H3001 براي ليست باكس حافظه كافي موجود نبود FRERR_BUFFERLENGTHZERO = &H4001 تابع با يك بافر غير موجود آماده سازي شده. FRERR_FINDREPLACECODES = &H4000 اشكال در پيدا كردن و يا جابجا كردن در ديالوگ باكس PDERR_CREATEICFAILURE = &H100A خطا در ايجاد اطلاعات PDERR_DEFAULTDIFFERENT = &H100C تابع نياز به چاپ دارد ولي چاپگر پيش فرض تنظيماتي متفاوت دارد PDERR_DNDMMISMATCH = &H1009 اطلاعات با ساختار چاپگر متفاوت است PDERR_GETDEVMODEFAIL = &H1005 خرابي در ساختار اوليه تعريف چاپگر PDERR_INITFAILURE = &H1006 بروز اشكال در زمان آماده سازي PDERR_LOADDRVFAILURE = &H1004 بروز اشكال در بار گزاري يك ديوايس درايور PDERR_NODEFAULTPRN = &H1008 بروز اشكال در يافتن چاپگر پيش فرض PDERR_NODEVICES = &H1007 بروز اشكال در يافتن چاپگر PDERR_PARSEFAILURE = &H1002 بروز اشكال در مرتبط كردن اجزاي چاپگر با استرينگ آن در Win.ini (براي فهم بيشتر فايل Win.ini را اديت نماييد و به قسمت Printer Port مراجعه كنيد) PDERR_PRINTERCODES = &H1000 بروز اشكال در چاپگر مشترك PDERR_PRINTERNOTFOUND = &H100B بروز اشكال در پيدا كردن اطلاعات چاپگر مورد نياز در فايل Win.ini PDERR_SETUPFAILURE = &H1001 بروز اشكال در باز گذاري منابع
پارامترها: ---
ثابتهاي مورد استفاده: ---
کتابخانه: Comdlg32
توابع مرتبط: GetLastError
نکات: ---
کد نمونه:
اعلان: Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (lpofn As OPENFILENAME) As Long
سيستم عامل: CE , 2000 , NT , 98 , 95
توضيحات: اين تابع باز ميكند پنجره ديالوگ باكس OpenFile را .همه تنظيمات براي ايجاد اين ديالوگ باكس و اطلاعات برگشت داده شده داخل پارامتر پاس داده شده(يك استراكچر از نوعOPENFILENAME) lpofn قرارداده ميشود. توجه داشته باشيد اين دستور عملا فايلي را باز نميكند بلكه با استفاده از آن كار بر ميتواند با استفاده از امكانات ويندوز يك فايل را انتخاب كرده و نام و محل قرار گيري آن را دريافت نمايد.
مقدار بازگشتي: اگر يك يا تعداد بيشتري فايل انتخاب شد توسط ديالوگ باكس اين تابع مقدار غير صفر برميگرداند و اگر به خطا بر خورد يا كاربر دكمه كنسل را فشار داد تابع صفر برميگرداند.براي تعيين نوع خطا ميتوان از CommDlgExtendedError استفاده نمود.
پارامترها: lpofn پارامترهاي لازم جهت باز كردن ديالوگ باكس Open . نام فايل(ها) و ديگر اطلاعات نيز داخل اين پارامتر برگشت داده ميشود.
ثابتهاي مورد استفاده: ---
کتابخانه: ComDlg32
توابع مرتبط: GetSaveFileName
نکات: ---
کد نمونه:
اعلان: Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (lpofn As OPENFILENAME) As Long
سيستم عامل: CE , 2000 , NT , 98 , 95
توضيحات: تابع پنجره ديالوگ ذخيره كردن را باز ميكند(ديالوگ باكس Save) . تمامي تنظيمات براي بازكردن اين ديالوگ و مقدار برگشتي از تابع نيز داخل يك پارامتر ارسال شده به نام lpofn قرار داده ميشود. توجه نماييد اين تابع خود فايلي را ذخيره نميكند بلكه پنجره اي جهت ذخيره باز ميكند.
مقدار بازگشتي: اگر كار بر يك فايل را انتخاب نمايد تابع مقدار غير صفر برميگرداند و اگر خطا برخورد نمايد يا كاربر دكمه كنسل را فشار داده باشد تابع صفر برميگرداند براي دانستن نوع خطا از تابع CommDlgExtendedError استفاده نماييد.
پارامترها: lpofn پارامترهاي لازم جهت باز كردن پنجره ديلوگ ذخيره و همچنين مقدار برگشتي نام فايلي كه كاربر انتخاب كرده و يا اطلاعات ديگر.
ثابتهاي مورد استفاده: ---
کتابخانه: ComDlg32
توابع مرتبط: GetOpenFileName
نکات: ---
کد نمونه:
