#include "stdafx.h"
#include "../include/filedialog.h"
namespace xm{namespace ui{
UINT_PTR CALLBACK CxmFileDialog::OFNHookProc(HWND hdlg,UINT uiMsg,WPARAM wParam, LPARAM lParam)
{
if(uiMsg==WM_INITDIALOG){
/*
HWND hWnd=GetParent(hdlg);
HWND hWndParent=GetParent(hWnd);
RECT rcMain,rc;
::GetWindowRect(hWndParent,&rcMain);
::GetWindowRect(hWnd,&rc);
int x=rcMain.left+(rcMain.right-rcMain.left-(rc.right-rc.left))/2;
int y=rcMain.top+(rcMain.bottom-rcMain.top-(rc.bottom-rc.top))/2;
::SetWindowPos(hWnd,0,x,y,0,0,SWP_NOZORDER|SWP_NOSIZE);
*/
CWindow wnd=GetParent(hdlg);
wnd.CenterWindow(wnd.GetParent());
return TRUE;
}
return FALSE;
}
CxmFileDialog::CxmFileDialog(
BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
LPCTSTR lpszFilter,
LPCTSTR lpszTitle,
HWND hWndParent,
LPCTSTR lpszDefExt,
LPCTSTR lpszFileName,
DWORD dwFlags
)
{
memset(&m_ofn, 0, sizeof(m_ofn)); // initialize structure to 0/NULL
m_szFileName[0] = '\0';
m_szFileTitle[0] = '\0';
if(lpszTitle)
{
lstrcpy(m_szFileTitle,lpszTitle);
}
m_bOpenFileDialog = bOpenFileDialog;
m_ofn.lStructSize = sizeof(m_ofn);
// m_ofn.lStructSize = 88;
m_ofn.lpstrTitle = m_szFileTitle;//_T("ѡ��һ�������ļ�"); // Caption
m_ofn.hwndOwner = hWndParent;
m_ofn.lpstrFile = m_szFileName;
m_ofn.nMaxFile = MAX_PATH;
m_ofn.lpstrInitialDir = NULL;//_T("c:\\");
m_ofn.lpstrFilter = lpszFilter;
m_ofn.lpfnHook = (LPOFNHOOKPROC)OFNHookProc;
//m_ofn.nFilterIndex = 2;
m_ofn.Flags = dwFlags;//OFN_CREATEPROMPT | OFN_LONGNAMES |OFN_ENABLEHOOK|OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY ;//| OFN_OVERWRITEPROMPT|OFN_ENABLEHOOK|OFN_EXPLORER;//dwFlags;//
}
INT_PTR CxmFileDialog::DoModal(HWND hWndParent)
{
if(m_ofn.hwndOwner == NULL) // set only if not specified before
m_ofn.hwndOwner = hWndParent;
BOOL bRet;
if(m_bOpenFileDialog)
bRet = ::GetOpenFileName(&m_ofn);
else
bRet = ::GetSaveFileName(&m_ofn);
return bRet ? IDOK : IDCANCEL;
}
}}//namespace xm::ui