📄 watchbar.cpp
字号:
// CWatchBar : implementation file
/////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "Resource.h"
#include "WatchBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const UINT FTS_XT_BOTTOM = 0x0001;
// Show back and next arrows.
const UINT FTS_XT_HASARROWS = 0x0002;
// Show home and end arrows. Used with FTS_XT_HASARROWS.
const UINT FTS_XT_HASHOMEEND = 0x0004;
// Show tooltips.
const UINT FTS_XT_TOOLTIPS = 0x0008;
// Same as FTS_XT_BOTTOM | FTS_XT_HASARROWS | FTS_XT_HASHOMEEND | FTS_XT_TOOLTIPS.
const UINT FTS_XT_DEFAULT = 0x000F;
// Show a horizontal scroll bar.
const UINT FTS_XT_HSCROLL = 0x0010;
// All FTS_ mask items.
const UINT FTS_XT_MASK = 0x001F;
/////////////////////////////////////////////////////////////////////////////
// CWatchBar
CWatchBar::CWatchBar()
{
NONCLIENTMETRICS ncm;
memset(&ncm, 0, sizeof(NONCLIENTMETRICS));
ncm.cbSize = sizeof(NONCLIENTMETRICS);
VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0));
_tcscpy( ncm.lfMessageFont.lfFaceName, _T("Courier"));
// m_Font.CreateFontIndirect(&ncm.lfMessageFont);
m_Font.CreateFont(10,10,0,0,0,0,0,0,
DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, FIXED_PITCH,"Courier");
}
CWatchBar::~CWatchBar()
{
// TODO: add destruction code here.
}
IMPLEMENT_DYNAMIC(CWatchBar, CCJControlBar)
BEGIN_MESSAGE_MAP(CWatchBar, CCJControlBar)
//{{AFX_MSG_MAP(CWatchBar)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWatchBar message handlers
int CWatchBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CCJControlBar::OnCreate(lpCreateStruct) == -1)
return -1;
/* if (!m_FlatTabCtrl.Create(NULL, "", WS_VISIBLE | WS_CHILD | FTS_HASARROWS | FTS_BOTTOM,
CRect(10,10,200,25), this, IDC_FLATTABCTRL))
{
TRACE0(_T("Unable to create flat tab control bar\n"));
return -1;
}
int nItemCount = sizeof(strTabs)/sizeof(strTabs[0]);
for( int iItem = 0; iItem < nItemCount; ++iItem)
{
m_FlatTabCtrl.InsertItem(iItem, strTabs[iItem]);
}
*/
DWORD dwStyle = WS_CHILD | LVS_REPORT | LVS_NOSORTHEADER |
WS_VSCROLL | WS_TABSTOP|LVS_SHOWSELALWAYS;
if (!m_viarable.Create (WS_TABSTOP|WS_CHILD|WS_VISIBLE|LVS_REPORT|
LVS_SHOWSELALWAYS,
CRect(0,0,0,0), this, IDC_VIARABLE))
{
TRACE0("Failed to create view for CMyBarLeft\n");
return -1;
}
SetChild(&m_viarable);
m_viarable.ModifyStyleEx(0, WS_EX_STATICEDGE);
m_viarable.InsertColumn(0, "Viarable name", LVCFMT_LEFT, 150);
m_viarable.InsertColumn(1, "value", LVCFMT_LEFT, 150);
// m_viarable.InsertColumn(2, "地物颜色", LVCFMT_LEFT, 120);
ListView_SetExtendedListViewStyle(m_viarable.m_hWnd, LVS_EX_GRIDLINES);
m_viarable.SetFont(&m_Font);
m_viarable.GetDlgItem(0)->SetFont(&m_Font);
#undef RAND_MAX
#define RAND_MAX 255
CString strName, strIndex;
for(int i=0; i<1; i++)
{
strIndex.Format("%d", i+1);
strName.Format("Class%d", i+1);
strName=_T(" ");
m_viarable.InsertItem( i, strName);
// m_viarable.SetItemText(i, 1, strIndex);
// m_viarable.SetItemText(i, 1, strIndex);
// m_viarable.InsertItem( i, strIndex);
// m_viarable.InsertItem( i, strIndex);
}
m_viarable.SetHotItem(0);
int n_count=m_viarable.GetItemCount();
CString str_new=_T(" ");
m_viarable.InsertItem(n_count,str_new);
m_viarable.SetItemText(0,0,"PC");
m_viarable.SetItemText(0,1,"0");
#undef RAND_MAX
#define RAND_MAX 0x7fff
/* int nListCount = sizeof(m_WatchList)/sizeof(m_WatchList[0]);
for( int iList = 0; iList < nListCount; ++iList)
{
if (!m_WatchList[iList].Create( dwStyle, CRect(0,0,0,0), this,
IDC_SHEET1+iList ))
{
TRACE(_T("Failed to create Watch window.\n"));
return -1;
}
*/
/*
LV_COLUMN lvColumn; //列表的结构类型 lvColumn.mask=LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|WS_CHILD|WS_BORDER|WS_GROUP|LVS_REPORT|LVS_EDITLABELS;
lvColumn.fmt=LVCFMT_CENTER;
lvColumn.cx=75;
lvColumn.iSubItem=0;
lvColumn.pszText="Column 0";
m_WatchList[iList].InsertColumn(0,&lvColumn);
lvColumn.iSubItem=1;
lvColumn.pszText="Column 1";
m_WatchList[iList].InsertColumn(1,&lvColumn);
lvColumn.iSubItem=2;
lvColumn.pszText="Column 2";
*/
// m_WatchList[iList].InsertColumn(0, _T("Name"), LVCFMT_LEFT, 125);
//. m_WatchList[iList].InsertColumn(1, _T("Value"), LVCFMT_LEFT, 355);
// ListView_SetExtendedListViewStyle(m_WatchList[iList].m_hWnd, LVS_EX_GRIDLINES);
// m_WatchList[iList].SetFont(&m_Font);
// m_WatchList[iList].GetDlgItem(0)->SetFont(&m_Font);
// m_WatchList[iList].SetFont( &m_Font );
// }
//m_WatchList[0].AddString("liu");
// m_WatchList[0].InsertColumn(2, _T("liming"), LVCFMT_LEFT, 125);
// int nListCount = sizeof(m_WatchList)/sizeof(m_WatchList[0]);
// for( int nList = 0; nList < nListCount; ++nList)
// {
// CreateTabListCtrl(m_WatchList[nList], IDC_SHEET1+nList );
// }
// m_WatchList[0].InsertColumn(0, _T("Name"), LVCFMT_LEFT, 125);
// m_WatchList[0].InsertColumn(1, _T("Value"), LVCFMT_LEFT, 355);
// ListView_SetExtendedListViewStyle(m_WatchList[0].m_hWnd, LVS_EX_GRIDLINES);
// m_WatchList[0].SetFont(&m_Font);
// m_WatchList[0].GetDlgItem(0)->SetFont(&m_Font);
/*
int nBuildCount = sizeof(strBuild)/sizeof(strBuild[0]);
for( int i = 0; i < nBuildCount; ++i)
{
m_WatchList[0].AddString(strBuild[i]);
}
int nDebugCount = sizeof(strDebug)/sizeof(strDebug[0]);
for( i = 0; i < nDebugCount; ++i)
{
m_WatchList[1].AddString(strDebug[i]);
}
*/
// m_FlatTabCtrl.SetCurSel(1);
// SelectTabView(1);
return 0;
}
BOOL CWatchBar::CreateTabListCtrl(CListCtrl& listCtrl, UINT nID)
{
// Define the default style for the output list controls.
DWORD dwStyle = WS_CHILD | LVS_REPORT | LVS_NOSORTHEADER |
WS_VSCROLL | WS_TABSTOP|LVS_SHOWSELALWAYS;
if (!listCtrl.Create( dwStyle, CRect(0,0,0,0), &m_FlatTabCtrl,
nID ))
{
TRACE(_T("Failed to create Watch window.\n"));
return -1;
}
listCtrl.InsertColumn(0, _T("Name"), LVCFMT_LEFT, 125);
listCtrl.InsertColumn(1, _T("Value"), LVCFMT_LEFT, 155);
ListView_SetExtendedListViewStyle(listCtrl.m_hWnd, LVS_EX_GRIDLINES);
listCtrl.SetFont(&m_Font);
listCtrl.GetDlgItem(0)->SetFont(&m_Font);
int n_count=listCtrl.GetItemCount();
CString str_new=_T(" ");
listCtrl.InsertItem(n_count,str_new);
listCtrl.SetItemText(0,0,"PC");
listCtrl.SetItemText(0,1,"0");
return TRUE;
}
BOOL CWatchBar::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
/* if(wParam==1072)
{
m_FlatTabCtrl.SetCurSel(0);
SelectTabView(0);
}*/
if(IDC_FLATTAB == (UINT)wParam)
{
NMHDR* pNMHDR = (NMHDR*)lParam;
switch(pNMHDR->code)
{
case TCN_SELCHANGING:
break;
case TCN_SELCHANGE:
SelectTabView(m_FlatTabCtrl.GetCurSel());
break;
}
}
return CCJControlBar::OnNotify(wParam, lParam, pResult);
}
void CWatchBar::SelectTabView(int nTab)
{
int nListCount = sizeof(m_WatchList)/sizeof(m_WatchList[0]);
for( int iList = 0; iList < nListCount; ++iList) {
m_WatchList[iList].ShowWindow(SW_HIDE);
}
m_WatchList[nTab].ShowWindow(SW_SHOW);
}
void CWatchBar::OnSize(UINT nType, int cx, int cy)
{
CCJControlBar::OnSize(nType, cx, cy);
if(m_FlatTabCtrl.GetSafeHwnd())
{
CRect rc;
GetChildRect(rc);
rc.DeflateRect(1,1);
int nListCount = sizeof(m_WatchList)/sizeof(m_WatchList[0]);
for( int iList = 0; iList < nListCount; ++iList) {
m_WatchList[iList].MoveWindow(rc.left, rc.top,
rc.Width(), rc.bottom-(IsFloating()?18:19));
}
m_FlatTabCtrl.MoveWindow(rc.left, rc.bottom-15, rc.Width(), 15);
}
}
void CWatchBar::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rc;
m_iAuxImage = (UINT)-1;
GetClientRect(&rc);
CRect rect;
GetChildRect(rect);
DrawBorders(&dc,rc);
dc.Draw3dRect(rect, ::GetSysColor(COLOR_3DDKSHADOW),
::GetSysColor(COLOR_3DDKSHADOW));
}
void CWatchBar::UpDateSearch1()
{
/*
m_WatchList[2].ResetContent();
SearchInf * m_pfinditem;
m_pfinditem =new SearchInf;
int n_linecount=a_searchinfo.GetSize();
CString str_addstring="";
CString str_line;
str_addstring="Searching for '"+findstring+"'..." ;
m_WatchList[2].AddString(str_addstring);
for( int i = 0; i <n_linecount; ++i)
{
m_pfinditem=(SearchInf * )a_searchinfo.GetAt(i);
// int n_line=m_pfinditem->n_lineno;
// str_line.Format("%d",n_line);
// 先获得当前工作目录的全路径
// 再获得文件的完整的路径名(包含文件的名称)
//strcat(str_addstring,"\\");
//strcat(str_addstring,m_pfinditem->str_filenm);
// str_addstring=str_addstring
// +"("+str_line+")"+":";
str_addstring=m_pfinditem->str_linetext;
// CString str_string=str_addstring+str_test;
m_WatchList[2].AddString(str_addstring);
}
str_line.Format("%d",n_linecount);
str_addstring=str_line+" occurrence(s) have been found.";
m_WatchList[2].AddString(str_addstring);
m_FlatTabCtrl.SetCurSel(2);
SelectTabView(2);
*/
/*
LPRECT lpRect1=NULL;
CRect lpRect2;
lpRect1=new tagRECT;
lpRect1->left=0;
lpRect1->right=0;
lpRect1->bottom=0;
lpRect1->top=0;
this->GetChildRect(lpRect2);
m_FlatTabCtrl.GetItemRect(2, lpRect1);
CPoint point;
point.x=lpRect1->left+lpRect2.left+2;
point.y=lpRect1->top+2+lpRect2.top;
UINT nFlags=MK_LBUTTON;
CMainFrame *m_pmainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
m_FlatTabCtrl.OnLButtonDown(nFlags, point);
*/
}
void CWatchBar::UpDatePC(int i_pc)
{
CString str_pc=_T("");
str_pc.Format("%d",i_pc);
m_viarable.SetItemText(0,1,str_pc);
}
void CWatchBar::UpDateVar(int i_sel,CString str_var)
{
// int n_count=m_viarable.GetItemCount();
m_viarable.SetItemText(i_sel,1,str_var);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -