INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Tips -N- Tricks

How can I improve control over the MS common dialog? by ChrisRChamberlain
Posted: 12 Apr 11 (Edited 7 Dec 11)

One of the useful features of the MS common dialog is the facility to select multiple files, and an alternative example is outlined in FAQ184-3106: How can I select multiple files from Windows.

What is not so easy is to control where on the screen you would like the dialog to appear and to add an icon specific to your application to the dialog.

To begin, add a new form to your project, setting .Visible = .F., .ShowWindow = 2, and set the .Icon property to a suitable icon.

What the form will do is 'launch' the Microsoft Common Dialog Control where you, as a developer, wish it be seen, whilst the form itself never shows.

Go to Tools > Options > Controls > ActiveX Controls, select Microsoft Common Dialog Control, Version 6.0, and drop it on your form.

In the .Activate() event of the form add

CODE

THIS.Release()

In the .Init() event of the form, add the following code

CODE

LOCAL lcCurDir ,;
    lcFileName ,;
    lcFileList ,;
    lcPath

lcCurDir = CURDIR()

WITH THIS
    .Left = 350
    .Top = 425
    .olecontrol1.Filter = [All Files|*.*|JPG Files|*.jpg|BMP Files|*.bmp]
    .olecontrol1.FilterIndex = 1
    .olecontrol1.DialogTitle = [Open files]
    .olecontrol1.MaxFileSize = 32767
    .olecontrol1.Flags = BITOR(0x4, 0x10, 0x200, 0x800, 0x1000, 0x8000, 0x40000, 0x80000)
    .olecontrol1.InitDir = [C:\]
    .olecontrol1.ShowOpen()
    lcFilelist = .olecontrol1.FileName
    lcFileName = []
    lcPath = []
ENDWITH     

CREATE CURSOR FILENAMES (filename C(254))

DO CASE
CASE EMPTY(lcFileList)
    USE IN SELECT([FILENAMES])
CASE OCCURS(CHR(0),lcFileList) = 0
    INSERT INTO FILENAMES (filename) VALUES (lcFileList)
OTHERWISE
    FOR i = 0 TO OCCURS(CHR(0),lcFileList)
        IF i = 0
            lcPath = SUBSTR(lcFileList,1,AT(CHR(0),lcFileList))        
            lcFileList = SUBSTR(lcFileList,AT(CHR(0),lcFileList) + 1)
        ELSE
            IF CHR(0) $ lcFileList    
                lcFileName = SUBSTR(lcFileList,1,AT(CHR(0),lcFileList))    
                lcFileList = SUBSTR(lcFileList,AT(CHR(0),lcFileList) + 1)    
            ELSE
                lcFileName = lcFileList
            ENDI
            INSERT INTO FILENAMES    ;
                (filename);
                VALUES ;
                (ADDBS(lcPath) + lcFileName)
        ENDIF
    ENDFOR
ENDCASE

SET DEFA TO (lcCurDir)
The use of the BITOR() function is an alternative to adding the desired constant values together to determine the .Flags value, which in turn determines the behaviour of the common dialog.

Documentation may be found here, and there may well be better documentation elsewhere.

It's relatively simple to change the behaviour of the common dialog by adding or removing parameters to suit.

Other properties will also need modifying to suit your particular project.

The dialog will now appear wherever you have determined the form would have shown and the dialog will have the icon of your choice.

Unless the user cancelled out, the barebones code example will populate a cursor FILENAMES with the path\filename.ext of a single selected file or path\filename.ext of multiple selected files.

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close