CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Code problem

  1. #1
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Code problem

    ok this is a replacement for CommonDialog.bas (replaces open and save)



    option Explicit


    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
    public Const OFN_READONLY = &H1
    public Const OFN_OVERWRITEPROMPT = &H2
    public Const OFN_HIDEREADONLY = &H4
    public Const OFN_NOCHANGEDIR = &H8
    public Const OFN_SHOWHELP = &H10
    public Const OFN_ENABLEHOOK = &H20
    public Const OFN_ENABLETEMPLATE = &H40
    public Const OFN_ENABLETEMPLATEHANDLE = &H80
    public Const OFN_NOVALIDATE = &H100
    public Const OFN_ALLOWMULTISELECT = &H200
    public Const OFN_EXTENSIONDIFFERENT = &H400
    public Const OFN_PATHMUSTEXIST = &H800
    public Const OFN_FILEMUSTEXIST = &H1000
    public Const OFN_CREATEPROMPT = &H2000
    public Const OFN_SHAREAWARE = &H4000
    public Const OFN_NOREADONLYRETURN = &H8000
    public Const OFN_NOTESTFILECREATE = &H10000
    public Const OFN_NONETWORKBUTTON = &H20000
    public Const OFN_NOLONGNAMES = &H40000 ' force no long names for 4.x modules
    public Const OFN_EXPLORER = &H80000 ' new look commdlg
    public Const OFN_NODEREFERENCELINKS = &H100000
    public Const OFN_LONGNAMES = &H200000 ' force long names for 3.x modules
    public Const OFN_SHAREFALLTHROUGH = 2
    public Const OFN_SHARENOWARN = 1
    public Const OFN_SHAREWARN = 0


    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


    Function SaveDialog(Form1 as Form, Filter as string, Title as string, InitDir as string) as string



    Dim ofn as OPENFILENAME
    Dim a as Long
    ofn.lStructSize = len(ofn)
    ofn.hwndOwner = Form1.hWnd
    ofn.hInstance = App.hInstance
    If Right$(Filter, 1) <> "|" then Filter = Filter + "|"


    for a = 1 to len(Filter)
    If mid$(Filter, a, 1) = "|" then mid$(Filter, a, 1) = Chr$(0)
    next

    ofn.lpstrFilter = Filter
    ofn.lpstrFile = Space$(254)
    ofn.nMaxFile = 255
    ofn.lpstrFileTitle = Space$(254)
    ofn.nMaxFileTitle = 255
    ofn.lpstrInitialDir = InitDir
    ofn.lpstrTitle = Title
    ofn.flags = OFN_HIDEREADONLY Or OFN_OVERWRITEPROMPT Or OFN_CREATEPROMPT
    a = GetSaveFileName(ofn)


    If (a) then
    SaveDialog = Trim$(ofn.lpstrFile)
    else
    SaveDialog = ""
    End If

    End Function



    Function OpenDialog(Form1 as Form, Filter as string, Title as string, InitDir as string) as string


    Dim ofn as OPENFILENAME
    Dim a as Long
    ofn.lStructSize = len(ofn)
    ofn.hwndOwner = Form1.hWnd
    ofn.hInstance = App.hInstance
    If Right$(Filter, 1) <> "|" then Filter = Filter + "|"


    for a = 1 to len(Filter)
    If mid$(Filter, a, 1) = "|" then mid$(Filter, a, 1) = Chr$(0)
    next

    ofn.lpstrFilter = Filter
    ofn.lpstrFile = Space$(254)
    ofn.nMaxFile = 255
    ofn.lpstrFileTitle = Space$(254)
    ofn.nMaxFileTitle = 255
    ofn.lpstrInitialDir = InitDir
    ofn.lpstrTitle = Title
    ofn.flags = OFN_HIDEREADONLY Or OFN_FILEMUSTEXIST
    a = GetOpenFileName(ofn)


    If (a) then
    OpenDialog = Trim$(ofn.lpstrFile)
    else
    OpenDialog = ""
    End If

    End Function





    well when i save it to BMP it saves the file, but it don't rename it's extenction to .BMP, when it should, if i rename manually then it works, but why it won't rename automatically like CommonDialog does
    Please Help



  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Code problem

    IMHO the code you posted has nothing to do with your problem.
    Nowhere in your code I can see any "renaming".
    GetSaveFileName does not save or rename anything. It only allows you to select or specify a file name.
    You have to do the save operation yourself.
    That's probably the area where your problem is.


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured