Thread: C++ Dialog Not Opening OPENFILENAME

  1. #1
    Registered User
    Join Date
    Dec 2019
    Posts
    7

    C++ Dialog Not Opening OPENFILENAME

    Im coding in CodeBlocks with the help of ResEdit for the GUI. I dont know why it doesnt open the Open File Dialog Box when pressing the IDC_FILEEXE.

    Anyone can give me a tip?

    Thanks

    CODE

    Code:
    #include <windows.h>#include <commctrl.h>
    #include <stdio.h>
    #include "resource.h"
    
    
    HINSTANCE hInst;
    
    
    
    
    void open_file(HWND hWnd){
    
    
        OPENFILENAME ofn;
    
    
        char file_name[100];
    
    
        ZeroMemory(&ofn, sizeof(OPENFILENAME));
    
    
        ofn.lStructSize = sizeof(OPENFILENAME)l
        ofn.hwndOwner = hWnd;
        ofn.lpstrFile = file_name;
        ofn.lpstrFile[0] = '\0';
        ofn.nMaxFile = 100;
        ofn.lpstrFilter = L"EXE file\0*.exe\0";
        ofn.nFilterIndex = 1;
    
    
        GetOpenFileName(&ofn);
    }
    
    
    
    
    
    
    
    
    BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        switch(uMsg)
        {
        case WM_INITDIALOG:
        {
        }
        return TRUE;
    
    
        case WM_CLOSE:
        {
            EndDialog(hwndDlg, 0);
        }
        return TRUE;
    
    
        case WM_COMMAND:
        {
            switch(wParam)
            {
                case ID_EXIT: EndDialog(hwndDlg,0);
                case ID_FINDEXE:{
                    open_file(hWnd);
                    break;
                }
    
    
            }
        }
        return TRUE;
        }
        return FALSE;
    }
    
    
    
    
    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
        hInst=hInstance;
        InitCommonControls();
        return DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), HWND_DESKTOP, (DLGPROC)DlgMain);
    }

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    834
    I dont know why it doesnt open the Open File Dialog Box when pressing the IDC_FILEEXE.

    That identifier doesn't appear in your code.
    The world hangs on a thin thread, and that is the psyche of man. - Carl Jung

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    3,744
    Code:
    ofn.lpstrFilter = L"EXE file\0*.exe\0";
    Is there any reason you think two '\0' are allowed?

    Edit: Looks like you were correct.
    A buffer containing pairs of null-terminated filter strings. The last string in the buffer must be terminated by two NULL characters.
    Tim S.
    Last edited by stahta01; 3 Weeks Ago at 09:05 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    3,744
    Paste error or ??

    Code:
    ofn.lStructSize = sizeof(OPENFILENAME)l
    The missing ";" at the end of line.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    Dec 2019
    Posts
    7
    Thanks Guys for you replys, above alllthe errors the code had, Code Blocks didnt update my code fixes.
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Openfilename
    By Gordon in forum Windows Programming
    Replies: 15
    Last Post: 09-22-2007, 04:37 PM
  2. Using OPENFILENAME
    By IdioticCreation in forum Windows Programming
    Replies: 9
    Last Post: 01-16-2007, 08:26 AM
  3. Having Trouble Opening My Dialog Box
    By ElWhapo in forum Windows Programming
    Replies: 8
    Last Post: 12-28-2004, 12:13 PM
  4. opening a dialog window from inside a dialog window
    By uvacow in forum C++ Programming
    Replies: 1
    Last Post: 12-02-2002, 09:27 AM
  5. Dialog not opening...
    By void in forum Windows Programming
    Replies: 3
    Last Post: 10-20-2002, 02:32 AM

Tags for this Thread