Help with text program...

This is a discussion on Help with text program... within the Windows Programming forums, part of the Platform Specific Boards category; The Problem: szFileName can't be read from the ShellExecute command. The Code(This is part of the WinProc): Code: case WM_COMMAND: ...

  1. #1
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    Help with text program...

    The Problem:

    szFileName can't be read from the ShellExecute command.

    The Code(This is part of the WinProc):

    Code:
    case WM_COMMAND:
        {
            switch(LOWORD(wParam))
            {
                    case ID_FILE_NEW:
                    {
                            DestroyWindow(hEdit);
                                    hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", 
                WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 
                0, 0, 800, 600, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
    
    
                    }
                    break;
                    case ID_FILE_EXIT:
                    {
                            SendMessage(hwnd, WM_CLOSE, 0, 0);
                    }
                    break;
                    case ID_FILE_SAVE:
                    {
                                OPENFILENAME sfn;
                                char szFileName[MAX_PATH] = ""; //definition of szFileName
    
                                ZeroMemory(&sfn, sizeof(sfn));
    
                                sfn.lStructSize = sizeof(sfn); // SEE NOTE BELOW
                                sfn.hwndOwner = hwnd;
                                sfn.lpstrFilter = "HTML Files (*.htm)\0*.htm\0Text Files(*.txt)\0*.txt\0RPGCode Files(*.prg)\0*.prg\0All Files (*.*)\0*.*\0";
                                sfn.lpstrFile = szFileName;
                                sfn.nMaxFile = MAX_PATH;
                                sfn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
                                sfn.lpstrDefExt = "html";
    
                                if(GetSaveFileName(&sfn))
                                {
                                           SaveTextFileFromEdit(hEdit, szFileName);
                                }
    
                    }
                    break;
                    case ID_FILE_OPEN:
                    {
                                OPENFILENAME ofn;
                                char szFileName[MAX_PATH] = ""; //definition of szFileName
    
                                ZeroMemory(&ofn, sizeof(ofn));
    
                                ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
                                ofn.hwndOwner = hwnd;
                                ofn.lpstrFilter = "HTML Files (*.htm)\0*.htm\0Text Files(*.txt)\0*.txt\0RPGCode Files(*.prg)\0*.prg\0All Files (*.*)\0*.*\0";
                                ofn.lpstrFile = szFileName;
                                ofn.nMaxFile = MAX_PATH;
                                ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
                                ofn.lpstrDefExt = "html";
    
                                if(GetOpenFileName(&ofn))
                                {
                                          LoadTextFileToEdit(hEdit, szFileName);
                                }     
                   }
                   break;
                   case ID_HELP_ABOUT:{
                                  DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
                                  }
                   break;
                   case ID_EDIT_PREVIEW:{
                                  ShellExecute(hwnd, "open", szFileName, NULL, NULL, SW_MAXIMIZE); //Shell Execute Command
                          }
    The Specifics:

    I want ShellExecute to open the file(If it's HTML in the Default Browser and nobody is dumb enough to preview a .txt file :P)

    The program opens ASCII files. Whoopee.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    What is in szFileName just before the ShellExecute call ? Your debugger should be able to help you with that one.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
                    case ID_FILE_OPEN:
                    {
                                OPENFILENAME ofn;
                                char szFileName[MAX_PATH] = ""; //
    This instance of szFileName is local to its block and unless you copy it somewhere it will be lost when the block ends (}).

    Possibly you want to use something like szTempFileName in this block and on success copy its contents to the global szFileName variable. You may already be doing this in your LoadTextFileToEdit/SaveTextFileToEdit functions.

    Code:
     if(GetOpenFileName(&ofn))
    lstrcpy(szFileName, szTempFileName);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  3. Replies: 3
    Last Post: 05-25-2005, 02:50 PM
  4. Changing text size in a program
    By RedTroja in forum C++ Programming
    Replies: 3
    Last Post: 10-12-2003, 04:53 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

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