首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

使用GetOpenFileName()时遇到的有关问题!

2012-03-24 
使用GetOpenFileName()时遇到的问题!!在线等我在使用GetOpenFileName()后,我定义的部分变量值也改变了!!!!

使用GetOpenFileName()时遇到的问题!! 在线等
我在使用GetOpenFileName()后,我定义的部分变量值也改变了!!!!

具体的,我是在类内部这样定义一个打开/保存对话框:

BOOL   CMapEditor::OpenSaveDialog(   int   dwFlag   )
{
        //   设置OPENFILENAME结构
        OPENFILENAME   ofn   ;//
        ZeroMemory(&ofn,   sizeof(ofn));

        static   const   TCHAR   szFilter[]   =  
TEXT( "Map   Files   (.txt)\0*.txt;\0 ")TEXT( "All   Files   (*.*)\0*.*;\0 ");
        ofn.lStructSize                   =   sizeof(OPENFILENAME);
        ofn.hwndOwner                       =   m_pApp-> GetWindow();
        ofn.hInstance                       =   NULL;
        ofn.lpstrFilter                   =   szFilter;
        ofn.nFilterIndex                 =   1;
        ofn.lpstrCustomFilter       =   NULL;
        ofn.nMaxCustFilter             =   0;
        ofn.lpstrFile                       =   m_MapFileName;
        ofn.nMaxFile                         =   MAX_PATH;
        ofn.lpstrFileTitle             =   NULL;
        ofn.nMaxFileTitle               =   0;
        ofn.lpstrInitialDir           =   NULL;
        if(   dwFlag   ==   0   )//打开文件编辑
                ofn.lpstrTitle             =   TEXT( "选择一个场景文件... ");
        else//保存文件
                ofn.lpstrTitle             =   TEXT( "保存为指定的文件... ");
        ofn.Flags                               =   OFN_HIDEREADONLY;
        ofn.nFileOffset                   =   0;
        ofn.nFileExtension             =   0;
        ofn.lpstrDefExt                   =   TEXT( "txt ");
        ofn.lCustData                       =   0L;
        ofn.lpfnHook                         =   NULL;
        ofn.lpTemplateName             =   NULL;


        //我单步执行发现
        //在这之前都还好好的..........................

       
        if(   dwFlag   ==   0   )//打开文件编辑


                return   GetOpenFileName(   &ofn   );
        else   //保存文件
                return   GetSaveFileName(   &ofn   );

        //执行过上面后类内变量的值就改变了!!!
}


这是我第二次在一个工程中使用这个函数,我第一次用时都很正常

请问这是为什么啊

[解决办法]
//执行过上面后类内变量的值就改变了!!!
ofn变了?

Syntax

BOOL GetOpenFileName( LPOPENFILENAME lpofn
);
Parameters

lpofn
[in, out] Pointer to an OPENFILENAME structure that contains information used to initialize the dialog box. When GetOpenFileName returns, this structure contains information about the user 's file selection.

参数即是in又是out,改变了很正常
[解决办法]
lpofn
[in, out] Pointer to an OPENFILENAME structure that contains information used to initialize the dialog box.

注意这句:
When GetOpenFileName returns, this structure contains information about the user 's file selection.

热点排行