Common Dialogs made easy - Page 2-VBForums
Page 2 of 2 FirstFirst 12
Results 41 to 51 of 51

Thread: Common Dialogs made easy

  1. #41
    Member
    Join Date
    Apr 2001
    Location
    Lake Charles, LA, USA
    Posts
    43
    Joacim, I figured out what's not working. I got the class to display a msgbox by modifying the ShowPrinter dialog like this:

    Code:
    Public Function ShowPrinter() As Boolean
        Dim pd As PrintDlgStruct
        Dim nRetVal As Long
        
        pd.lpSetupTemplateName = ""
        pd.lpPrintTemplateName = ""
        pd.hwndOwner = m_Owner.hwnd
        pd.nCopies = Me.PrintCopies
        pd.Flags = PD_HIDEPRINTTOFILE Or PD_NOPAGENUMS Or PD_NOSELECTION
        pd.lStructSize = Len(pd)
        nRetVal = PrintDlg(pd)
        MsgBox pd.nCopies
        Me.PrintCopies = pd.nCopies
        ShowPrinter = (nRetVal <> 0)
    End Function
    What I found was that everytime the msgbox appeared, no matter what the number of copies was set to, pd.nCopies was always 1 for some reason. Do you know why it would do that? Is there a way to fix it? Please respond A.S.A.P. Thanks for all your help.

  2. #42

    Thread Starter
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,241
    Yes I know whats wrong.
    When you call ShowPrinterProperties and you'll have the option to set the number of copies in that dialog (I can't do it on any of my printers)
    the value is sent directly to the printer and is not (for some reason) saved in the structure (Why? -Ask Microsoft).
    When this is stored in the printer the printer itself will print that number of copies without you needing to loop thru the PrintCopies property.

    If you don't want this behaviour I can only suggest that you don't show the properties dialog but only call the ShowPrinter dialog.

    Best regards
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP

  3. #43
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943
    ccommondialog.filename won't work.... I am doing openfolder in the commondialog class, but when i try to retrieve the filename it won't work, is there another way to do this??
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

  4. #44

    Thread Starter
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,241
    The FileName property can only be used when you pick a file (in the Open and Save As dialogs).
    When you call the ShowFolder method use the Path property instead.

    Best regards

    PS.
    To Cinder829,

    Thanks for downloading Source Edit. I hope you enjoy it and please mail me any feedbacks you can think of.
    And if you didn't download it, there is a version 1.2 update on http://www.sourceedit.cc
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP

  5. #45
    Member
    Join Date
    Apr 2001
    Location
    Lake Charles, LA, USA
    Posts
    43
    Well, I've gotten rid of the print properties dialog, but I still can't print multiple copies. Do you know why pd.nCopies wouldn't change when the user closed the print dialog? For some reason it's always 1. Is there a fix or a workaround? Here's the code I have right now.

    Code:
    Public Function ShowPrinter() As Boolean
        Dim pd As PrintDlgStruct
        Dim nRetVal As Long
        
        pd.lpSetupTemplateName = ""
        pd.lpPrintTemplateName = ""
        pd.hwndOwner = m_Owner.hwnd
        pd.nCopies = Me.PrintCopies
        pd.Flags = m_Flags
        pd.lStructSize = Len(pd)
        nRetVal = PrintDlg(pd)
        Me.PrintCopies = pd.nCopies
        ShowPrinter = (nRetVal <> 0)
    End Function
    P.S. Joacim, I know that Source Edit probably wasn't really made to edit vb programs, but it would still be nice if it did a better job with visual basic form files, e.g. didn't display all of the form information at the top of the file. Other than that, it's great! Keep up the good work...

  6. #46
    veebee
    Guest
    Joacim,

    I'm trying to use this class to show the color dialog, and I can't get it to set the focus on the correct box for the initial color. My code is as follows:
    VB Code:
    1. i_CommonDialog.Init Me
    2.     i_CommonDialog.Color = Me.BackColor
    3.     lb_Result = i_CommonDialog.ShowColor
    4.     If lb_Result = True Then Me.BackColor = i_CommonDialog.Color
    When the color dialog appears, the first color box in the dialog has focus (which is a pink color box on mine) instead of the gray that is my form backcolor. If I click OK without clicking on any color boxes, the color does not change to the color in that first box, it does stay the same color as my form, which would be correct. But it should set focus on the initial display of the dialog box to the correct color box, shouldn't it?

    I also noticed that the custom color boxes at the bottom are not always the same.

    Thanks..... (this class is very helpful)

  7. #47

    Thread Starter
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,241
    The problem is that you assign one of the system colors. In this case (probably) vbButtonFace which has a value of &H8000000F. Which isn't actually grey.
    To change this behaviour add the following declaration to the class
    VB Code:
    1. Private Declare Function GetSysColor _
    2.  Lib "user32" ( _
    3.  ByVal nIndex As Long) As Long
    Now change the Property Let Color procedure into the following
    VB Code:
    1. Public Property Let Color(ByVal nNew As Long)
    2.     Dim sHex As String
    3.     m_Color = nNew
    4.     If m_Color < 0 Then
    5.         ' A system color. Convert it to correct color
    6.         sHex = Right$(Hex(m_Color), 4)
    7.         m_Color = CLng("&H" & sHex)
    8.         m_Color = GetSysColor(m_Color)
    9.     End If
    10. End Property
    You should now get the correct color.

    Thank you so much for pointing this out.
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP

  8. #48
    Junior Member
    Join Date
    Feb 2002
    Posts
    18

    show folder

    Does this class work in MS Word 97?

    I have it running in VB6 but want to use it in VBA

    I am declaring my class as following but I'm getting an error

    Dim cdl As CCommonDialogs

    Set cdl = New CCommonDialogs

    cdl.Init Me
    cdl.ShowFolder

  9. #49

    Thread Starter
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,241
    You have to make some slight changes to the code to make it work in Word.
    The Init method takes a VB Form as an argument. This form is then used as the parent window for the dialog boxes.
    Remove the Init method and change all the code you find with m_Owner.hWnd to 0.

    Best regards
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP

  10. #50
    Junior Member
    Join Date
    Feb 2002
    Posts
    18
    Thanks for the quick response. Unfortunately I didn't have any luck. I'm new to VBA and learning this as I go so it could be something quite simple that I'm doing wrong. I'm using the class in a template which I place in the startup folder for word. It wont let me step through the code to find the error so I feel a little helpless. Why is it not possible to run my macro when I'm editing the template. Why do I have to run the template in the startup folder in order to run the macro and then not be able to view the code behind the macro? Any help muchly appreciated!

  11. #51
    New Member
    Join Date
    Mar 2009
    Posts
    13

    Re: Common Dialogs made easy

    How I can show common dialog ( commondialog1.showfont for Example) in center of screen ?

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.