📄 toolsdlg.cpp
字号:
// ToolsDlg.cpp : implementation file
//
#include "stdafx.h"
#include "45MapMaker.h"
#include "ToolsDlg.h"
#include "Mainfrm.h"
#include "45MapMakerView.h"
#include ".\toolsdlg.h"
#include "SetWallBlockDlg.h"
#include "MyWall.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CToolsDlg dialog
IMPLEMENT_DYNCREATE(CToolsDlg, CDialog)
CToolsDlg::CToolsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CToolsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CToolsDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_Pic = NULL;
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CToolsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CToolsDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_TREE2, m_FileTree);
DDX_Control(pDX, IDC_PICTURE, m_Picture);
}
void CToolsDlg::BrowseFile(int CallNum, CString strFile)
{
CMy45MapMakerApp* theApp = (CMy45MapMakerApp*)AfxGetApp();
CallNum++;
CFileFind ff;
CString szDir = strFile;
if(szDir.Right(1) != "\\")
szDir += "\\";
szDir += "*.*";
BOOL res = ff.FindFile(szDir);
while(res)
{
res = ff.FindNextFile();
if(ff.IsDirectory() && !ff.IsDots())
{
//如果是一个子目录,用递归继续往深一层找
CString strPath = ff.GetFilePath();
CString strTitle = ff.GetFileTitle();
int i =0;
switch(CallNum)
{
//目录只有1极
case 1:
strHTFir = m_FileTree.InsertItem(strTitle,0,1,NULL);
break;
default:
//strHtFif = m_FileTree.InsertItem(strTitle,3,0,strHtThi);
break;
}
BrowseFile(CallNum,strPath);
}
else if(!ff.IsDirectory() && !ff.IsDots())
{
//显示当前访问的文件
CString strPath;
CString strTitle;
strPath = ff.GetFilePath();
if(strPath.Find("bmp",0)!=-1)
{
strTitle = ff.GetFileTitle();
Imagemanger temp;//这里new出来的东西,在程序退出的时候delete
WallConfig temp1;
temp1.edit = false;//未被编辑
temp1.id=temp.filename = atoi(strTitle); //id号
temp1.offx = 0;
temp1.offy = 0;
temp1.centerx = 1;
temp1.centery = 1;
temp1.projectnumber = 0;
theApp->m_myWall.Insert(temp1);
CHAR* name =strPath.GetBuffer(strPath.GetLength());
if(FAILED(theApp->display->CreateSurfaceFromBitmap(&temp.image,name,DDSCAPS_OFFSCREENPLAIN|DDSCAPS_SYSTEMMEMORY)))
MessageBox("读取图片失败","Error",MB_OK);
else if(FAILED(temp.image->SetColorKey(RGB(255,0,255))))
MessageBox("关键色!");
if(strPath.Find("Box",0)!=-1)
{
theApp->Box.insert(temp);
}
else if(strPath.Find("Tile",0)!=-1)
{
theApp->Tile.insert(temp);
}
else if(strPath.Find("Wall",0)!=-1)
{
theApp->Wall.insert(temp);
}
else
{
MessageBox("STL 出错了,搞不懂","Error",MB_OK);
}
switch(CallNum)
{
case 2:
strHtEnd = m_FileTree.InsertItem(strTitle,3,2,strHTFir);
break;
default:
//strHtEnd = m_FileTree.InsertItem(strTitle,3,0,strHtFif);
break;
}
}
}
}
ff.Close();//关闭
}
BEGIN_MESSAGE_MAP(CToolsDlg, CDialog)
//{{AFX_MSG_MAP(CToolsDlg)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
// ON_WM_NCLBUTTONDBLCLK()
ON_NOTIFY(NM_DBLCLK, IDC_TREE2, OnNMDblclkTree2)
//ON_NOTIFY(NM_RCLICK, IDC_TREE2, OnNMRclickTree2)
ON_NOTIFY(NM_RCLICK, IDC_TREE2, OnNMRclickTree2)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CToolsDlg message handlers
BOOL CToolsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
m_iImageList.Create(16,16,ILC_COLOR16,0,0);
HICON hIcon = NULL;
HICON hIcon1 = NULL;
HICON hIcon2 = NULL;
HICON hIcon3 = NULL;
m_iImageList.SetBkColor(RGB(255,255,255));
hIcon = (HICON)::LoadImage(::AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, 0);
hIcon1 = (HICON)::LoadImage(::AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_ICON4), IMAGE_ICON, 16, 16, 0);
hIcon2 = (HICON)::LoadImage(::AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_ICON2), IMAGE_ICON, 16, 16, 0);
hIcon3 = (HICON)::LoadImage(::AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_ICON3), IMAGE_ICON, 16, 16, 0);
m_iImageList.Add(hIcon);
m_iImageList.Add(hIcon1);
m_iImageList.Add(hIcon2);
m_iImageList.Add(hIcon3);
m_FileTree.SetImageList ( &m_iImageList,TVSIL_NORMAL );
CMy45MapMakerApp* theApp = (CMy45MapMakerApp*)AfxGetApp();
theApp->m_myWall.LoadFile();//载入,载入
BrowseFile(0,"Image");//遍历"成绩表"文件夹内的所有目录
return TRUE; // return TRUE unless you set the focus to a control
}
void CToolsDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
if(m_Pic)
{
HDC hdc;
m_Pic->GetDDrawSurface()->GetDC(&hdc);
CDC *temp1=m_Picture.GetDC(); //得到dc
CRect dcRect;
m_Picture.GetClientRect(dcRect);//得到rect
int w1 = dcRect.Width();
int w2 = m_Pic->GetDDrawDesc().dwWidth;
int h1 = dcRect.Height();
int h2 = m_Pic->GetDDrawDesc().dwHeight;
//使用双缓存
HDC MemDC = ::CreateCompatibleDC(temp1->m_hDC);
HBITMAP MemBitmap = ::CreateCompatibleBitmap(temp1->m_hDC,w1,h1);
SelectObject(MemDC,MemBitmap);
//画在中间
if(w1>=w2&&h1>=h2)
::BitBlt(MemDC,(w1-w2)/2,(h1-h2)/2,w2,h2,hdc,0,0,SRCCOPY);
else
{
SetStretchBltMode (MemDC, COLORONCOLOR|STRETCH_DELETESCANS ) ;
if((w1/h1)>(w2/h2))//如果
{
::StretchBlt(MemDC,(w1-(w2*h1)/h2)/2,0,(w2*h1)/h2,h1,hdc,0,0,w2,h2,MERGECOPY);
}
else
{
::StretchBlt(MemDC,0,(h1-(h2*w1)/w2)/2,w1,(h2*w1)/w2,hdc,0,0,w2,h2,MERGECOPY);
}
}
::BitBlt(temp1->m_hDC,0,0,w1,h1,MemDC,0,0,SRCCOPY);
m_Pic->GetDDrawSurface()->ReleaseDC(hdc);//一定要释放阿
}
}
HCURSOR CToolsDlg::OnQueryDragIcon()
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
return (HCURSOR) m_hIcon;
}
void CToolsDlg::OnNMDblclkTree2(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: 在此添加控件通知处理程序代码
CMainFrame *pMain=(CMainFrame *)AfxGetApp()->m_pMainWnd;
CMy45MapMakerView *pView=(CMy45MapMakerView *)pMain->GetActiveView();
int send;
CMy45MapMakerApp* theApp = (CMy45MapMakerApp*)AfxGetApp();
m_hTreeItem = m_FileTree.GetSelectedItem();
CString s = m_FileTree.GetItemText(m_hTreeItem);
m_hTreeItemParent = m_FileTree.GetParentItem(m_hTreeItem);
if(m_hTreeItemParent == NULL)
return;
CString t = m_FileTree.GetItemText(m_hTreeItemParent);
m_Pic = theApp->GetCSurface(t,atoi(s));
if(m_Pic==NULL)
MessageBox("没有找到");
theApp->CurrentEdit = m_Pic; //改变当前的画刷
theApp->CurrentEditId = atoi(s);
if(t.Find("Tile",0)!=-1)
{
pView->OnEditfront();
send = 1;
}
else if(t.Find("Wall",0)!=-1)
{
WallConfig* temp = NULL;
theApp->m_myWall.find(theApp->CurrentEditId,temp);//寻找配置文件
if(!temp->edit)//如果未被编辑,就编辑她
{
SetWallBlockDlg dlg(theApp->CurrentEditId);
if(dlg.DoModal()==IDOK)
{
temp->edit = true;
temp->offx = dlg.calculateOffist().x;
temp->offy = dlg.calculateOffist().y;
temp->centerx = dlg.centerx;
temp->centery = dlg.centery;
temp->projectnumber = dlg.projectnum;
temp->project = dlg.vtProject;
//在这里需要添加投影代码,这里略过
}
else
{
MessageBox("你未编辑这个图块的属性,可以从新编辑");
}
}
pView->OnEditsecond();
send = 2;
}
else if(t.Find("Box",0)!=-1)
{
pView->OnEditblock();
send = 3;
}
else send = 0;
AfxGetApp()->m_pMainWnd->PostMessage(WM_BUSH_ID,send,theApp->CurrentEditId);
CRect rt;
m_Picture.GetClientRect(rt);
this->InvalidateRect(rt,1);
*pResult = 0;
}
void CToolsDlg::OnNMRclickTree2(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: 在此添加控件通知处理程序代码
CMy45MapMakerApp* theApp = (CMy45MapMakerApp*)AfxGetApp();
m_hTreeItem = m_FileTree.GetSelectedItem();//得到当前节点
CString s = m_FileTree.GetItemText(m_hTreeItem);//得到当前节点的字符串
m_hTreeItemParent = m_FileTree.GetParentItem(m_hTreeItem); //得到当前节点的父节点
if(m_hTreeItemParent == NULL) //如果父节点为NULL
return; //返回
CString t = m_FileTree.GetItemText(m_hTreeItemParent);//得到父节点的字符串
int Wallid = atoi(s);
if(t.Find("Wall",0)!=-1) //如果父节点为Wall
{
WallConfig* temp = NULL;
theApp->m_myWall.find(Wallid,temp);//寻找配置文件
SetWallBlockDlg dlg(Wallid,temp);
if(dlg.DoModal()==IDOK)
{
temp->edit = true;
temp->offx = dlg.calculateOffist().x;
temp->offy = dlg.calculateOffist().y;
temp->centerx = dlg.centerx;
temp->centery = dlg.centery;
temp->projectnumber = dlg.projectnum;
temp->project = dlg.vtProject;
//在这里需要添加投影代码,这里略过
}
}
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -