class CMainFrame :

        public CFrameWindowImpl<CMainFrame>,

        public CUpdateUI<CMainFrame>,

        public CMessageFilter, public CIdleHandler

{

public:

 

DECLARE_FRAME_WND_CLASS(NULL, IDR_MAINFRAME)

 

BEGIN_MSG_MAP(CMainFrame)

 

        MESSAGE_HANDLER    ( WM_CREATE        , OnCreate       )

        MESSAGE_HANDLER    ( WM_DESTROY       , OnDestroy      )

        MESSAGE_HANDLER    ( WM_DROPFILES     , OnDropFile     )

        COMMAND_ID_HANDLER ( ID_SELECTFOLDER  , OnSelectFolder )

        COMMAND_ID_HANDLER ( ID_FILE_OPEN     , OnFileOpen     )

        COMMAND_ID_HANDLER ( ID_FILE_SAVE     , OnFileSave     )

        ...

END_MSG_MAP()

 

LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)

{

        ...

        DragAcceptFiles (TRUE);

 

        return 0;

}

 

LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)

{

        DragAcceptFiles (FALSE);

        ...

}

 

LRESULT OnDropFile (UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)

{

        HDROP  hDrop = (HDROP) wParam;    

 

        TCHAR filePath [MAX_PATH];

        int   fileCount;

        int   index;

 

        fileCount = DragQueryFile (hDrop, -1, NULL, NULL);

        if (fileCount > 0)

        {

               for (index=0; index<fileCount; index++)

               {

                       if (DragQueryFile (hDrop, index, filePath, sizeof(filePath)))

                       {

                              ATLTRACE (_T("OnDropFile(): %s \r\n"), filePath);

                       }

               }

        }

 

        DragFinish(hDrop);

 

        return 0;

}

 

LRESULT OnSelectFolder (WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)

{

        BROWSEINFO   bi = { 0 };

        LPITEMIDLIST pidl;

        TCHAR        path[MAX_PATH] = { 0 };

 

        ZeroMemory (&bi,sizeof(BROWSEINFO));

 

        bi.ulFlags        = 0;

        bi.lpszTitle      = NULL;

        bi.pszDisplayName = path;

        pidl              = SHBrowseForFolder ( &bi );

 

        if ( pidl != 0 )

        {

               if (SHGetPathFromIDList (pidl, path))

               {

                       ATLTRACE (_T("OnSelectFolder(): %s \r\n"), path);

               }

 

               // free memory used

               IMalloc * imalloc = 0;

               if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )

               {

                       imalloc->Free ( pidl );

                       imalloc->Release ( );

               }

        }

 

        return 0;

}

 

LRESULT OnFileSave(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)

{

        CFileDialog FileOpenDilaog

        (

               FALSE,

               _T("bin"),

               _T("default.bin"),         

               OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,

               _T("Binary Files (*.bin)\0*.bin\0All Files (*.*)\0*.*\0"),

               m_hWnd

        );

 

 

        if (FileOpenDilaog.DoModal() == IDOK)

        {

               ATLTRACE (_T("OnFileSave(): %s \r\n"), FileOpenDilaog.m_szFileName);

        }

 

        return 0;

}

 

LRESULT OnFileOpen(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)

{

        CFileDialog FileOpenDilaog

        (

                TRUE,

               _T("bin"),

               NULL,

               OFN_HIDEREADONLY,

               _T("Binary Files (*.bin)\0*.bin\0All Files (*.*)\0*.*\0"),

               m_hWnd

        );

 

        if (FileOpenDilaog.DoModal() == IDOK)

        {

               ATLTRACE (_T("OnFileOpen(): %s \r\n"), FileOpenDilaog.m_szFileName);

        }

 

        return 0;

}

 

};

 

Posted by 셈말짓기 :