0

私はメモ帳プログラムを書いており、名前を付けて保存機能を実装しています(保存ダイアログボックスなど)。保存のみする方法(ファイルが既に存在する場合は保存ダイアログボックスを表示しない)を探してみましたが、何も見つかりませんでした。どうすればいいですか?saveas 機能のコードは次のとおりです。

case ID_FILE_SAVEAS:
            {
                OPENFILENAME ofn;
                char szFileName[ MAX_PATH ] = "";
                ZeroMemory( &ofn, sizeof( ofn ) );

                ofn.lStructSize = sizeof( ofn );
                ofn.hwndOwner   = hwnd;
                ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
                ofn.lpstrFile   = szFileName;
                ofn.nMaxFile    = MAX_PATH;
                ofn.lpstrDefExt = "txt";
                ofn.Flags       = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;

                if( GetSaveFileName( &ofn ) )
                {
                    // DO FUN STUFF
                }
            }
            break;
4

1 に答える 1

0
// Prerequisite: You need to keep track of the filename that you have loaded...

case ID_FILE_SAVE:
    {
    if (... there is already a filename loaded ...)
        {
        // open the filename that is being tracked...
        // write data to the file as needed...
        // close the file...

        break;
        }

    // there is no file loaded yet so fall through to the next case...
    }

case ID_FILE_SAVEAS:
    {
    OPENFILENAME ofn = {0};
    char szFileName[ MAX_PATH ] = "";

    ofn.lStructSize = sizeof( ofn );
    ofn.hwndOwner   = hwnd;
    ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
    ofn.lpstrFile   = szFileName;
    ofn.nMaxFile    = MAX_PATH;
    ofn.lpstrDefExt = "txt";
    ofn.Flags       = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;

    if( GetSaveFileName( &ofn ) )
        {
        // open the selected filename...
        // write data to the file as needed...
        // close the file...

        // track the selected filename for later use in ID_FILE_SAVE...
        }

    break;
    }
于 2013-10-28T23:42:57.703 に答える