GetOpenFileName() ?

This is a discussion on GetOpenFileName() ? within the Windows Programming forums, part of the Platform Specific Boards category; Can anyone please show me how to use GetOpenFileName() ? Thanks....

  1. #1
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768

    GetOpenFileName() ?

    Can anyone please show me how to use GetOpenFileName() ?

    Thanks.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361

    Re: GetOpenFileName() ?

    Originally posted by Devil Panther
    Can anyone please show me how to use GetOpenFileName() ?

    Thanks.
    STFW

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    EDIT: As Eibro says. Code removed as it's copyrighted.
    Last edited by _Elixia_; 07-18-2003 at 01:22 PM.

  4. #4
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    the example does not work, it doesn't even show the dialog box.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  5. #5
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    I have a feeling it's your code, and not the examples code. Are you checking the return values of all your calls? If you want another example, check www.sunlightd.com (It's the Windows tutorial, bitmap loading section)

  6. #6
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    I've placed the code so it will be used when a button is pressed, and changed the hwnd to my handle and everything, but it doesn't show the dialog...
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  7. #7
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Please wait while I attempt to use my telepathic powers to read the code off of your PC...

    Or, if you don't want to wait as long, post some code.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  8. #8
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    Code:
    OPENFILENAME	ofn;
    char filename[256]={0};
    
    ZeroMemory(&ofn, sizeof(OPENFILENAME));
    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = hDlg;
    ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0All Files (*.*\0*.*\0\0";
    ofn.lpstrFile = filename;
    ofn.nMaxFile = 256;
    ofn.lpstrTitle = "Browse";
    ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
    GetOpenFileName(&ofn);
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  9. #9
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    From The Forgers Win32 API Tutorial
    http://www.winprog.org/tutorial/

    Code:
     OPENFILENAME ofn;
        char szFileName[MAX_PATH] = "";
        ZeroMemory(&ofn, sizeof(ofn));
        ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
        ofn.hwndOwner = hwnd;
        ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
        ofn.lpstrFile = szFileName;
        ofn.nMaxFile = MAX_PATH;
        ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
        ofn.lpstrDefExt = "txt";
        if(GetOpenFileName(&ofn))
        {
            // Do something usefull with the filename stored in szFileName 
        }
    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  10. #10
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    *shrug* works fine for me. The only potential problem I can see is hDlg. Ensure that it's a valid window handle.

  11. #11
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    A stab in the dark, have you called InitCommonControls() somewhere?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  12. #12
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    here is the exact code:

    Code:
    // in the WM_COMMAND
    case IDD_SETLOG_BROWSE:
                        {
        OPENFILENAME ofn;
        char szFileName[100] = "";
        InitCommonControls();
        ZeroMemory(&ofn, sizeof(ofn));
        ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
        ofn.hwndOwner = hDlg;
        ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
        ofn.lpstrFile = szFileName;
        ofn.nMaxFile = 100;
        ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
        ofn.lpstrDefExt = "txt";
        if(GetOpenFileName(&ofn))
        {
           MessageBox (NULL, "Message" , " ", 0);
        }
                        }
                         break;
    hDlg is the handle of that dialog, I'm calling the GetOpenFileName() from...

    And I am calling InitCommonControls().


    Just... one more thing, I'm using borland C++ 5.5 compiler. And C, not C++, I don't know, I'm just shooting in the dark as well
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  13. #13
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    http://www.winprog.org/tutorial/

    I've checked out their example code for GetOpenFileName()
    I downloaded it (app_two) and tried to use FILE->OPEN, but nothing happened... maybe it's the windows?
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  14. #14
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    With the last code you posted, did it put up the messagge box, i.e. is the call to GetOpenFileName() returning TRUE?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  15. #15
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    it returns false... and as I said, it doesn't even show the dialog...
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GetOpenFileName not working...
    By manugarciac in forum Windows Programming
    Replies: 6
    Last Post: 04-24-2007, 10:50 PM
  2. GetOpenFileName function for dir's?
    By willc0de4food in forum Windows Programming
    Replies: 3
    Last Post: 04-15-2006, 12:54 AM
  3. Major Problems with GetSaveFileName() and GetOpenFileName()
    By CodeHacker in forum Windows Programming
    Replies: 8
    Last Post: 07-12-2004, 11:05 AM
  4. Troubles with GetOpenFileName()
    By lyx in forum Windows Programming
    Replies: 13
    Last Post: 10-28-2003, 08:47 PM
  5. GetOpenFileName() won't show
    By harryP in forum Windows Programming
    Replies: 1
    Last Post: 10-20-2003, 04:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21