📄 textshowview.cpp
字号:
// textshowView.cpp : implementation file
//
#include "stdafx.h"
#include "bpnlayerexe.h"
#include "textshowView.h"
#include "BpNlayerEXEDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// textshowView
IMPLEMENT_DYNCREATE(textshowView, CTreeView)
textshowView::textshowView()
{
}
textshowView::~textshowView()
{
}
BEGIN_MESSAGE_MAP(textshowView, CTreeView)
//{{AFX_MSG_MAP(textshowView)
ON_NOTIFY_REFLECT(TVN_BEGINLABELEDIT, OnBeginlabeledit)
ON_NOTIFY_REFLECT(TVN_ENDLABELEDIT, OnEndlabeledit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// textshowView drawing
void textshowView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// textshowView diagnostics
#ifdef _DEBUG
void textshowView::AssertValid() const
{
CTreeView::AssertValid();
}
void textshowView::Dump(CDumpContext& dc) const
{
CTreeView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// textshowView message handlers
void textshowView::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
HICON hIcon[4];
m_imageList.Create(32,32,0,3,3);
hIcon[0]=AfxGetApp()->LoadIcon(IDI_NNET);
hIcon[1]=AfxGetApp()->LoadIcon(IDI_NLAYER);
hIcon[2]=AfxGetApp()->LoadIcon(IDI_NCELL);
hIcon[3]=AfxGetApp()->LoadIcon(IDI_NW);
for(int i=0;i<4;i++)
{
m_imageList.Add(hIcon[i]);
}
GetTreeCtrl().SetImageList(&m_imageList,TVSIL_NORMAL);
GetTreeCtrl().SetIndent(20);
}
void textshowView::SetTreeView()
{
SetWindowLong(GetTreeCtrl().m_hWnd,GWL_STYLE,TVS_EDITLABELS|TVS_HASBUTTONS|TVS_HASLINES|GetWindowLong(GetTreeCtrl().m_hWnd,GWL_STYLE));
GetTreeCtrl().DeleteAllItems();
CBpNlayerEXEDoc *pDoc=CBpNlayerEXEDoc::GetDoc();
char str[20];
HTREEITEM hTemp1,hTemp2,hTemp3,hTemp4;
TV_INSERTSTRUCT tvinsert;
tvinsert.hInsertAfter=TVI_LAST;
tvinsert.item.mask=TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_TEXT;
tvinsert.item.cchTextMax=6;
tvinsert.item.cChildren=1;
tvinsert.item.lParam=0;
//top level
tvinsert.hParent=NULL;
tvinsert.item.pszText="神经网络";
tvinsert.item.iImage=0;
tvinsert.item.iSelectedImage=0;
hTemp1=GetTreeCtrl().InsertItem(&tvinsert);
for (int i=0;i<pDoc->m_iLayerNum;i++)
{
tvinsert.hParent=hTemp1;
sprintf(str,"层%d",i+1);
tvinsert.item.pszText=str;
tvinsert.item.iImage=1;
tvinsert.item.iSelectedImage=1;
hTemp2=GetTreeCtrl().InsertItem(&tvinsert);
for (int j=0;j<*(pDoc->m_piLayerCapture+i);j++)
{
tvinsert.hParent=hTemp2;
sprintf(str,"第%d个神经元",j+1);
tvinsert.item.pszText=str;
tvinsert.item.iImage=2;
tvinsert.item.iSelectedImage=2;
hTemp3=GetTreeCtrl().InsertItem(&tvinsert);
if (0!=i)
{
for (int k=0;k<*(pDoc->m_piLayerCapture+i-1);k++)
{
//tvinsert.item.lParam=(long)pDoc;
tvinsert.hParent=hTemp3;
sprintf(str,"第%d个权值:%f",k+1,pDoc->m_pBPNet->GetNeuronWeight(i,j,k));
tvinsert.item.pszText=str;
tvinsert.item.iImage=3;
tvinsert.item.iSelectedImage=3;
hTemp4=GetTreeCtrl().InsertItem(&tvinsert);
}
}
}
}
}
void textshowView::OnBeginlabeledit(NMHDR* pNMHDR, LRESULT* pResult)
{
TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
// TODO: Add your control notification handler code here
//GetTreeCtrl().GetEditControl()->SetLimitText(3);
//GetTreeCtrl().SetItemText(pTVDispInfo->item.hItem,pTVDispInfo->item.pszText);
if ((!GetTreeCtrl().ItemHasChildren(pTVDispInfo->item.hItem))
&&(GetTreeCtrl().GetParentItem(GetTreeCtrl().GetParentItem(pTVDispInfo->item.hItem))!=GetTreeCtrl().GetRootItem()))
{
GetTreeCtrl().GetEditControl()->SetWindowText("");
*pResult=0;
}
else
/*SetWindowLong(GetTreeCtrl().GetEditControl()->m_hWnd,GWL_STYLE
,GetWindowLong(GetTreeCtrl().GetEditControl()->m_hWnd,GWL_STYLE)|ES_NUMBER);*/
{
*pResult=1;
}
}
void textshowView::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult)
{
TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
// TODO: Add your control notification handler code here
CString str;
HTREEITEM hTemp;
int iLayerTh,iNuecellTh,iWTh;
CBpNlayerEXEDoc *pDoc=CBpNlayerEXEDoc::GetDoc();
iLayerTh=-1;
iNuecellTh=-1;
iWTh=-1;
str=pTVDispInfo->item.pszText;
if (IsFloat(str))
{
//////////////////////////////////////////////////////////////////////////
hTemp=pTVDispInfo->item.hItem;
while (hTemp!=NULL)
{
hTemp=GetTreeCtrl().GetPrevSiblingItem(hTemp);
iWTh+=1;
}
hTemp=pTVDispInfo->item.hItem;
hTemp=GetTreeCtrl().GetParentItem(hTemp);
while (hTemp!=NULL)
{
hTemp=GetTreeCtrl().GetPrevSiblingItem(hTemp);
iNuecellTh+=1;
}
hTemp=pTVDispInfo->item.hItem;
hTemp=GetTreeCtrl().GetParentItem(hTemp);
hTemp=GetTreeCtrl().GetParentItem(hTemp);
while (hTemp!=NULL)
{
hTemp=GetTreeCtrl().GetPrevSiblingItem(hTemp);
iLayerTh+=1;
}
pDoc->m_pBPNet->SetNeuronWeight(iLayerTh,iNuecellTh,iWTh,atof(str));
//////////////////////////////////////////////////////////////////////////
char *buffer;
buffer=new char[str.GetLength()+1];
memcpy(buffer,str.GetBuffer(1),str.GetLength());
buffer[str.GetLength()+1]=NULL;
str.ReleaseBuffer();
str.Format("第%d个权值:%s",iWTh+1,buffer);
GetTreeCtrl().SetItemText(pTVDispInfo->item.hItem,str);
}
*pResult = 0;
}
BOOL textshowView::IsFloat(CString str)
{
if (str.GetLength()==0)
{
return FALSE;
}
BOOL bOneDot=TRUE;
for(int i=0;i<str.GetLength();i++)
{
if((str[i]<'0'||str[i]>'9')&&(str[i]!='.'?TRUE:(bOneDot?(bOneDot=FALSE,FALSE):TRUE))&&((str[i]!='-')||(0!=i)))
return FALSE;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -