www.pudn.com > sancedit.rar > BrowseDlg.cpp
// BrowseDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MapGen.h"
#include "BrowseDlg.h"
#include "OgreFrameWork.h"
#include "ControlDialog.h"
#include ".\browsedlg.h"
//#ifdef _DEBUG
//#define new DEBUG_NEW
//#undef THIS_FILE
//static char THIS_FILE[] = __FILE__;
//#endif
/////////////////////////////////////////////////////////////////////////////
// CBrowseDlg dialog
CBrowseDlg* CBrowseDlg::m_Inst = NULL;
CBrowseDlg::CBrowseDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBrowseDlg::IDD, pParent)
{
m_Edit = NULL;
m_bInit = FALSE;
//{{AFX_DATA_INIT(CBrowseDlg)
//}}AFX_DATA_INIT
}
void CBrowseDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBrowseDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBrowseDlg, CDialog)
//{{AFX_MSG_MAP(CBrowseDlg)
ON_WM_SIZE()
ON_BN_CLICKED(IDC_PLACE, OnPlace)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchangedTree1)
//}}AFX_MSG_MAP
ON_STN_CLICKED(IDC_BROWSER_WND, OnStnClickedBrowserWnd)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBrowseDlg message handlers
void CBrowseDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if(!m_bInit)
return;
CRect TopHalf;
GetClientRect(TopHalf);
TopHalf.bottom = TopHalf.bottom / 2;
TopHalf.DeflateRect(5,5);
CRect BottomHalf;
GetClientRect(BottomHalf);
BottomHalf.top = BottomHalf.bottom / 2;
BottomHalf.DeflateRect(5,5);
m_Edit = (CTreeCtrl*)GetDlgItem(IDC_EDIT2);
// m_Edit->MoveWindow(TopHalf);
/*
//IDC_BOTTOM_FRAME
CRect BottomFrame;
CPoint Delta;
GetDlgItem(IDC_BOTTOM_FRAME)->GetWindowRect(BottomFrame);
CRect buttonrect;
GetDlgItem(IDC_DELETE)->GetWindowRect(buttonrect);
Delta.x = buttonrect.left - BottomFrame.left;
Delta.y = buttonrect.top - BottomFrame.top;
char str[128];
sprintf(str,"%d %d",Delta.x,Delta.y);
AfxMessageBox(str);
RECT rc;
GetDlgItem(IDC_DELETE)->GetClientRect(&rc);
//GetDlgItem(IDC_DELETE)->MoveWindow(Delta.x,Delta.y + BottomHalf.top,rc.right,rc.bottom);
// GetDlgItem(IDC_DELETE)->MoveWindow(0+Delta.x,BottomHalf.top+Delta.y,rc.right,rc.bottom);
*/
}
BOOL CBrowseDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_bInit = TRUE;
CRect sz;
GetClientRect(sz);
sz.DeflateRect(5,5);
FindMeshes(".\\Media\\");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBrowseDlg::OnOK()
{
// TODO: Add extra validation here
// CDialog::OnOK();
}
void CBrowseDlg::FindMeshes(char *directory)
{
CString szStartDir; // Local copy of szStart
BOOL bFound; // Whether or not a new file has been found
HANDLE hFile; // Handle to found file
WIN32_FIND_DATA stFindData; // Info about the found file
int i = 0;
// Append "*.*" to the end of the directory name passed in
CTreeCtrl *pTree = (CTreeCtrl*)GetDlgItem(IDC_TREE1);
szStartDir = directory;
szStartDir += CString("*.mesh");
// First, see if there's anything in the directory
hFile = FindFirstFile((LPCTSTR)szStartDir, &stFindData);
if (INVALID_HANDLE_VALUE == hFile)
{
//MessageBox("FindFirstFile() returned INVALID_HANDLE_VALUE", "DEBUG", MB_OK);
return;
}
// Next, loop through everything in the directory. If the found file
// is itself a directory, add it to the tree.
while (INVALID_HANDLE_VALUE != hFile)
{
if ((0 == strcmp(stFindData.cFileName, ".")) || (0 == strcmp(stFindData.cFileName, "..")) || (stFindData.cFileName[strlen(stFindData.cFileName)-1] == 'o'))
;
else {
if (stFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
;
else {
pTree->InsertItem(stFindData.cFileName);
i++;
}
}
bFound = FindNextFile(hFile, &stFindData);
if (!bFound)
break;
}
FindClose(hFile);
char str[128];
sprintf(str,"%d Meshes Found",i);
// AfxMessageBox(str);
}
void strip_file_extension(char *str) {
int i;
for (i = 0; i < strlen(str); i++) {
if (str[i] == '.') {
str[i] = 0;
return;
}
}
}
void CBrowseDlg::OnPlace()
{
// TODO: Add your control notification handler code here
CTreeCtrl *pTree = (CTreeCtrl*)GetDlgItem(IDC_TREE1);
HTREEITEM hItem = pTree->GetSelectedItem();
if (hItem == NULL)
{
AfxMessageBox("You must select the item to place");
return;
}
CString selectedStr = pTree->GetItemText(hItem);
// AfxMessageBox(selectedStr);
char SelectedMeshFile[128];
strcpy(SelectedMeshFile,(LPCTSTR)selectedStr);
char EntityName[128];
/* GetDlgItem(IDC_EDIT_ENTITY)->GetWindowText(EntityName,128);
if (strlen(EntityName) == 0) {
AfxMessageBox("You must supply a unique Entity Name");
return;
}*/
char NodeName[128];
GetDlgItem(IDC_EDIT_NODE)->GetWindowText(NodeName,128);
if (strlen(NodeName) == 0) {
AfxMessageBox("You must supply a unique Node Name");
return;
}
strcpy(EntityName,NodeName);
if (CControlDialog::GetInstance()->AddNode(SelectedMeshFile,EntityName,NodeName) == false)
{
AfxMessageBox("EntityName or NodeName is not Unique");
return;
}
//
// update the node edit box with an incremented instance
//
strcpy(NodeName,SelectedMeshFile);
strip_file_extension(NodeName);
strcat(NodeName,"_node");
CControlDialog::GetInstance()->incNodeInstance(NodeName);
GetDlgItem(IDC_EDIT_NODE)->SetWindowText(NodeName);
// cOgreFramework::GetInstance()->InitBrowserWindow(GetDlgItem(IDC_BROWSER_WND)->GetSafeHwnd());
}
void CBrowseDlg::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
CTreeCtrl *pTree = (CTreeCtrl*)GetDlgItem(IDC_TREE1);
HTREEITEM hItem = pTree->GetSelectedItem();
if (hItem == NULL)
{
AfxMessageBox("You must select the item to place");
return;
}
CString selectedStr = pTree->GetItemText(hItem);
char NodeName[128];
strcpy(NodeName,selectedStr);
strip_file_extension(NodeName);
strcat(NodeName,"_node");
CControlDialog::GetInstance()->incNodeInstance(NodeName);
GetDlgItem(IDC_EDIT_NODE)->SetWindowText(NodeName);
*pResult = 0;
}
HWND CBrowseDlg::GetBrowserWndHandle()
{
return GetDlgItem(IDC_BROWSER_WND)->GetSafeHwnd();
}
void CBrowseDlg::OnStnClickedBrowserWnd()
{
// TODO: 在此添加控件通知处理程序代码
}