Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

Common dialog controls using ATL

hi i have to use common dialog control using atl.
i used my code as below,
i got error as interface ICommonDialog not found.
is there any better way,
thanks in advance
What is the header file i have to use

#import "c:\winnt\system32\comdlg32.ocx"

CComPtr<ICommonDialog> sp_CmnDlg;

CoCreateInstance(__uuidof(CCommonDialog), ..., ...

sp_CmnDlg->ShowOpen();

ravi.
0
ravikirang
Asked:
ravikirang
  • 2
1 Solution
 
Roshan DavisCommented:
If u need an Open File Common Dialog, u can do this

          OPENFILENAME ofn;
            TCHAR  szFile[5000] = "\0";
          strcpy(szFile, "");

          memset(&ofn, 0, sizeof (ofn));
          ofn.lpstrFile          = szFile;
          ofn.lStructSize          = sizeof(OPENFILENAME);
          ofn.hwndOwner          = NULL;
          ofn.nMaxFile          = 5000;
          ofn.lpstrFilter          = "Text Files (*.txt)\0*.txt\0Document Files (*.doc)\0*.doc\0All Files (*.*)\0*.*\0\0";
          ofn.lpstrTitle          = "Open a File";
        ofn.Flags               = OFN_EXPLORER|OFN_PATHMUSTEXIST|OFN_ENABLEHOOK|OFN_ALLOWMULTISELECT|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
          ofn.lpstrDefExt         = "txt";
          //ofn.lpfnHook          = (LPOFNHOOKPROC)OFNHookProc1;
          ofn.lpfnHook          = NULL;

        if(GetOpenFileName(&ofn))
          {
               if(NULL != ofn.lpstrFile)
               {
                    // to do
               }
          }


GOOD LUCK
0
 
ravikirangAuthor Commented:
thanks mr ramson, it worked for me. could u tell me changes for save dialog box.
0
 
Roshan DavisCommented:
For that u can use GetSaveFileName API

GOOD LUCK
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now