|
-
Jul 9th, 2001, 01:46 AM
#1
Thread Starter
Member
Help me get rid of the Common Dialog OCX!
I'm writing a program that up until now used the comdlg32.ocx control. All the program uses is the open, save and print dialogs. I want to get rid of the control so that my setup files won't be as big. I found the code to show the open and save dialogs using the common dialog dll that comes with windows, but what I need to know is how I can show the print dialog using a dll that comes with windows. I can't find the code anywhere (maybe it doesn't exist? ), but if someone could help me out, I could get rid of that ocx file. I can't just use the print commands in vb because I want to show the user the same print dialog that most programs use. If anyone knows how to do this, any help you could give me would be greatly appreciated. Thanks!
-
Jul 9th, 2001, 02:04 AM
#2
PowerPoster
Can you make your own form that looks exactly the same as the print dialog, then use the built in print functions?
-
Jul 9th, 2001, 02:21 AM
#3
Registered User
File open:
VB Code:
Option Explicit
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As Long
nMaxCustrFilter 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
lCustrData As Long
lpfnHook As Long
lpTemplateName As Long
End Type
Private Const OFN_HIDEREADONLY = &H4 'hide open as read only check box
Private Const OFN_ALLOWMULTISELECT = &H200
Private Const OFN_CREATEPROMPT = &H2000
Private Const OFN_EXPLORER = &H80000
Private Const OFN_FILEMUSTEXIST = &H1000
Private Const OFN_NOCHANGEDIR = &H8
Private Const OFN_NODEREFERENCELINKS = &H100000
Private Const OFN_NONETWORKBUTTON = &H20000
Private Const OFN_NOREADONLYRETURN = &H8000
Private Const OFN_NOVALIDATE = &H100
Private Const OFN_OVERWRITEPROMPT = &H2
Private Const OFN_PATHMUSTEXIST = &H800
Private Const OFN_READONLY = &H1
Private Const OFN_SHOWHELP = &H10
Private Const ALLFILES = "All Files"
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Boolean
'Purpose: Shows the open file common dialog
'Inputs: strTitle, the title of the dialog, pass "" for default
'Inputs: strDefaultPath, the default path
'Inputs: Filter, the filter, an even number of arguments e.g.("text files, *.txt, mdb files, *.mdb")
'Outputs: Returns the specified file name and path or "" if cancelled
'Author: Nucleus
Public Function ShowOpen(Optional strTitle As String, _
Optional strDefaultPath As String, Optional Filter As String) As String
Dim OFName As OPENFILENAME
OFName.lStructSize = Len(OFName)
'Set the parent window
OFName.hwndOwner = GetActiveWindow
'Set the application's instance
OFName.hInstance = 0
'create a buffer for the file
OFName.lpstrFile = Space$(254)
'set the maximum length of a returned file
OFName.nMaxFile = 255
'Create a buffer for the file title
OFName.lpstrFileTitle = Space$(254)
'Set the maximum length of a returned file title
OFName.nMaxFileTitle = 255
'Set the title
OFName.lpstrTitle = strTitle
'No flags
OFName.Flags = OFN_HIDEREADONLY Or OFN_FILEMUSTEXIST _
If strDefaultPath = "" Or Len(Dir$(strDefaultPath)) Then
OFName.lpstrInitialDir = strDefaultPath
Else
OFName.lpstrInitialDir = CurDir$
End If
OFName.lpstrFilter = CreateFilterString(Filter)
'Call the Open dialog routine.
If GetOpenFileName(OFName) Then _
ShowOpen = Trim$(OFName.lpstrFile) Else ShowOpen = ""
End Function
Private Function CreateFilterString(Filter As String) As String
' Creates a filter string from the passed in arguments.
' Expects an even number of arguments
Dim sa() As String, i%
sa = Split(Filter, ",")
For i = 0 To UBound(sa)
CreateFilterString = CreateFilterString & sa(i) & vbNullChar
Next i
CreateFilterString = CreateFilterString & "All Files (*.*)" & vbNullChar & "*.*"
End Function
usage:
Private Sub Command1_Click()
MsgBox ShowOpen()
End Sub
-
Jul 9th, 2001, 02:22 AM
#4
Registered User
File save:
VB Code:
Option Explicit
Private Declare Function GetSaveFileNameA Lib "comdlg32.dll" (pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetActiveWindow Lib "user32" () As Long
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 Const OFN_HIDEREADONLY = &H4 'hide open as read only check box
Private Const OFN_OVERWRITEPROMPT = &H2 'show message before overwriting existing files
Private Const OFN_PATHMUSTEXIST = &H800 'refuse filenames with invalid paths
'Purpose : Shows the save file common dialog
'Inputs : strTitle The title of the dialog, pass "" for default
' strDefaultPath The default path
' Filter The filter, an even number of arguments
' e.g.("text files, *.txt, mdb files, *.mdb")
'Outputs : Returns the specified file name and path or "" if cancelled
'Author : Nucleus
Function ShowSave(Optional strTitle As String, Optional strDefaultPath As String, _
Optional Filter As String) As String
Const clBufferLen As Long = 255
Dim OFName As OPENFILENAME, sBuffer As String * 255
Dim strFilter As String: strFilter = ""
Dim intcount As Integer
'Set title
OFName.lpstrTitle = strTitle
'Set filter
OFName.lpstrFilter = CreateFilterString(Filter)
'Set the initial directory
If strDefaultPath = "" Or Len(Dir$(strDefaultPath)) Then
OFName.lpstrInitialDir = strDefaultPath
Else
OFName.lpstrInitialDir = CurDir$
End If
OFName.lStructSize = Len(OFName)
OFName.hwndOwner = GetActiveWindow 'or Me.hwnd in VB
OFName.hInstance = 0 'or App.hInstance in VB
OFName.lpstrFile = sBuffer
OFName.nMaxFile = clBufferLen 'Set max number of characters
OFName.lpstrFileTitle = sBuffer
OFName.nMaxFileTitle = clBufferLen 'Set max number of characters
OFName.flags = OFN_HIDEREADONLY Or OFN_OVERWRITEPROMPT Or OFN_PATHMUSTEXIST
'Show dialog
If GetSaveFileNameA(OFName) Then _
ShowSave = Trim$(OFName.lpstrFile) Else ShowSave = ""
End Function
Private Function CreateFilterString(Filter As String) As String
' Creates a filter string from the passed in arguments.
' Expects an even number of arguments
Dim sa() As String, i%
sa = Split(Filter, ",")
For i = 0 To UBound(sa)
CreateFilterString = CreateFilterString & sa(i) & vbNullChar
Next i
CreateFilterString = CreateFilterString & "All Files (*.*)" & vbNullChar & "*.*"
End Function
Usage:
'Usage
Private Sub Command1_Click()
MsgBox ShowSave(, "d:", "Text files , *.txt")
End Sub
-
Jul 9th, 2001, 02:59 AM
#5
Thread Starter
Member
To MidgetsBro: I thought of that and I guess I could do it, but I won't for two reasons:
A: It would be a lot of work that I'd rather not do if the code already exists in a dll file.
B: After writing the new form and trying to make sure there were no bugs in it, I'd probably find that I'd made my setup files bigger than they were before because my program had gotten so much larger.
Thanks for trying to help though. 
To Nucleus: I already found that code. What I need to know is if there's a way to do that for the print dialog box. Thanks anyway.
If anyone else has any ideas or knows how to do this, please post a response!
-
Jul 9th, 2001, 03:11 AM
#6
Fanatic Member
Well he beat me to the punch there. I was going to say that was the part you already knew . Anyhow, I'm not going to repost a long list of junk, so I'll give a link with an example. There's one in the API Guide, which means there is a version on the net. This is it.
http://www.allapi.net/api/PrintDialog.php
It goes to the main page of the function and there's a link for the example, and there are other links you may find useful (ones to all of the other common dialog parts).
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
-
Jul 9th, 2001, 03:35 AM
#7
Thread Starter
Member
Thanks Kaverin! You da man!
-
Jul 9th, 2001, 03:55 AM
#8
Registered User
Also check out here for a class that replaces the common dialog control completely:
http://www.vbforums.com/showthread.p...=common+dialog
-
Jul 9th, 2001, 04:18 AM
#9
-
Jul 10th, 2001, 02:47 AM
#10
Thread Starter
Member
Thanks for the link to the great class module Nucleus! I was having trouble with Kaverin's code...it kept crashing for some reason ...
-
Jul 10th, 2001, 04:07 AM
#11
Registered User
No problem, but thank Joacim Andersson not me
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|