BOOL CDlgGLDlg::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
BOOL CDlgDbgDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // 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
// TODO: Add extra initialization here // View size CRect clientRect; GetClientRect(&clientRect); // afxDump << clientRect << "\n"; // Creation 'on the fly' of the new view CView* pNewView; pNewView = new CFunctionView; // Creation of the view window afxTraceEnabled=FALSE; if(! pNewView->Create(NULL, NULL, WS_VISIBLE | WS_CHILD, clientRect, this, 1000)) { TRACE( "Failed view creation\n" ); } afxTraceEnabled=TRUE; pNewView->OnInitialUpdate();// return TRUE; // return TRUE unless you set the focus to a control }没有另一个EditCtrl, CEditView 自己有,你把 edit 的内容放 void CFunctionView::OnInitialUpdate() { CEditView::OnInitialUpdate();
请帮我看一下,我不知道怎么把这两个功能放到一起。
这个是CFunctionView类的代码
// FunctionView.cpp : 实现文件
//#include "stdafx.h"
#include "jiqiren.h"
#include "FunctionView.h"
#include "MainFrm.h"// CFunctionViewIMPLEMENT_DYNCREATE(CFunctionView, CEditView)CFunctionView::CFunctionView()
{}CFunctionView::~CFunctionView()
{
}BEGIN_MESSAGE_MAP(CFunctionView, CEditView)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_KEYDOWN()
ON_CONTROL_REFLECT(EN_CHANGE,OnChange)
END_MESSAGE_MAP()
// CFunctionView 诊断#ifdef _DEBUG
void CFunctionView::AssertValid() const
{
CEditView::AssertValid();
}#ifndef _WIN32_WCE
void CFunctionView::Dump(CDumpContext& dc) const
{
CEditView::Dump(dc);
}
#endif
#endif //_DEBUG
// CDebugWin 消息处理程序
void CFunctionView::OnPaint()
{
CEditView::OnPaint();
PaintLeft();
}
void CFunctionView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值 CEditView::OnLButtonDown(nFlags, point);
m_ldown = TRUE;
PaintLeft();
}
void CFunctionView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值 CEditView::OnLButtonUp(nFlags, point);
m_ldown = FALSE;
if(point.x < m_LineHeight+6)
{
point.x += 20;
CEdit& theEdit = GetEditCtrl ();
int n = theEdit.CharFromPos(point);
AddRemoveBP(HIWORD(n)+1);
}
PaintLeft();
}
void CFunctionView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值 CEditView::OnMouseMove(nFlags, point);
if(m_ldown == TRUE)
PaintLeft();
}
void CFunctionView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值 CEditView::OnKeyDown(nChar, nRepCnt, nFlags);
PaintLeft();
}
void CFunctionView::OnInitialUpdate()
{
CEditView::OnInitialUpdate(); // TODO: 在此添加专用代码和/或调用基类
SIZE size;
GetTextExtentPoint(GetDC()->GetSafeHdc (),"A",1,&size);
m_LineHeight = size.cy; //得到行的高度 CEdit& theEdit = GetEditCtrl ();
theEdit.SetMargins (m_LineHeight+31,0); //设置编辑框的左边界
theEdit.SetLimitText(10 * 1024); //设置输入的最大文本
m_ldown = FALSE;
}//画左边的显示条
void CFunctionView::PaintLeft()
{
CBrush brushb(RGB(245,245,230));
int m_breakpoint;
CDC* hdc;
hdc = GetWindowDC();
CRect rect;
GetClientRect(&rect);
hdc->FillRect (CRect(rect.left ,rect.top ,rect.left +15,rect.Height ()+2),&brushb);//画底色
brushb.DeleteObject (); CEdit& theEdit = GetEditCtrl ();
int nFirstVisible = theEdit.GetFirstVisibleLine(); //得到当前显示的最上端的行号
CBrush OrigBrush,brushf(RGB(255,0,0));
CBrush *oldBrush = (CBrush*)hdc->SelectObject (brushf);
OrigBrush.FromHandle((HBRUSH)oldBrush); IntList::iterator it;
for(it = lBreakPoint.begin(); it != lBreakPoint.end(); it++)
{
m_breakpoint = *it;
if(m_breakpoint > nFirstVisible)
{
int point = (m_breakpoint-1 - nFirstVisible)*m_LineHeight +3; //计算断点位置
if(point < (rect.bottom - m_LineHeight+1))
{
hdc->Ellipse(rect.left, point, rect.left+10,point+m_LineHeight-5);//画断点
}
}
}
hdc->SelectObject (&OrigBrush);
OrigBrush.DeleteObject();
brushf.DeleteObject (); int CurrentLine = nFirstVisible + 1,CurrentPoint;
CRect leftRect;
CString strLine;
while(1)
{
CurrentPoint = (CurrentLine - nFirstVisible - 1) * m_LineHeight + 2;
if(CurrentPoint <0 || CurrentPoint > (rect.bottom - m_LineHeight+1) || CurrentLine > theEdit.GetLineCount())
break;
leftRect.left = rect.left + 15;
leftRect.right = m_LineHeight + 30;
leftRect.top = CurrentPoint;
leftRect.bottom = CurrentPoint + m_LineHeight;
strLine.Format ("%d",CurrentLine);
hdc->SetTextColor(RGB(192,192,192));
hdc->DrawText (strLine,&leftRect,0);
CurrentLine ++;
}
}void CFunctionView::OnEditBP()
{
CEdit& theEdit = GetEditCtrl ();
int newpoint = theEdit.LineFromChar (-1) + 1;
AddRemoveBP(newpoint);
Invalidate ();
}void CFunctionView::AddRemoveBP(int point)
{
CMainFrame* pMain=(CMainFrame*)AfxGetApp()->m_pMainWnd;
IntList::iterator it;
it = find(lBreakPoint.begin (), lBreakPoint.end (), point); if( it != lBreakPoint.end () ) //如果此行为设置了断点的行则删除否则添加
{
lBreakPoint.erase (it);
}
else
{
lBreakPoint.push_back (point);
}}void CFunctionView::OnChange()
{
PaintLeft();
}void CFunctionView::RemoveAllBP()
{
lBreakPoint.clear();
}这个是对话框的CProgramDlg类的代码
// ProgramDlg.cpp : 实现文件
//#include "stdafx.h"
#include "jiqiren.h"
#include "ProgramDlg.h"
#include "afxdialogex.h"// CProgramDlg 对话框IMPLEMENT_DYNAMIC(CProgramDlg, CDialog)CProgramDlg::CProgramDlg(CWnd* pParent /*=NULL*/)
: CDialog(CProgramDlg::IDD, pParent)
{
m_proEdit = _T("");
}CProgramDlg::~CProgramDlg()
{
}
CProgramDlg *g_Prodlg=NULL;
void CProgramDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT_Pro, m_ProEd);
DDX_Text(pDX, IDC_EDIT_Pro, m_proEdit);
}
BEGIN_MESSAGE_MAP(CProgramDlg, CDialog)
ON_WM_SIZE()
ON_COMMAND(ID_Generation, &CProgramDlg::OnGeneration)END_MESSAGE_MAP()
// CProgramDlg 消息处理程序BOOL CProgramDlg::OnInitDialog()
{
CDialog::OnInitDialog();
g_Prodlg=this;
//m_font.CreatePointFont(120,(LPCTSTR)"宋体");
//GetDlgItem(IDC_EDIT_Pro)->SetFont(&m_font);
if(!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
{
TRACE0( "Failed to Create Dialog Toolbar\n ");
EndDialog(IDCANCEL);
} /*CRect rcClientOld; // 旧客户区RECT
CRect rcClientNew; // 加入TOOLBAR后的CLIENT RECT
GetClientRect(rcClientOld);
//重新计算RECT大小
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0,reposQuery,rcClientNew);
//所有的子窗口将被移动,以免被TOOLBAR覆盖
//计算移动的距离
CPoint ptOffset(rcClientNew.left-rcClientOld.left,rcClientNew.top-rcClientOld.top);
CRect rcChild;
CWnd* pwndChild = GetWindow(GW_CHILD); //得到子窗口
while(pwndChild) // 处理所有子窗口
{
//移动所有子窗口
pwndChild-> GetWindowRect(rcChild);
ScreenToClient(rcChild);
rcChild.OffsetRect(ptOffset);
pwndChild-> MoveWindow(rcChild,FALSE);
pwndChild = pwndChild-> GetNextWindow();
} CRect rcWindow;
GetWindowRect(rcWindow); // 得到对话框RECT
rcWindow.right += rcClientOld.Width() - rcClientNew.Width(); // 修改对话框尺寸
rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height();
MoveWindow(rcWindow,FALSE); // Redraw Window
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);*/
return TRUE; // return TRUE unless you set the focus to a control}void CProgramDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy); // TODO: 在此处添加消息处理程序代码
CWnd *pWnd;
pWnd = GetDlgItem(IDC_EDIT_Pro ); //获取控件句柄
if(pWnd)//判断是否为空,因为对话框创建时会调用此函数,而当时控件还未创建
{
CRect rect; //获取控件变化前大小
pWnd->GetWindowRect(&rect);
ScreenToClient(&rect);//将控件大小转换为在对话框中的区域坐标
// cx/m_rect.Width()为对话框在横向的变化比例
rect.left=rect.left*cx/m_rect.Width();//调整控件大小
rect.right=rect.right*cx/m_rect.Width();
rect.top=rect.top*cy/m_rect.Height();
rect.bottom=rect.bottom*cy/m_rect.Height();
pWnd->MoveWindow(rect);//设置控件大小
}
GetClientRect(&m_rect);//将变化后的对话框大小设为旧大小
}
void CProgramDlg::OnGeneration()
{
// TODO: 在此添加命令处理程序代码
CString strPath[2];
CString strText;
strPath[0]=_T("E:\\example\\1test.cpp");
strPath[1]=_T("E:\\example\\2test.cpp");
for(int i=0;i<2;i++)
{
CFile file(strPath[i],CFile::modeRead);
char read[10000];
file.Read(read,10000);
for(int i=0;i<(file.GetLength());i++)
{
strText+=read[i];
}
file.Close();
//g_Prodlg->m_ProEd.SetSel(-1,-1); //在edit中追加内容
//g_Prodlg->m_ProEd.ReplaceSel(strText);
}}
不能把CFunctionView的功能和CProgramDlg整合到一起吗?
{
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
// TODO: Add extra initialization here
// View size
CRect clientRect;
GetClientRect(&clientRect);
#ifdef USE_GL_VIEW
//afxDump << clientRect << "\n";
// Creation 'on the fly' of the new view
CView* pNewView;
pNewView = new COpenGLView;
// Creation of the view window
afxTraceEnabled=FALSE;
if(! pNewView->Create(NULL, NULL, WS_VISIBLE | WS_CHILD, clientRect, this, 1000))
{
TRACE( "Failed view creation\n" );
}
afxTraceEnabled=TRUE;
//设置像素格式,并在DC中选择这种格式
#else
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24 ,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
32 ,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
}; int pixelformat;
m_hDC = ::GetDC(this->GetSafeHwnd());
if (!(pixelformat = ChoosePixelFormat(m_hDC , &pfd)))
{
MessageBox("ChoosePixelFormat failed!");
return false;
} if (!SetPixelFormat(m_hDC , pixelformat , &pfd))
{
MessageBox("SetPixelFormat failed!");
return false;
} if (!(m_hRC = wglCreateContext(m_hDC)))
{
MessageBox("CreateContext failed!");
return false;
} if (!wglMakeCurrent(m_hDC , m_hRC))
{
MessageBox("MakeCurrent failed!");
return false;
}
//
CRect rect; //在这个矩形中画图
GetClientRect(rect); glViewport(0 , 0 , rect.Width() , rect.Height());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
/*gluPerspective(45.0f , rect.Width()/rect.Height() , 0.1f , 100.0f);// 计算窗口的外观比例*/
gluPerspective(45.0f , 640/480 , 0.1f , 100.0f);// 计算窗口的外观比例
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glClearColor(0.0f , 0.0f , 0.0f , 1.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST); RotateDegTriangle = RotateDegQuad = 0;
//
SetTimer(1 , 50 , NULL);
//
#endif
return TRUE; // return TRUE unless you set the focus to a control
}也就是:
pNewView = new CFunctionView,;
CEditView 自带CEditCtrl
麻烦大神能不能把我的程序整合下,实现我说的功能。我不是太懂
{
CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
} // 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
// TODO: Add extra initialization here
// View size
CRect clientRect;
GetClientRect(&clientRect);
// afxDump << clientRect << "\n";
// Creation 'on the fly' of the new view
CView* pNewView;
pNewView = new CFunctionView;
// Creation of the view window
afxTraceEnabled=FALSE;
if(! pNewView->Create(NULL, NULL, WS_VISIBLE | WS_CHILD, clientRect, this, 1000))
{
TRACE( "Failed view creation\n" );
}
afxTraceEnabled=TRUE; pNewView->OnInitialUpdate();//
return TRUE; // return TRUE unless you set the focus to a control
}没有另一个EditCtrl, CEditView 自己有,你把 edit 的内容放 void CFunctionView::OnInitialUpdate()
{
CEditView::OnInitialUpdate();
// TODO: 在此添加专用代码和/或调用基类
SIZE size;
GetTextExtentPoint(GetDC()->GetSafeHdc (),"A",1,&size);
m_LineHeight = size.cy; //得到行的高度
CEdit& theEdit = GetEditCtrl ();
theEdit.SetMargins (m_LineHeight+31,0); //设置编辑框的左边界
theEdit.SetLimitText(10 * 1024); //设置输入的最大文本
m_ldown = FALSE;
//
SetWindowText(
"1111111111111111111\r\n"
"2222222222222222222\r\n"
"3322222222222222222\r\n"
"4222222222222222222\r\n"
"5222222222222222222\r\n"
"6222222222222222222\r\n"
"7222222222222222222\r\n"
"8222222222222222222\r\n"
"9222222222222222222\r\n"
"1111111111111111111\r\n"
"2222222222222222222\r\n"
"3322222222222222222\r\n"
"4222222222222222222\r\n"
"5222222222222222222\r\n"
"6222222222222222222\r\n"
"7222222222222222222\r\n"
"8222222222222222222\r\n"
"9222222222222222222\r\n"
"0222222222222222222\r\n"
"1222222222222222222\r\n"
"2222222222222222222\r\n"
"3222222222222222222\r\n"
"4222222222222222222\r\n"
"5222222222222222222\r\n"
"6222222222222222222\r\n"
"7222222222222222222\r\n"
"8222222222222222222\r\n"
"9222222222222222222\r\n"
"0222222222222222222\r\n"
);
}
但我在EditView中显示的文本不是一开始写进去的,需要将两个特定路径下的文件打开依次写进去,
类似于以下代码中的功能怎么实现啊?void CProgramDlg::OnGeneration()
{
// TODO: 在此添加命令处理程序代码
CString strPath[2];
CString strText;
strPath[0]=_T("E:\\example\\1test.cpp");
strPath[1]=_T("E:\\example\\2test.cpp");
for(int i=0;i<2;i++)
{
CFile file(strPath[i],CFile::modeRead);
char read[10000];
file.Read(read,10000);
for(int i=0;i<(file.GetLength());i++)
{
strText+=read[i];
}
file.Close();
g_Prodlg->m_ProEd.SetSel(-1,-1); //在edit中追加内容
g_Prodlg->m_ProEd.ReplaceSel(strText);
}
}
//画左边的显示条
void CFunctionView::PaintLeft()
{
CBrush brushb(RGB(245,245,230)); CDC* hdc;
hdc = GetWindowDC();
CRect rect;
GetClientRect(&rect);
hdc->FillRect (CRect(rect.left ,rect.top ,rect.left +15,rect.Height ()+2),&brushb);//画底色
brushb.DeleteObject ();
//得到当前显示的最上端的行号
CEdit& theEdit = GetEditCtrl ();
int nFirstVisible = theEdit.GetFirstVisibleLine();
//
CBrush brushRed(RGB(255,0,0));
CBrush *oldBrush = (CBrush*)hdc->SelectObject(brushRed); for(int jj=0;jj<m_arInt.GetSize();jj++)
{
m_breakpoint = (int)m_arInt[jj];
if(m_breakpoint > nFirstVisible)
{
m_breakpoint--;
int Yat = (m_breakpoint - nFirstVisible) * m_LineHeight + 8; //计算断点位置
if(Yat < rect.bottom)
{
hdc->Ellipse(rect.left, Yat, rect.left+10,Yat+10);//画断点
}
}
}
hdc->SelectObject (&oldBrush);
//
int CurrentLine = nFirstVisible + 1;
int CurrentPoint;
CRect leftRect;
CString strLine;
while(1)
{
CurrentPoint = (CurrentLine - nFirstVisible - 1) * m_LineHeight + 2;
if(CurrentPoint <0 || CurrentPoint > (rect.bottom - m_LineHeight+1) || CurrentLine > theEdit.GetLineCount())
break;
leftRect.left = rect.left + 15;
leftRect.right = m_LineHeight + 30;
leftRect.top = CurrentPoint;
leftRect.bottom = CurrentPoint + m_LineHeight;
// line number
strLine.Format ("%d",CurrentLine);
hdc->SetTextColor(RGB(0,255,0));
hdc->DrawText (strLine,&leftRect,0);
CurrentLine ++;
}
}头中
int m_breakpoint;
CDWordArray m_arInt;
//
void CFunctionView::OnInitialUpdate()
加:
m_arInt.Add(10);
m_arInt.Add(21);
}