如何将Dialog中的数据传送到文档类中(在线等待)

shen13 2003-07-21 08:12:23
本人在一个多文档的应用程序中加入了一个派生Dialog的类,派生Dialog的类中有一个变量,我想当按了Dialog窗口中的“OK”键后,将这个变量的值传给文档类有一个成员变量。小弟不知道怎么实现,请各位大侠帮忙!!最好有示例.
...全文
64 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
topYellow 2003-07-21
  • 打赏
  • 举报
回复
第一次得分,好高兴啊
SeainBlue 2003-07-21
  • 打赏
  • 举报
回复
视图起到连接对话框和文档类的作用
视图 可以取到对话框的变量 dlg.dlgVar
视图也可以取得文档类的变量
C***Doc *pDoc = GetDocument();
pDoc->DocVar

所以就可以将对话框变量的值赋给文档类中的变量了
SeainBlue 2003-07-21
  • 打赏
  • 举报
回复
那就是我上面的第二个回帖就可以解决了
shen13 2003-07-21
  • 打赏
  • 举报
回复
对不起,我打错了,应该是由在视图上的按钮触发对话框
shen13 2003-07-21
  • 打赏
  • 举报
回复
还有一个问题,我的程序中间还有一个对话框,由最后一个对话框怎么传到文档类呢
SeainBlue 2003-07-21
  • 打赏
  • 举报
回复
对话框在视图上的按钮?
什么意思
shen13 2003-07-21
  • 打赏
  • 举报
回复
由对话框在视图上的按钮触发
SeainBlue 2003-07-21
  • 打赏
  • 举报
回复
如果在视图类中调用对话框

其它都一样,就是增加一个找到文档指针
C***Doc *pDoc = GetDocument();

pDoc->DocVar = dlg.dlgVar ;

注意对话框的变量dlgVar要定义成public型
SeainBlue 2003-07-21
  • 打赏
  • 举报
回复
对话框在什么地方调用的?

如果是文档类就简单了
假设文档类变量 int DocVar;
对话框类变量 int DlgVar ;

C***Dialog dlg ;
if(dlg.DoModal() == IDOK)
{
DocVar = dlg.dlgVar ;
}
topYellow 2003-07-21
  • 打赏
  • 举报
回复
试试下面的
C*Dlg dlg;
if(dlg.Dodlg.DoModal()==IDOK){
this->m_name = dlg.name;
}假设你的文档类有Public:name and C*Dlg有Public:name
Visual C++MFC入门教程 目录 +-- 第一章 VC入门 |------ 1.1 如何学好VC |------ 1.2 理解Windows消息机制 |------ 1.3 利用Visual C++/MFC开发Windows程序的优势 |------ 1.4 利用MFC进行开发的通用方法介绍 |------ 1.5 MFC常用类,宏,函数介绍 +-- 第二章 图形输出 |------ 2.1 和GUI有关的各种对象 |------ 2.2 在窗口输出文字 |------ 2.3 使用点,刷子,笔进行绘图 |------ 2.4 在窗口绘制设备相关位图,图标,设备无关位图 |------ 2.5 使用各种映射方式 |------ 2.6 多边形和剪贴区域 +-- 第三章 文档视结构 |------ 3.1 文档 视图 框架窗口间的关系和消息传送规律 |------ 3.2 接收用户输入 |------ 3.3 使用菜单 |------ 3.4 文档,视,框架之间相互作用 |------ 3.5 利用序列化进行文件读写 |------ 3.6 MFC所提供的各种视类介绍 +-- 第四章 窗口控件 |------ 4.1 Button |------ 4.2 Static Box |------ 4.3 Edit Box |------ 4.4 Scroll Bar |------ 4.5 List Box/Check List Box |------ 4.6 Combo Box/Combo Box Ex |------ 4.7 Tree Ctrl |------ 4.8 List Ctrl |------ 4.9 Tab Ctrl |------ 4.A Tool Bar |------ 4.B Status Bar |------ 4.C Dialog Bar |------ 4.D 利用AppWizard创建并使用ToolBar StatusBar Dialog Bar |------ 4.E General Window |------ 4.F 关于WM_NOTIFY的使用方法 +-- 第五章 对话框 |------ 5.1 使用资源编辑器编辑对话框 |------ 5.2 创建有模式对话框 |------ 5.3 创建无模式对话框 |------ 5.4 在对话框进行消息映射 |------ 5.5 在对话框进行数据交换和数据检查 |------ 5.6 使用属性对话框 |------ 5.7 使用通用对话框 |------ 5.8 建立以对话框为基础的应用 |------ 5.9 使用对话框作为子窗口 +-- 第六章 网络通信开发 |------ 6.1 WinSock介绍 |------ 6.2 利用WinSock进行无连接的通信 +------ 6.3 利用WinSock建立有连接的通信   第一章 VC入门 1.1 如何学好VC 这个问题很多朋友都问过我,当然流汗是必须的,但同时如果按照某种思路进行有计划的学习就会起到更好的效果。万事开头难,为了帮助朋友们更快的掌握VC开发,下面我将自己的一点体会讲一下: 1、需要有好的C/C++基础。正所谓“磨刀不误砍柴工”,最开始接触VC时不要急于开始Windows程序开发,而是应该进行一些字符界面程序的编写。这样做的目的主要是增加对语言的熟悉程度,同时也训练自己的思维和熟悉一些在编程常犯的错误。更重要的是理解并能运用C++的各种特性,这些在以后的开发都会有很大的帮助,特别是利用MFC进行开发的朋友对C++一定要能熟练运用。 2、理解Windows的消息机制,窗口句柄和其他GUI句柄的含义和用途。了解和MFC各个类功能相近的API函数。 3、一定要理解MFC消息映射的作用。 4、训练自己在编写代码时不使用参考书而是使用Help Online。 5、记住一些常用的消息名称和参数的意义。 6、学会看别人的代码。 7、多看书,少买书,买书前一定要慎重。 8、闲下来的时候就看参考书。 9、多来我的主页。^O^ 后面几条是我个人的一点意见,你可以根据需要和自身的情况选用适用于自己的方法。 此外我将一些我在选择参考书时的原则: 对于初学者:应该选择一些内容比较全面的书籍,并且书籍的内容应该以合理的方式安排,在使用该书时可以达到循序渐进的效果,书的代码要有详细的讲解。尽量买翻译的书,因为这些书一般都比较易懂,而且语言比较轻松。买书前一定要慎重如果买到不好用的书可能会对自己的学习积极性产生击。 对于已经掌握了VC的朋友:这种程度的开发者应该加深自己对系统原理,技术要点的认识。需要选择一些对原理讲解的比较透彻的书籍,这样一来才会对新技术有更多的了解,最好书对技术的应用有一定的阐述。尽量选择示范代码必较精简的书,可以节约银子。 此外最好涉猎一些辅助性的书籍。 1.2 理解Windows消息机制 Windows系统是一个消息驱动的OS,什么是消息呢?我很难说得清楚,也很难下一个定义(谁在嘘我),我下面从不同的几个方面讲解一下,希望大家看了后有一点了解。 1、消息的组成:一个消息由一个消息名称(UINT),和两个参数(WPARAM,LPARAM)。当用户进行了输入或是窗口的状态发生改变时系统都会发送消息到某一个窗口。例如当菜单转之后会有WM_COMMAND消息发送,WPARAM的高字(HIWORD(wParam))是命令的ID号,对菜单来讲就是菜单ID。当然用户也可以定义自己的消息名称,也可以利用自定义消息来发送通知和传送数据。 2、谁将收到消息:一个消息必须由一个窗口接收。在窗口的过程(WNDPROC)可以对消息进行分析,对自己感兴趣的消息进行处理。例如你希望对菜单选择进行处理那么你可以定义对WM_COMMAND进行处理的代码,如果希望在窗口进行图形输出就必须对WM_PAINT进行处理。 3、未处理的消息到那里去了:M$为窗口编写了默认的窗口过程,这个窗口过程将负责处理那些你不处理消息。正因为有了这个默认窗口过程我们才可以利用Windows的窗口进行开发而不必过多关注窗口各种消息的处理。例如窗口在被拖动时会有很多消息发送,而我们都可以不予理睬让系统自己去处理。 4、窗口句柄:说到消息就不能不说窗口句柄,系统通过窗口句柄来在整个系统唯一标识一个窗口,发送一个消息时必须指定一个窗口句柄表明该消息由那个窗口接收。而每个窗口都会有自己的窗口过程,所以用户的输入就会被正确的处理。例如有两个窗口共用一个窗口过程代码,你在窗口一上按下鼠标时消息就会通过窗口一的句柄被发送到窗口一而不是窗口二。 5、示例:下面有一段伪代码演示如何在窗口过程处理消息 LONG yourWndProc(HWND hWnd,UINT uMessageType,WPARAM wP,LPARAM) { switch(uMessageType) { //使用SWITCH语句将各种消息分开 case(WM_PAINT): doYourWindow(...);//在窗口需要重新绘制时进行输出 break; case(WM_LBUTTONDOWN): doYourWork(...);//在鼠标左键被按下时进行处理 break; default: callDefaultWndProc(...);//对于其它情况就让系统自己处理 break; } } 接下来谈谈什么是消息机制:系统将会维护一个或多个消息队列,所有产生的消息都回被放入或是插入队列。系统会在队列取出每一条消息,根据消息的接收句柄而将该消息发送给拥有该窗口的程序的消息循环。每一个运行的程序都有自己的消息循环,在循环得到属于自己的消息并根据接收窗口的句柄调用相应的窗口过程。而在没有消息时消息循环就将控制权交给系统所以Windows可以同时进行多个任务。下面的伪代码演示了消息循环的用法: while(1) { id=getMessage(...); if(id == quit) break; translateMessage(...); } 当该程序没有消息通知时getMessage就不会返回,也就不会占用系统的CPU时间。 下图为消息投递模式 在16位的系统系统只有一个消息队列,所以系统必须等待当前任务处理消息后才可以发送下一消息到相应程序,如果一个程序陷如死循环或是耗时操作时系统就会得不到控制权。这种多任务系统也就称为协同式的多任务系统。Windows3.X就是这种系统。而32位的系统每一运行的程序都会有一个消息队列,所以系统可以在多个消息队列转换而不必等待当前程序完成消息处理就可以得到控制权。这种多任务系统就称为抢先式的多任务系统。Windows95/NT就是这种系统。 1.3 利用Visual C++/MFC开发Windows程序的优势 MFC借助C++的优势为Windows开发开辟了一片新天地,同时也借助ApplicationWizzard使开发者摆脱离了那些每次都必写基本代码,借助ClassWizard和消息映射使开发者摆脱了定义消息处理时那种混乱和冗长的代码段。更令人兴奋的是利用C++的封装功能使开发者摆脱Windows各种句柄的困扰,只需要面对C++的对象,这样一来使开发更接近开发语言而远离系统。(但我个人认为了解系统原理对开发很有帮助) 正因为MFC是建立在C++的基础上,所以我强调C/C++语言基础对开发的重要性。利用C++的封装性开发者可以更容易理解和操作各种窗口对象;利用C++的派生性开发者可以减少开发自定义窗口的时间和创造出可重用的代码;利用虚拟性可以在必要时更好的控制窗口的活动。而且C++本身所具备的超越C语言的特性都可以使开发者编写出更易用,更灵活的代码。 在MFC对消息的处理利用了消息映射的方法,该方法的基础是宏定义实现,通过宏定义将消息分派到不同的成员函数进行处理。下面简单讲述一下这种方法的实现方法: 代码如下 BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() //}}AFX_MSG_MAP ON_COMMAND(ID_FONT_DROPDOWN, DoNothing) END_MESSAGE_MAP() 经过编译后,代码被替换为如下形式(这只是作讲解,实际情况比这复杂得多): //BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) CMainFrame::newWndProc(...) { switch(...) { //{{AFX_MSG_MAP(CMainFrame) // ON_WM_CREATE() case(WM_CREATE): OnCreate(...); break; //}}AFX_MSG_MAP // ON_COMMAND(ID_FONT_DROPDOWN, DoNothing) case(WM_COMMAND): if(HIWORD(wP)==ID_FONT_DROPDOWN) { DoNothing(...); } break; //END_MESSAGE_MAP() } } newWndProc就是窗口过程只要是该类的实例生成的窗口都使用该窗口过程。 所以了解了Windows的消息机制在加上对消息映射的理解就很容易了解MFC开发的基本思路了。 1.4 利用MFC进行开发的通用方法介绍 以下是我在最初学习VC时所常用的开发思路和方法,希望能对初学VC的朋友有所帮助和启发。 1、开发需要读写文件的应用程序并且有简单的输入和输出可以利用单文档视结构。 2、开发注重交互的简单应用程序可以使用对话框为基础的窗口,如果文件读写简单这可利用CFile进行。 3、开发注重交互并且文件读写复杂的的简单应用程序可以利用以CFormView为基础视的单文档视结构。 4、利用对话框得到用户输入的数据,在等级提高后可使用就地输入。 5、在对多文档要求不强烈时尽量避免多文档视结构,可以利用分隔条产生单文档多视结构。 6、在要求在多个文档间传递数据时使用多文档视结构。 7、学会利用子窗口,并在自定义的子窗口包含多个控件达到封装功能的目的。 8、尽量避免使用多文档多视结构。 9、不要使用多重继承并尽量减少一个类封装过多的功能。 1.5 MFC常用类,宏,函数介绍 常用类 CRect:用来表示矩形的类,拥有四个成员变量:top left bottom right。分别表是左上角和右下角的坐标。可以通过以下的方法构造: CRect( int l, int t, int r, int b ); 指明四个坐标 CRect( const RECT& srcRect ); 由RECT结构构造 CRect( LPCRECT lpSrcRect ); 由RECT结构构造 CRect( POINT point, SIZE size ); 有左上角坐标和尺寸构造 CRect( POINT topLeft, POINT bottomRight ); 有两点坐标构造 下面介绍几个成员函数: int Width( ) const; 得到宽度 int Height( ) const; 得到高度 CSize Size( ) const; 得到尺寸 CPoint& TopLeft( ); 得到左上角坐标 CPoint& BottomRight( ); 得到右下角坐标 CPoint CenterPoint( ) const; 得当心坐标 此外矩形可以和点(CPoint)相加进行位移,和另一个矩形相加得到“并”操作后的矩形。 CPoint:用来表示一个点的坐标,有两个成员变量:x y。 可以和另一个点相加。 CString:用来表示可变长度的字符串。使用CString可不指明内存大小,CString会根据需要自行分配。下面介绍几个成员函数: GetLength 得到字符串长度 GetAt 得到指定位置处的字符 operator + 相当于strcat void Format( LPCTSTR lpszFormat, ... ); 相当于sprintf Find 查找指定字符,字符串 Compare 比较 CompareNoCase 不区分大小写比较 MakeUpper 改为小写 MakeLower 改为大写 CStringArray:用来表示可变长度的字符串数组。数组每一个元素为CString对象的实例。下面介绍几个成员函数: Add 增加CString RemoveAt 删除指定位置CString对象 RemoveAll 删除数组所有CString对象 GetAt 得到指定位置的CString对象 SetAt 修改指定位置的CString对象 InsertAt 在某一位置插入CString对象 常用宏 RGB TRACE ASSERT VERIFY 常用函数 CWindApp* AfxGetApp(); HINSTANCE AfxGetInstanceHandle( ); HINSTANCE AfxGetResourceHandle( ); int AfxMessageBox( LPCTSTR lpszText, UINT nType = MB_OK, UINT nIDHelp = 0 );用于弹出一个消息框 第二章 图形输出 2.1 和GUI有关的各种对象 在Windows有各种GUI对象(不要和C++对象混淆),当你在进行绘图就需要利用这些对象。而各种对象都拥有各种属性,下面分别讲述各种GUI对象和拥有的属性。 字体对象CFont用于输出文字时选用不同风格和大小的字体。可选择的风格包括:是否为斜体,是否为粗体,字体名称,是否有下划线等。颜色和背景色不属于字体的属性。关于如何创建和使用字体在2.2 在窗口输出文字会详细讲解。 刷子CBrush对象决定填充区域时所采用的颜色或模板。对于一个固定色的刷子来讲它的属性为颜色,是否采用网格和网格的类型如水平的,垂直的,交叉的等。你也可以利用8*8的位图来创建一个自定义模板的刷子,在使用这种刷子填充时系统会利用位图逐步填充区域。关于如何创建和使用刷子在2.3 使用刷子,笔进行绘图会详细讲解。 画笔CPen对象在画点和画线时有用。它的属性包括颜色,宽度,线的风格,如虚线,实线,点划线等。关于如何创建和使用画笔在2.3 使用刷子,笔进行绘图会详细讲解。 位图CBitmap对象可以包含一幅图像,可以保存在资源。关于如何使用位图在2.4 在窗口绘制设备相关位图,图标,设备无关位图会详细讲解。 还有一种特殊的GUI对象是多边形,利用多边形可以很好的限制作图区域或是改变窗口外型。关于如何创建和使用多边形在2.6 多边形和剪贴区域会详细讲解。 在Windows使用GUI对象必须遵守一定的规则。首先需要创建一个合法的对象,不同的对象创建方法不同。然后需要将该GUI对象选入DC,同时保存DC原来的GUI对象。如果选入一个非法的对象将会引起异常。在使用完后应该恢复原来的对象,这一点特别重要,如果保存一个临时对象在DC,而在临时对象被销毁后可能引起异常。有一点必须注意,每一个对象在重新创建前必须销毁,下面的代码演示了这一种安全的使用方法: OnDraw(CDC* pDC) { CPen pen1,pen2; pen1.CreatePen(PS_SOLID,2,RGB(128,128,128));//创建对象 pen2.CreatePen(PS_SOLID,2,RGB(128,128,0));//创建对象 CPen* pPenOld=(CPen*)pDC->SelectObject(&pen1);//选择对象进DC drawWithPen1... (CPen*)pDC->SelectObject(&pen2);//选择对象进DC drawWithPen2... pen1.DeleteObject();//再次创建前先销毁 pen1.CreatePen(PS_SOLID,2,RGB(0,0,0));//再次创建对象 (CPen*)pDC->SelectObject(&pen1);//选择对象进DC drawWithPen1... pDC->SelectObject(pOldPen);//恢复 } 此外系统还拥有一些库存GUI对象,你可以利用CDC::SelectStockObject(SelectStockObject( int nIndex )选入这些对象,它们包括一些固定颜色的刷子,画笔和一些基本字体。 • BLACK_BRUSH Black brush. • DKGRAY_BRUSH Dark gray brush. • GRAY_BRUSH Gray brush. • HOLLOW_BRUSH Hollow brush. • LTGRAY_BRUSH Light gray brush. • NULL_BRUSH Null brush. • WHITE_BRUSH White brush. • BLACK_PEN Black pen. • NULL_PEN Null pen. • WHITE_PEN White pen. • ANSI_FIXED_FONT ANSI fixed system font. • ANSI_VAR_FONT ANSI variable system font. • DEVICE_DEFAULT_FONT Device-dependent font. • OEM_FIXED_FONT OEM-dependent fixed font. • SYSTEM_FONT The system font. By default, Windows uses the system font to draw menus, dialog-box controls, and other text. In Windows versions 3.0 and later, the system font is proportional width; earlier versions of Windows use a fixed-width system font. • SYSTEM_FIXED_FONT The fixed-width system font used in Windows prior to version 3.0. This object is available for compatibility with earlier versions of Windows. • DEFAULT_PALETTE Default color palette. This palette consists of the 20 static colors in the system palette. 这些对象留在DC是安全的,所以你可以利用选入库存对象来作为恢复DCGUI对象。 大家可能都注意到了绘图时都需要一个DC对象,DC(Device Context设备环境)对象是一个抽象的作图环境,可能是对应屏幕,也可能是对应打印机或其它。这个环境是设备无关的,所以你在对不同的设备输出时只需要使用不同的设备环境就行了,而作图方式可以完全不变。这也就是Windows耀眼的一点设备无关性。如同你将对一幅画使用照相机或复印机将会产生不同的输出,而不需要对画进行任何调整。DC的使用会穿插在本章进行介绍。 2.2 在窗口输出文字 在这里我假定读者已经利用ApplicationWizard生成了一个SDI界面的程序代码。接下来的你只需要在CView派生类的OnDraw成员函数加入绘图代码就可以了。在这里我需要解释一下OnDraw函数的作用,OnDraw函数会在窗口需要重绘时自动被调用,传入的参数CDC* pDC对应的就是DC环境。使用OnDraw的优点就在于在你使用打印功能的时候传入OnDraw的DC环境将会是打印机绘图环境,使用打印预览时传入的是一个称为CPreviewDC的绘图环境,所以你只需要一份代码就可以完成窗口/打印预览/打印机绘图三重功能。利用Windows的设备无关性和M$为打印预览所编写的上千行代码你可以很容易的完成一个具有所见即所得的软件。 输出文字一般使用CDC::BOOL TextOut( int x, int y, const CString& str )和CDC::int DrawText( const CString& str, LPRECT lpRect, UINT nFormat )两个函数,对TextOut来讲只能输出单行的文字,而DrawText可以指定在一个矩形输出单行或多行文字,并且可以规定对齐方式和使用何种风格。nFormat可以是多种以下标记的组合(利用位或操作)以达到选择输出风格的目的。 • DT_BOTTOM底部对齐 Specifies bottom-justified text. This value must be combined with DT_SINGLELINE. • DT_CALCRECT计算指定文字时所需要矩形尺寸 Determines the width and height of the rectangle. If there are multiple lines of text, DrawText will use the width of the rectangle pointed to by lpRect and extend the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText will modify the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text, but does not draw the text. • DT_CENTER部对齐 Centers text horizontally. • DT_END_ELLIPSIS or DT_PATH_ELLIPSIS Replaces part of the given string with ellipses, if necessary, so that the result fits in the specified rectangle. The given string is not modified unless the DT_MODIFYSTRING flag is specified. You can specify DT_END_ELLIPSIS to replace characters at the end of the string, or DT_PATH_ELLIPSIS to replace characters in the middle of the string. If the string contains backslash (\) characters, DT_PATH_ELLIPSIS preserves as much as possible of the text after the last backslash. • DT_EXPANDTABS Expands tab characters. The default number of characters per tab is eight. • DT_EXTERNALLEADING Includes the font抯 external leading in the line height. Normally, external leading is not included in the height of a line of text. • DT_LEFT左对齐 Aligns text flush-left. • DT_MODIFYSTRING Modifies the given string to match the displayed text. This flag has no effect unless the DT_END_ELLIPSIS or DT_PATH_ELLIPSIS flag is specified. Note Some uFormat flag combinations can cause the passed string to be modified. Using DT_MODIFYSTRING with either DT_END_ELLIPSIS or DT_PATH_ELLIPSIS may cause the string to be modified, causing an assertion in the CString override. • DT_NOCLIP Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used. • DT_NOPREFIX禁止使用&前缀 Turns off processing of prefix characters. Normally, DrawText interprets the ampersand (&) mnemonic-prefix character as a directive to underscore the character that follows, and the two-ampersand (&&) mnemonic-prefix characters as a directive to print a single ampersand. By specifying DT_NOPREFIX, this processing is turned off. • DT_PATH_ELLIPSIS • DT_RIGHT右对齐 Aligns text flush-right. • DT_SINGLELINE单行输出 Specifies single line only. Carriage returns and linefeeds do not break the line. • DT_TABSTOP设置TAB字符所占宽度 Sets tab stops. The high-order byte of nFormat is the number of characters for each tab. The default number of characters per tab is eight. • DT_TOP定部对齐 Specifies top-justified text (single line only). • DT_VCENTER部对齐 Specifies vertically centered text (single line only). • DT_WORDBREAK每行只在单词间被折行 Specifies word-breaking. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by lpRect. A carriage return杔inefeed sequence will also break the line. 在输出文字时如果希望改变文字的颜色,你可以利用CDC::SetTextColor( COLORREF crColor )进行设置,如果你希望改变背景色就利用CDC::SetBkColor( COLORREF crColor ),很多时候你可能需要透明的背景色你可以利用CDC::SetBkMode( int nBkMode )设置,可接受的参数有 • OPAQUE Background is filled with the current background color before the text, hatched brush, or pen is drawn. This is the default background mode. • TRANSPARENT Background is not changed before drawing. 接下来讲讲如何创建字体,你可以创建的字体有两种:库存字体CDC::CreateStockObject( int nIndex )和自定义字体。 在创建非库存字体时需要填充一个LOGFONT结构并使用CFont::CreateFontIndirect(const LOGFONT* lpLogFont ),或使用CFont::CreateFont( int nHeight, int nWidth, int nEscapement, int nOrientation, int nWeight, BYTE bItalic, BYTE bUnderline, BYTE cStrikeOut, BYTE nCharSet, BYTE nOutPrecision, BYTE nClipPrecision, BYTE nQuality, BYTE nPitchAndFamily, LPCTSTR lpszFacename )其的参数和LOGFONT的分量有一定的对应关系。下面分别讲解参数的意义: nHeight 字体高度(逻辑单位)等于零为缺省高度,否则取绝对值并和可用的字体高度进行匹配。 nWidth 宽度(逻辑单位)如果为零则使用可用的横纵比进行匹配。 nEscapement 出口矢量与X轴间的角度 nOrientation 字体基线与X轴间的角度 nWeight 字体粗细,可取以下值 Constant Value FW_DONTCARE 0 FW_THIN 100 FW_EXTRALIGHT 200 FW_ULTRALIGHT 200 FW_LIGHT 300 FW_NORMAL 400 FW_REGULAR 400 FW_MEDIUM 500 FW_SEMIBOLD 600 FW_DEMIBOLD 600 FW_BOLD 700 FW_EXTRABOLD 800 FW_ULTRABOLD 800 FW_BLACK 900 FW_HEAVY 900 bItalic 是否为斜体 bUnderline 是否有下划线 cStrikeOut 是否带删除线 nCharSet 指定字符集合,可取以下值 Constant Value ANSI_CHARSET 0 DEFAULT_CHARSET 1 SYMBOL_CHARSET 2 SHIFTJIS_CHARSET 128 OEM_CHARSET 255 nOutPrecision 输出精度 OUT_CHARACTER_PRECIS OUT_STRING_PRECIS OUT_DEFAULT_PRECIS OUT_STROKE_PRECIS OUT_DEVICE_PRECIS OUT_TT_PRECIS OUT_RASTER_PRECIS nClipPrecision 剪辑精度,可取以下值 CLIP_CHARACTER_PRECIS CLIP_MASK CLIP_DEFAULT_PRECIS CLIP_STROKE_PRECIS CLIP_ENCAPSULATE CLIP_TT_ALWAYS CLIP_LH_ANGLES nQuality 输出质量,可取以下值 • DEFAULT_QUALITY Appearance of the font does not matter. • DRAFT_QUALITY Appearance of the font is less important than when PROOF_QUALITY is used. For GDI raster fonts, scaling is enabled. Bold, italic, underline, and strikeout fonts are synthesized if necessary. • PROOF_QUALITY Character quality of the font is more important than exact matching of the logical-font attributes. For GDI raster fonts, scaling is disabled and the font closest in size is chosen. Bold, italic, underline, and strikeout fonts are synthesized if necessary. nPitchAndFamily 字体间的间距 lpszFacename 指定字体名称,为了得到系统所拥有的字体可以利用EmunFontFamiliesEx。 此外可以利用CFontDialog来得到用户选择的字体的LOGFONT数据。 最后我讲一下文本坐标的计算,利用CDC::GetTextExtent( const CString& str )可以得到字符串的在输出时所占用的宽度和高度,这样就可以在手工输出多行文字时使用正确的行距。另外如果需要更精确的对字体高度和宽度进行计算就需要使用CDC::GetTextMetrics( LPTEXTMETRIC lpMetrics ) 该函数将会填充TEXTMETRIC结构,该结构的分量可以非常精确的描述字体的各种属性。 2.3 使用点,刷子,笔进行绘图 在Windows画点的方法很简单,只需要调用COLORREF CDC::SetPixel( int x, int y, COLORREF crColor )就可以在指定点画上指定颜色,同时返回原来的颜色。COLORREF CDC::GetPixel( int x, int y)可以得到指定点的颜色。在Windows应该少使用画点的函数,因为这样做的执行效率比较低。 刷子和画笔在Windows作图是使用最多的GUI对象,本节在讲解刷子和画笔使用方法的同时也讲述一写基本作图函数。 在画点或画线时系统使用当前DC的画笔,所以在创建画笔后必须将其选入DC才会在绘图时产生效果。画笔可以通过CPen对象来产生,通过调用CPen::CreatePen( int nPenStyle, int nWidth, COLORREF crColor )来创建。其nPenStyle指名画笔的风格,可取如下值: • PS_SOLID 实线 Creates a solid pen. • PS_DASH 虚线,宽度必须为一 Creates a dashed pen. Valid only when the pen width is 1 or less, in device units. • PS_DOT 点线,宽度必须为一 Creates a dotted pen. Valid only when the pen width is 1 or less, in device units. • PS_DASHDOT 点划线,宽度必须为一 Creates a pen with alternating dashes and dots. Valid only when the pen width is 1 or less, in device units. • PS_DASHDOTDOT 双点划线,宽度必须为一 Creates a pen with alternating dashes and double dots. Valid only when the pen width is 1 or less, in device units. • PS_NULL 空线,使用时什么也不会产生 Creates a null pen. • PS_ENDCAP_ROUND 结束处为圆形 End caps are round. • PS_ENDCAP_SQUARE 结束处为方形 End caps are square. nWidth和crColor为线的宽度和颜色。 刷子是在画封闭曲线时用来填充的颜色,例如当你画圆形或方形时系统会用当前的刷子对内部进行填充。刷子可利用CBrush对象产生。通过以下几种函数创建刷子: • BOOL CreateSolidBrush( COLORREF crColor ); 创建一种固定颜色的刷子 • BOOL CreateHatchBrush( int nIndex, COLORREF crColor ); 创建指定颜色和网格的刷子,nIndex可取以下值: • HS_BDIAGONAL Downward hatch (left to right) at 45 degrees • HS_CROSS Horizontal and vertical crosshatch • HS_DIAGCROSS Crosshatch at 45 degrees • HS_FDIAGONAL Upward hatch (left to right) at 45 degrees • HS_HORIZONTAL Horizontal hatch • HS_VERTICAL Vertical hatch • BOOL CreatePatternBrush( CBitmap* pBitmap ); 创建以8*8位图为模板的刷子 在选择了画笔和刷子后就可以利用Windows的作图函数进行作图了,基本的画线函数有以下几种 • CDC::MoveTo( int x, int y ); 改变当前点的位置 • CDC::LineTo( int x, int y ); 画一条由当前点到参数指定点的线 • CDC::BOOL Arc( LPCRECT lpRect, POINT ptStart, POINT ptEnd ); 画弧线 • CDC::BOOL Polyline( LPPOINT lpPoints, int nCount ); 将多条线依次序连接 基本的作图函数有以下几种: • CDC::BOOL Rectangle( LPCRECT lpRect ); 矩形 • CDC::RoundRect( LPCRECT lpRect, POINT point ); 圆角矩形 • CDC::Draw3dRect( int x, int y, int cx, int cy, COLORREF clrTopLeft, COLORREF clrBottomRight ); 3D边框 • CDC::Chord( LPCRECT lpRect, POINT ptStart, POINT ptEnd ); 扇形 • CDC::Ellipse( LPCRECT lpRect ); 椭圆形 • CDC::Pie( LPCRECT lpRect, POINT ptStart, POINT ptEnd ); • CDC::Polygon( LPPOINT lpPoints, int nCount ); 多边形 对于矩形,圆形或类似的封闭曲线,系统会使用画笔绘制边缘,使用刷子填充内部。如果你不希望填充或是画出边缘,你可以选入空刷子(NULL_PEN)或是(NULL_BRUSH)空笔。 下面的代码创建一条两象素宽的实线并选入DC。并进行简单的作图: { ... CPen pen; pen.CreatePen(PS_SOLID,2,RGB(128,128,128)); CPen* pOldPen=(CPen*)dc.SelectObject(&pen); dc.SelectStockObject(NULL_BRUSH);//选入空刷子 dc.Rectangle(CRect(0,0,20,20));//画矩形 ... } 2.4 在窗口绘制设备相关位图,图标,设备无关位图 在Windows可以将预先准备好的图像复制到显示区域,这种内存拷贝执行起来是非常快的。在Windows提供了两种使用图形拷贝的方法:通过设备相关位图(DDB)和设备无关位图(DIB)。 DDB可以用MFC的CBitmap来表示,而DDB一般是存储在资源文件,在加载时只需要通过资源ID号就可以将图形装入。BOOL CBitmap::LoadBitmap( UINT nIDResource )可以装入指定DDB,但是在绘制时必须借助另一个和当前绘图DC兼容的内存DC来进行。通过CDC::BitBlt( int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, DWORD dwRop )绘制图形,同时指定光栅操作的类型。BitBlt可以将源DC位图复制到目的DC,其前四个参数为目的区域的坐标,接下来是源DC指针,然后是源DC的起始坐标,由于BitBlt为等比例复制,所以不需要再次指定长宽,(StretchBlt可以进行缩放)最后一个参数为光栅操作的类型,可取以下值: • BLACKNESS 输出区域为黑色 Turns all output black. • DSTINVERT 反色输出区域 Inverts the destination bitmap. • MERGECOPY 在源和目的间使用AND操作 Combines the pattern and the source bitmap using the Boolean AND operator. • MERGEPAINT 在反色后的目的和源间使用OR操作 Combines the inverted source bitmap with the destination bitmap using the Boolean OR operator. • NOTSRCCOPY 将反色后的源拷贝到目的区 Copies the inverted source bitmap to the destination. • PATINVERT 源和目的间进行XOR操作 Combines the destination bitmap with the pattern using the Boolean XOR operator. • SRCAND 源和目的间进行AND操作 Combines pixels of the destination and source bitmaps using the Boolean AND operator. • SRCCOPY 复制源到目的区 Copies the source bitmap to the destination bitmap. • SRCINVERT 源和目的间进行XOR操作 Combines pixels of the destination and source bitmaps using the Boolean XOR operator. • SRCPAINT 源和目的间进行OR操作 Combines pixels of the destination and source bitmaps using the Boolean OR operator. • WHITENESS 输出区域为白色 Turns all output white. 下面用代码演示这种方法: CYourView::OnDraw(CDC* pDC) { CDC memDC;//定义一个兼容DC memDC.CreateCompatibleDC(pDC);//创建DC CBitmap bmpDraw; bmpDraw.LoadBitmap(ID_BMP) ;//装入DDB CBitmap* pbmpOld=memDC.SelectObject(&bmpDraw) ; //保存原有DDB,并选入新DDB入DC pDC->BitBlt(0,0,20,20,&memDC,0,0,SRCCOPY) ; //将源DC(0,0,20,20)复制到目的DC(0,0,20,20) pDC->BitBlt(20,20,40,40,&memDC,0,0,SRCAND); //将源DC(0,0,20,20)和目的DC(20,20,40,40)区域进行AND操作 memDC.SelectObject(pbmpOld) ;//选入原DDB } (图标并不是一个GDI对象,所以不需要选入DC)在MFC没有一个专门的图标类,因为图标的操作比较简单,使用HICON CWinApp::LoadIcon( UINT nIDResource )或是HICON CWinApp::LoadStandardIcon( LPCTSTR lpszIconName ) 装入后就可以利用BOOL CDC::DrawIcon( int x, int y, HICON hIcon )绘制。由于在图标可以指定透明区域,所以在某些需要使用非规则图形而且面积不大的时候使用图标会比较简单。下面给出简单的代码: OnDraw(CDC* pDC) { HICON hIcon1=AfxGetApp()->LoadIcon(IDI_I1); HICON hIcon2=AfxGetApp()->LoadIcon(IDI_I2); pDC->DrawIcon(0,0,hIcon1); pDC->DrawIcon(0,40,hIcon2); DestroyIcon(hIcon1); DestroyIcon(hIcon2); } 同样在MFC也没有提供一个DIB的类,所以在使用DIB位图时我们需要自己读取位图文件的头信息,并读入数据,并利用API函数StretchDIBits绘制。位图文件以BITMAPFILEHEADER结构开始,然后是BITMAPINFOHEADER结构和调色版信息和数据,其实位图格式是图形格式最简单的一种,而且也是Windows可以理解的一种。我不详细讲解DIB位图的结构,提供一个CDib类供大家使用,这个类包含了基本的功能如:Load,Save,Draw。DownLoad CDib 4K 2.5 使用各种映射方式 所谓的映射方式简单点讲就是坐标的安排方式,系统默认的映射方式为MM_TEXT即X坐标向右增加,Y坐标向下增加,(0,0)在屏幕左上方,DC的每一点就是屏幕上的一个象素。也许你会认为这种方式下是最好理解的,但是一个点和象素对应的关系在屏幕上看来是正常的,但到了打印机上就会很不正常。因为我们作图是以点为单位并且打印机的分辨率远远比显示器高(800DPI 800点每英寸)所以在打印机上图形看起来就会很小。这样就需要为打印另做一套代码而加大了工作量。如果每个点对应0.1毫米那么在屏幕上的图形就会和打印出来的图形一样大小。 通过int CDC::SetMapMode( int nMapMode )可以指定映射方式,可用的有以下几种: • MM_HIENGLISH 每点对应0.001英寸 Each logical unit is converted to 0.001 inch. Positive x is to the right; positive y is up. • MM_HIMETRIC 每点对应0.001毫米 Each logical unit is converted to 0.01 millimeter. Positive x is to the right; positive y is up. • MM_LOENGLISH 每点对应0.01英寸 Each logical unit is converted to 0.01 inch. Positive x is to the right; positive y is up. • MM_LOMETRIC 每点对应0.001毫米 Each logical unit is converted to 0.1 millimeter. Positive x is to the right; positive y is up. • MM_TEXT 象素对应 Each logical unit is converted to 1 device pixel. Positive x is to the right; positive y is down. 以上几种映射默认的原点在屏幕左上方。除MM_TEXT外都为X坐标向右增加,Y坐标向上增加,和自然坐标是一致的。所以在作图是要注意什么时候应该使用负坐标。而且以上的映射都是X-Y等比例的,即相同的长度在X,Y轴上显示的长度都是相同的。 DownLoad Sample 另外的一种映射方式为MM_ANISOTROPIC,这种方式可以规定不同的长宽比例。在设置这映射方式后必须调用CSize CDC::SetWindowExt( SIZE size )和CSize CDC::SetViewportExt( SIZE size )来设定长宽比例。系统会根据两次设定的长宽的比值来确定长宽比例。下面给出一段代码比较映射前后的长宽比例: OnDraw(CDC* pDC) { CRect rcC1(200,0,400,200); pDC->FillSolidRect(rcC1,RGB(0,0,255)); pDC->SetMapMode(MM_ANISOTROPIC ); CSize sizeO; sizeO=pDC->SetWindowExt(5,5); TRACE("winExt %d %d\n",sizeO.cx,sizeO.cy); sizeO=pDC->SetViewportExt(5,10); TRACE("ViewExt %d %d\n",sizeO.cx,sizeO.cy); CRect rcC(0,0,200,200); pDC->FillSolidRect(rcC,RGB(0,128,0)); } 上面代码在映射后画出的图形将是一个长方形。 DownLoad Sample 最后讲讲视原点(viewport origin),你可以通过调用CPoint CDC::SetViewportOrg( POINT point )重新设置原点的位置,这就相对于对坐标进行了位移。例如你将原点设置在(20,20)那么原来的(0,0)就变成了(-20,-20)。 2.6 多边形和剪贴区域 多边形也是一个GDI对象,同样遵守其他GDI对象的规则,只是通常都不将其选入DC。在MFC多边形有CRgn表示。多边形用来表示一个不同与矩形的区域,和矩形具有相似的操作。如:检测某点是否在内部,并操作等。此外还得到一个包含此多边形的最小矩形。下面介绍一下多边形类的成员函数: • CreateRectRgn 由矩形创建一个多边形 • CreateEllipticRgn 由椭圆创建一个多边形 • CreatePolygonRgn 创建一个有多个点围成的多边形 • PtInRegion 某点是否在内部 • CombineRgn 两个多边形相并 • EqualRgn 两个多边形是否相等 在本节讲演多边形的意义在于重新在窗口作图时提高效率。因为引发窗口重绘的原因是某个区域失效,而失效的区域用多边形来表示。假设窗口大小为500*400当上方的另一个窗口从(0,0,10,10)移动到(20,20,30,30)这时(0,0,10,10)区域就失效了,而你只需要重绘这部分区域而不是所有区域,这样你程序的执行效率就会提高。 通过调用API函数int GetClipRgn( HDC hdc, HRGN hrgn)就可以得到失效区域,但是一般用不着那么精确而只需得到包含该区域的最小矩形就可以了,所以可以利用int CDC::GetClipBox( LPRECT lpRect )完成这一功能。 第三章 文档视结构 3.1 文档 视图 框架窗口间的关系和消息传送规律 在MFCM$引入了文档-视结构的概念,文档相当于数据容器,视相当于查看数据的窗口或是和数据发生交互的窗口。(这一结构在MFC的OLE,ODBC开发时又得到更多的拓展)因此一个完整的应用一般由四个类组成:CWinApp应用类,CFrameWnd窗口框架类,CDocument文档类,CView视类。(VC6支持创建不带文档-视的应用) 在程序运行时CWinApp将创建一个CFrameWnd框架窗口实例,而框架窗口将创建文档模板,然后有文档模板创建文档实例和视实例,并将两者关联。一般来讲我们只需对文档和视进行操作,框架的各种行为已经被MFC安排好了而不需人为干预,这也是M$设计文档-视结构的本意,让我们将注意力放在完成任务上而从界面编写解放出来。 在应用一个视对应一个文档,但一个文档可以包含多个视。一个应用只用一个框架窗口,对多文档界面来讲可能有多个MDI子窗口。每一个视都是一个子窗口,在单文档界面父窗口即是框架窗口,在多文档界面父窗口为MDI子窗口。一个多文档应用可以包含多个文档模板,一个模板定义了一个文档和一个或多个视之间的对应关系。同一个文档可以属于多个模板,但一个模板只允许定义一个文档。同样一个视也可以属于多个文档模板。(不知道我说清楚没有) 接下来看看如何在程序得到各种对象的指针: • 全局函数AfxGetApp可以得到CWinApp应用类指针 • AfxGetApp()->m_pMainWnd为框架窗口指针 • 在框架窗口:CFrameWnd::GetActiveDocument得到当前活动文档指针 • 在框架窗口:CFrameWnd::GetActiveView得到当前活动视指针 • 在视:CView::GetDocument得到对应的文档指针 • 在文档:CDocument::GetFirstViewPosition,CDocument::GetNextView用来遍历所有和文档关联的视。 • 在文档:CDocument::GetDocTemplate得到文档模板指针 • 在多文档界面:CMDIFrameWnd::MDIGetActive得到当前活动的MDI子窗口 一般来讲用户输入消息(如菜单选择,鼠标,键盘等)会先发往视,如果视未处理则会发往框架窗口。所以定义消息映射时定义在视就可以了,如果一个应用同时拥有多个视而当前活动视没有对消息进行处理则消息会发往框架窗口。 3.2 接收用户输入 在视接收鼠标输入: 鼠标消息是我们常需要处理的消息,消息分为:鼠标移动,按钮按下/松开,双击。利用ClassWizard可以轻松的添加这几种消息映射,下面分别讲解每种消息的处理。 WM_MOUSEMOVE对应的函数为OnMouseMove( UINT nFlags, CPoint point ),nFlags表明了当前一些按键的消息,你可以通过“位与”操作进行检测。 • MK_CONTROL Ctrl键是否被按下 Set if the CTRL key is down. • MK_LBUTTON 鼠标左键是否被按下 Set if the left mouse button is down. • MK_MBUTTON 鼠标间键是否被按下 Set if the middle mouse button is down. • MK_RBUTTON 鼠标右键是否被按下 Set if the right mouse button is down. • MK_SHIFT Shift键是否被按下 Set if the SHIFT key is down. point表示当前鼠标的设备坐标,坐标原点对应视左上角。 WM_LBUTTONDOWN/WM_RBUTTONDOWN(鼠标左/右键按下)对应的函数为OnLButtonDown/OnRButtonDown( UINT nFlags, CPoint point )参数意义和OnMouseMove相同。 WM_LBUTTONUP/WM_RBUTTONUP(鼠标左/右键松开)对应的函数为OnLButtonUp/OnRButtonUp( UINT nFlags, CPoint point )参数意义和OnMouseMove相同。 WM_LBUTTONDBLCLK/WM_RBUTTONDBLCLK(鼠标左/右键双击)对应的函数为OnLButtonDblClk/OnRButtonDblClk( UINT nFlags, CPoint point )参数意义和OnMouseMove相同。 下面我用一段伪代码来讲解一下这些消息的用法: 代码的作用是用鼠标拉出一个矩形 global BOOL fDowned;//是否在拉动 global CPoint ptDown;//按下位置 global CPoint ptUp;//松开位置 OnLButtonDown(UINT nFlags, CPoint point) { fDowned=TRUE; ptUp=ptDown=point; DrawRect(); ... } OnMouseMove(UINT nFlags, CPoint point) { if(fDowned) { DrawRect();//恢复上次所画的矩形 ptUp=point; DrawRect();//画新矩形 } } OnLButtonUp(UINT nFlags, CPoint point) { if(fDowned) { DrawRect();//恢复上次所画的矩形 ptUp=point; DrawRect();//画新矩形 fDowned=FALSE; } } DrawRect() {//以反色屏幕的方法画出ptDown,ptUp标记的矩形 CClientDC dc(this); MakeRect(ptDown,ptUp); SetROP(NOT); Rect(); } 坐标间转换:在以上的函数point参数对应的都是窗口的设备坐标,我们应该将设备坐标和逻辑坐标相区别,在图32_g1由于窗口使用了滚动条,所以传入的设备坐标是对应于当前窗口左上角的坐标,没有考虑是否滚动,而逻辑坐标必须考虑滚动后对应的坐标,所以我以黄线虚拟的表达一个逻辑坐标的区域。可以看得出同一点在滚动后的坐标值是不同的,这一规则同样适用于改变了映射方式的窗口,假设你将映射方式设置为每点为0.01毫米,那么设备坐标所对应的逻辑坐标也需要重新计算。进行这种转换需要写一段代码,所幸的是系统提供了进行转换的功能DC的DPtoLP,LPtoDP,下面给出代码完成由设备坐标到逻辑坐标的转换。 图32_g1 CPoint CYourView::FromDP(CPoint point) { CClientDC dc(this); CPoint ptRet=point; dc.PrepareDC();//必须先准备DC,这在使用滚动时让DC重新计算坐标 //如果你作图设置了不同的映射方式,则在下面需要设置 dc.SetMapMode(...) // dc.DPtoLP(&ptRet);//DP->LP进行转换 return ptRet; } 在图32_g1以蓝线标记的是屏幕区域,红线标记的客户区域。利用ScreenToClient,ClientToScreen可以将坐标在这两个区域间转换。 在视接收键盘输入: 键盘消息有三个:键盘被按下/松开,输入字符。其输入字符相当于直接得到用户输入的字符这在不需要处理按键细节时使用,而键盘被按下/松开在按键状态改变时发送。 WM_CHAR对应的函数为OnChar( UINT nChar, UINT nRepCnt, UINT nFlags ),其nChar为被按下的字符,nRepCnt表明在长时间为松开时相当于的按键次数,nFlags的不同位代表不同的含义,在这里一般不使用。 WM_KEYDOWN/WM_KEYUP所对应的函数为OnKeyDown/OnKeyUp( UINT nChar, UINT nRepCnt, UINT nFlags )nChar代表按键的虚拟码值,如VK_ALT为ALT键,VK_CONTROL为Ctrl键。nFlags各位的含义如下: Value Description 0? Scan code (OEM-dependent value). 8 Extended key, such as a function key or a key on the numeric keypad (1 if it is an extended key). 9?0 Not used. 11?2 Used internally by Windows. 13 Context code (1 if the ALT key is held down while the key is pressed; otherwise 0). 14 Previous key state (1 if the key is down before the call, 0 if the key is up). 15 Transition state (1 if the key is being released, 0 if the key is being pressed). 3.3 使用菜单 利用菜单接受用户命令是一很简单的交互方法,同时也是一种很有效的方法。通常菜单作为一资源存储在文件,因此我们可以在设计时就利用资源编辑器设计好一个菜单。关于使用VC设计菜单我就不再多讲了,但你在编写菜单时应该尽量在属性对话框的底部提示(Prompt)处输入文字,这虽然不是必要的,但MFC在有状态栏和工具条的情况下会使用该文字,文字的格式为“状态栏出说明\n工具条提示”。 图33_g1 我们要面临的任务是如何知道用户何时选择了菜单,他选的是什么菜单项。当用户选择了一个有效的菜单项时系统会向应用发送一个WM_COMMAND消息,在消息的参数表明来源。在MFC我们只需要进行一次映射,将某一菜单ID映射到一处理函数,图33_g2。在这里我们在CView的派生类处理菜单消息,同时我对同一ID设置两个消息映射,接下来将这两种映射的作用。 图33_g2 ON_COMMAND 映射的作用为在用户选择该菜单时调用指定的处理函数。如:ON_COMMAND(IDM_COMMAND1, OnCommand1)会使菜单被选择时调用OnCommand1成员函数。 ON_UPDATE_COMMAND_UI(IDM_COMMAND1, OnUpdateCommand1) 映射的作用是在菜单被显示时通过调用指定的函数来进行确定其状态。在这个处理函数你可以设置菜单的允许/禁止状态,其显示字符串是什么,是否在前面打钩。函数的参数为CCmdUI* pCmdUI,CCmdUI是MFC专门为更新命令提供的一个类,你可以调用 • Enable 设置允许/禁止状态 • SetCheck 设置是否在前面打钩 • SetText 设置文字 下面我讲解一个例子:我在CView派生类有一个变量m_fSelected,并且在视处理两个菜单的消息,当IDM_COMMAND1被选时,对m_fSelected进行逻辑非操作,当IDM_COMMAND2被选时出一提示;同时IDM_COMMAND1根据m_fSelected决定菜单显示的文字和是否在前面打上检查符号,IDM_COMMAND2根据m_fSelected的值决定菜单的允许/禁止状态。下面是代码和说明:下载示例代码 17K void CMenuDView::OnCommand1() { m_fSelected=!m_fSelected; TRACE("command1 selected\n"); } void CMenuDView::OnUpdateCommand1(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_fSelected);//决定检查状态 pCmdUI->SetText(m_fSelected?"当前被选":"当前未被选");//决定所显示的文字 } void CMenuDView::OnUpdateCommand2(CCmdUI* pCmdUI) {//决定是否为允许 pCmdUI->Enable(m_fSelected); } void CMenuDView::OnCommand2() {//选时给出提示 AfxMessageBox("你选了command2"); } 接下来再讲一些通过代码操纵菜单的方法,在MFC有一个类CMenu用来处理和菜单有关的功能。在生成一个CMenu对象时你需要从资源装如菜单,通过调用BOOL CMenu::LoadMenu( UINT nIDResource )进行装入,然后你就可以对菜单进行动态的修改,所涉及到的函数有: • CMenu* GetSubMenu( int nPos ) 一位置得到子菜单的指针,因为一个CMenu对象只能表示一个弹出菜单,如果菜单的某一项也为弹出菜单,就需要通过该函数获取指针。 • BOOL AppendMenu( UINT nFlags, UINT nIDNewItem = 0, LPCTSTR lpszNewItem = NULL ) 在末尾添加一项,nFlag为MF_SEPARATOR表示增加一个分隔条,这样其他两个参数将会被忽略;为MF_STRING表示添加一个菜单项uIDNewItem为该菜单的ID命令值;为MF_POPUP表示添加一个弹出菜单项,这时uIDNewItem为另一菜单的句柄HMENU。lpszNewItem为菜单文字说明。 • BOOL InsertMenu( UINT nPosition, UINT nFlags, UINT nIDNewItem = 0, LPCTSTR lpszNewItem = NULL )用于在指定位置插入一菜单,位置由变量nPosition指明。如果nFlags包含MF_BYPOSITION则表明插入在nPosition位置,如果包含MF_BYCOMMAND表示插入在命令ID为nPosition的菜单处。 • BOOL ModifyMenu( UINT nPosition, UINT nFlags, UINT nIDNewItem = 0, LPCTSTR lpszNewItem = NULL )用于修改某一位置的菜单,如果nFlags包含MF_BYPOSITION则表明修改nPosition位置的菜单,如果包含MF_BYCOMMAND表示修改命令ID为nPosition处的菜单。 • BOOL RemoveMenu( UINT nPosition, UINT nFlags )用于删除某一位置的菜单。如果nFlags包含MF_BYPOSITION则表明删除nPosition位置的菜单,如果包含MF_BYCOMMAND表示删除命令ID为nPosition处的菜单。 • BOOL AppendMenu( UINT nFlags, UINT nIDNewItem, const CBitmap* pBmp ) 和 BOOL InsertMenu( UINT nPosition, UINT nFlags, UINT nIDNewItem, const CBitmap* pBmp )可以添加一位图菜单,但这样的菜单在选时只是反色显示,并不美观。 视图是没有菜单的,在框架窗口才有,所以只有用AfxGetApp()->m_pMainWnd->GetMenu()才能得到应用的菜单指针。 最后我讲一下如何在程序弹出一个菜单,你必须先装入一个菜单资源,你必需得到一个弹出菜单的指针然后调用BOOL TrackPopupMenu( UINT nFlags, int x, int y, CWnd* pWnd, LPCRECT lpRect = NULL )弹出菜单,你需要指定(x,y)为菜单弹出的位置,pWnd为接收命令消息的窗口指针。下面有一段代码说明方法,下载示例代码 17K。当然为了处理消息你应该在pWnd指明的窗口对菜单命令消息进行映射。 CMenu menu; menu.LoadMenu(IDR_POPUP); CMenu* pM=menu.GetSubMenu(0); CPoint pt; GetCursorPos(&pt); pM->TrackPopupMenu(TPM_LEFTALIGN,pt.x,pt.y,this); 另一种做法是通过CMenu::CreatePopupMenu()建立一个弹出菜单,然后使用TrackPopupMenu弹出菜单。使用CreatePopupMenu创建的菜单也可以将其作为一个弹出项添加另一个菜单。下面的伪代码演示了如何创建一个弹出菜单并进行修改后弹出: CMenu menu1,menu2; menu1.CreatePopupMenu menu1.InsertMenu(1) menu1.InsertMenu(2) menu1.InsertMenu(3) menu2.CreatePopupMenu menu2.AppendMenu(MF_POPUP,1,menu1.Detach()) 将弹出菜单加入 or InsertMenu... menu2.InsertMenu("string desc"); menu.TrackPopupMenu(...) 3.4 文档,视,框架之间相互作用 一般来说用户的输入/输出基本都是通过视进行,但一些例外的情况下可能需要和框架直接发生作用,而在多视的情况下如何在视之间传递数据。 在使用菜单时大家会发现当一个菜单没有进行映射处理时为禁止状态,在多视的情况下菜单的状态和处理映射是和当前活动视相联系的,这样MFC可以保证视能正确的接收到各种消息,但有时候也会产生不便。有一个解决办法就是在框架对消息进行处理,这样也可以保证当前文档可以通过框架得到当前消息。 在用户进行输入后如何使视的状态得到更新?这个问题在一个文档对应一个视图时是不存在的,但是现在有一个文档对应了两个视图,当在一个视上进行了输入时如何保证另一个视也得到通知呢?MFC的做法是利用文档来处理的,因为文档管理着当前和它联系的视,由它来通知各个视是最合适的。让我们同时看两个函数: • void CView::OnUpdate( CView* pSender, LPARAM lHint, CObject* pHint ) • void CDocument::UpdateAllViews( CView* pSender, LPARAM lHint = 0L, CObject* pHint = NULL ) 当文档的UpdateAllViews被调用时和此文档相关的所有视的OnUpdate都会被调用,而参数lHint和pHint都会被传递。这样一来发生改变视就可以通知其他的兄弟了。那么还有一个问题:如何在OnUpdate知道是那个视图发生了改变呢,这就可以利用pHint参数,只要调用者将this指针赋值给参数就可以了,当然完全可以利用该参数传递更复杂的结构。 视的初始化,当一个文档被打开或是新建一个文档时视图的CView::OnInitialUpdate()会被调用,你可以通过重载该函数对视进行初始化,并在结束前调用父类的OnInitialUpdate,因为这样可以保证OnUpdate会被调用。 文档内容的清除,当文档被关闭时(比如退出或是新建前上一个文档清除)void CDocument::DeleteContents ()会被调用,你可以通过重载该函数来进行清理工作。 在单文档结构上面两点尤其重要,因为软件运行文档对象和视对象只会被产生并删除一次。所以应该将上面两点和C++对象构造和构析分清楚。 最后将一下文档模板(DocTemplate)的作用,文档模板分为两类单文档模板和多文档模板,分别由CSingleDocTemplate和CMultiDocTemplate表示,模板的作用在于记录文档,视,框架之间的对应关系。还有一点就是模板可以记录应用程序可以打开的文件的类型,当打开文件时会根据文档模板的信息选择正确的文档和视。模板是一个比较抽想的概念,一般来说是不需要我们直接进行操作的。 当使用者通过视修改了数据时,应该调用GetDocument()->SetModifiedFlag(TRUE)通知文档数据已经被更新,这样在关闭文档时会自动询问用户是否保存数据。 好象这一节讲的有些乱,大家看后有什么想法和问题请在VCHelp论坛上留言,我会尽快回复并且会对本节内容重新整理和修改。 3.5 利用序列化进行文件读写 在很多应用我们需要对数据进行保存,或是从介质上读取数据,这就涉及到文件的操作。我们可以利用各种文件存取方法完成这些工作,但MFC也提供了一种读写文件的简单方法——“序列化”。序列化机制通过更高层次的接口功能向开发者提供了更利于使用和透明于字节流的文件操纵方法,举一个例来讲你可以将一个字串写入文件而不需要理会具体长度,读出时也是一样。你甚至可以对字符串数组进行操作。在MFC提供的可自动分配内存的类的支持下你可以更轻松的读/写数据。你也可以根据需要编写你自己的具有序列化功能的类。 序列化在最低的层次上应该被需要序列化的类支持,也就是说如果你需要对一个类进行序列化,那么这个类必须支持序列化。当通过序列化进行文件读写时你只需要该类的序列化函数就可以了。 怎样使类具有序列化功能呢?你需要以下的工作: • 该类从CObject派生。 • 在类声明包括DECLARE_SERIAL宏定义。 • 提供一个缺省的构造函数。 • 在类实现Serialze函数 • 使用IMPLEMENT_SERIAL指明类名和版本号 下面的代码建立了一个简单身份证记录的类,同时也能够支持序列化。 in H struct strPID { char szName[10]; char szID[16]; struct strPID* pNext; }; class CAllPID : public CObject { public: DECLARE_SERIAL(CAllPID) CAllPID(); ~CAllPID(); public:// 序列化相关 struct strPID* pHead; //其他的成员函数 void Serialize(CArchive& ar); }; in CPP IMPLEMENT_SERIAL(CAllPID,CObject,1) // version is 1,版本用于读数据时的检测 void CAllPID::Serialize(CArchive& ar) { int iTotal; if(ar.IsStoring()) {//保存数据 iTotal=GetTotalID();//得到链表的记录数量 arr<26;i++) ar<>iTotal; for(int i=0;i26;j++) ar>>*(((BYTE*)pID)+j);//读一个strPID所有的数据 //修改链表 } } } 当然上面的代码很不完整,但已经可以说明问题。这样CAllPID就是一个可以支持序列化的类,并且可以根据记录的数量动态分配内存。在序列化我们使用了CArchive类,该类用于在序列化时提供读写支持,它重载了<>运算符号,并且提供Read和Write函数对数据进行读写。 下面看看如何在文档使用序列化功能,你只需要修改文档类的Serialize(CArchive& ar)函数,并调用各个进行序列化的类的Serial进行数据读写就可以了。当然你也可以在文档类的内部进行数据读写,下面的代码利用序列化功能读写数据: class CYourDoc : public CDocument { void Serialize(CArchive& ar); CString m_szDesc; CAllPID m_allPID; ...... } void CYourDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) {//由于CString对CArchive定义了<>操作符号,所以可以直接利用>>和<< ar<>m_szDesc; } m_allPID.Serialize(ar);//调用数据类的序列化函数 3.6 MFC所提供的各种视类介绍 MFC提供了丰富的视类供开发者使用,下面对各个类进行介绍: CView类是最基本的视类只支持最基本的操作。 CScrollView类提供了滚动的功能,你可以利用void CScrollView::SetScrollSizes( int nMapMode, SIZE sizeTotal, const SIZE& sizePage = sizeDefault, const SIZE& sizeLine = sizeDefault )设置滚动尺寸,和坐标映射模式。但是在绘图和接收用户输入时需要对坐标进行转换。请参见3.2 接收用户输入。 CFormView类提供用户在资源文件定义界面的能力,并可以将子窗口和变量进行绑定。通过UpdateData函数让数据在变量和子窗口间交换。 CTreeView类利用TreeCtrl界面作为视界面,通过调用CTreeCtrl& CTreeView::GetTreeCtrl( ) const得到CTreeCtrl的引用。 CListView类利用ListCtrl界面作为视界面,通过调用CTreeCtrl& CTreeView::GetTreeCtrl( ) const得到CListCtrl的引用。 CEditView类利用Edit接收用户输入,它具有输入框的一切功能。通过调用CEdit& CEditView::GetEditCtrl( ) const得到Edit&的引用。void CEditView::SetPrinterFont( CFont* pFont )可以设置打印字体。 CRichEditView类作为Rich Text Edit(富文本输入)的视类,提供了可以按照格式显示文本的能力,在使用时需要CRichEditDoc的支持。 第四章 窗口控件 4.1 Button 按钮窗口(控件)在MFC使用CButton表示,CButton包含了三种样式的按钮,Push Button,Check Box,Radio Box。所以在利用CButton对象生成按钮窗口时需要指明按钮的风格。 创建按钮:BOOL CButton::Create( LPCTSTR lpszCaption, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID );其lpszCaption是按钮上显示的文字,dwStyle为按钮风格,除了Windows风格可以使用外(如WS_CHILD|WS_VISUBLE|WS_BORDER)还有按钮专用的一些风格。 • BS_AUTOCHECKBOX 检查框,按钮的状态会自动改变 Same as a check box, except that a check mark appears in the check box when the user selects the box; the check mark disappears the next time the user selects the box. • BS_AUTORADIOBUTTON 圆形选择按钮,按钮的状态会自动改变 Same as a radio button, except that when the user selects it, the button automatically highlights itself and removes the selection from any other radio buttons with the same style in the same group. • BS_AUTO3STATE 允许按钮有三种状态即:选,未选,未定 Same as a three-state check box, except that the box changes its state when the user selects it. • BS_CHECKBOX 检查框 Creates a small square that has text displayed to its right (unless this style is combined with the BS_LEFTTEXT style). • BS_DEFPUSHBUTTON 默认普通按钮 Creates a button that has a heavy black border. The user can select this button by pressing the ENTER key. This style enables the user to quickly select the most likely option (the default option). • BS_LEFTTEXT 左对齐文字 When combined with a radio-button or check-box style, the text appears on the left side of the radio button or check box. • BS_OWNERDRAW 自绘按钮 Creates an owner-drawn button. The framework calls the DrawItem member function when a visual aspect of the button has changed. This style must be set when using the CBitmapButton class. • BS_PUSHBUTTON 普通按钮 Creates a pushbutton that posts a WM_COMMAND message to the owner window when the user selects the button. • BS_RADIOBUTTON 圆形选择按钮 Creates a small circle that has text displayed to its right (unless this style is combined with the BS_LEFTTEXT style). Radio buttons are usually used in groups of related but mutually exclusive choices. • BS_3STATE 允许按钮有三种状态即:选,未选,未定 Same as a check box, except that the box can be dimmed as well as checked. The dimmed state typically is used to show that a check box has been disabled. rect为窗口所占据的矩形区域,pParentWnd为父窗口指针,nID为该窗口的ID值。 获取/改变按钮状态:对于检查按钮和圆形按钮可能有两种状态,选和未选,如果设置了BS_3STATE或BS_AUTO3STATE风格就可能出现第三种状态:未定,这时按钮显示灰色。通过调用int CButton::GetCheck( ) 得到当前是否被选,返回0:未选,1:选,2:未定。调用void CButton::SetCheck( int nCheck );设置当前选状态。 处理按钮消息:要处理按钮消息需要在父窗口进行消息映射,映射宏为ON_BN_CLICKED( id, memberFxn )id为按钮的ID值,就是创建时指定的nID值。处理函数原型为afx_msg void memberFxn( ); 4.2 Static Box 静态文本控件的功能比较简单,可作为显示字符串,图标,位图用。创建一个窗口可以使用成员函数: BOOL CStatic::Create( LPCTSTR lpszText, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID = 0xffff ); 其dwStyle将指明该窗口的风格,除了子窗口常用的风格WS_CHILD,WS_VISIBLE外,你可以针对静态控件指明专门的风格。 • SS_CENTER,SS_LEFT,SS_RIGHT 指明字符显示的对齐方式。 • SS_GRAYRECT 显示一个灰色的矩形 • SS_NOPREFIX 如果指明该风格,对于字符&将直接显示,否则&将作为转义符,&将不显示而在其后的字符将有下划线,如果需要直接显示&必须使用&&表示。 • SS_BITMAP 显示位图 • SS_ICON 显示图标 • SS_CENTERIMAGE 图象居显示 控制显示的文本利用成员函数SetWindowText/GetWindowText用于设置/得到当前显示的文本。 控制显示的图标利用成员函数SetIcon/GetIcon用于设置/得到当前显示的图标。 控制显示的位图利用成员函数SetBitmap/GetBitmap用于设置/得到当前显示的位图。下面一段代码演示如何创建一个显示位图的静态窗口并设置位图 CStatic* pstaDis=new CStatic; pstaDis->Create("",WS_CHILD|WS_VISIBLE|SS_BITMAP|SSCENTERIMAGE, CRect(0,0,40,40),pWnd,1); CBitmap bmpLoad; bmpLoad.LoadBitmap(IDB_TEST); pstaDis->SetBitmap(bmpLoad.Detach()); 4.3 Edit Box Edit窗口是用来接收用户输入最常用的一个控件。创建一个输入窗口可以使用成员函数: BOOL CEdit::Create( LPCTSTR lpszText, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID = 0xffff ); 其dwStyle将指明该窗口的风格,除了子窗口常用的风格WS_CHILD,WS_VISIBLE外,你可以针对输入控件指明专门的风格。 • ES_AUTOHSCROLL,ES_AUTOVSCROLL 指明输入文字超出显示范围时自动滚动。 • ES_CENTER,ES_LEFT,ES_RIGHT 指定对齐方式 • ES_MULTILINE 是否允许多行输入 • ES_PASSWORD 是否为密码输入框,如果指明该风格则输入的文字显示为* • ES_READONLY 是否为只读 • ES_UPPERCASE,ES_LOWERCASE 显示大写/小写字符 控制显示的文本利用成员函数SetWindowText/GetWindowText用于设置/得到当前显示的文本。 通过GetLimitText/SetLimitText可以得到/设置在输入框输入的字符数量。 由于在输入时用户可能选择某一段文本,所以通过void CEdit::GetSel( int& nStartChar, in
Radmin自动登陆器 v3.0 - By: ybmj@vip.163.com 20150615 By: ybmj@vip.163.com , http://dep.yibinu.cn/wgzxnew/ 1、程序功能和使用环境介绍 2、程序操作方法介绍 3、登录信息文件RadminM.txt介绍 4、登录信息文件RadminM.txt的转换和编制 5、v3.0版新增解锁远程桌面功能 6、相关配置和多种语言支持介绍 7、免责申明 1、程序功能和使用环境介绍 (1)、程序功能 为了安全高效地使用Radmin Viewer来自动登录和管理多台服务器,故编制RadminM (Radmin Connection Manager,Radmin自动登录器)。 v3.0版的可执行文件是RadminM.exe,一台电脑只能运行一个实例,再次运行只是将已运行的实例调到前台。v3.0版之前的老版本的可执行文件是RadminM2.exe。 新版的功能已经比较完善,基本上可以代替Radmin Viewer 3.5进行管理(除Intel AMT功能外),另外还增加了一些实用功能,支持Windows Xp、Vista、Win7、Win8、2003、2000、9x及相应Windows Server版等操作系统。 (2)、程序使用环境要求 使用前请将Radmin Viewer 3.5的Radmin.exe文件直接拷贝到该目录,其它Radmin Viewer 3.x版本也可以,文版、英文版均可; 请设置防火墙允许Radmin.exe和RadminM.exe(仅扫描功能用)访问网络; 若要用到聊天、语音聊天、传送信息等连接模式,必须将相应的8个dll文件也拷贝到该目录:ChatLPCx.dll、raudiox.dll、rchatx.dll、unicows.dll、vcintcx.dll、vcintsx.dll、voicex.dll、WinLpcDl.dll。 (3)、Radmin Server使用权限设置(新版本可选) 注意:在v1.5及以前的老版本,Radmin Server被控端必须将“使用权限...”(Permissions)设置为“Windows NT 安全性”(Security),如果设置为“Radmin安全性”(Security)将不能实现自动登录功能。在新版本,这两种安全性模式下,都可以实现自动登录功能。 (4)、开发环境 v1.5及以前的老版本用AutoIt语言开发,AutoIt是解释性语言,功能和稳定性有限,并且一些防病毒软件会报警。 为了在功能和稳定性方面进一步提高和改进,v2.0版使用VC++ Unicode(MFC)编程,程序在编译时已经集成了VC运行库,可独立运行。 由于MFC越益臃肿笨重,为了提高稳定性和效率,v3.0版使用WTL VC++ Unicode编程,程序短小精悍、可独立运行。WTL是Windows Template Library,可参见 http://wtl.sourceforge.net/ 。 2、程序操作方法介绍 (1)、程序的鼠标操作 * 双击某条记录以默认模式自动连接(等待6秒);若该记录包含私有代理将自动进行代理连接(代理登录和目标登录各等待6秒); * 左上角的选择框或主菜单都可以选择默认连接模式; * 先右击某条记录(或F9)填为强制代理(支持域名),并选强制代理选项,便可对另一条记录强制进行代理连接(将忽略私有代理); * 支持鼠标滚轮; * 主菜单和右键菜单均可完成本程序的常规操作;记录窗格的右键菜单或单击工具栏的相应按钮可直接选择进行指定模式的连接(将忽略默认连接模式); * 主菜单的“配置”菜单可以选择程序的各项相关配置; * 工具栏各个按钮的功能均有提示; * 单击工具栏上的“显示隐藏树状目录”按钮可以显示隐藏目录树窗格,目录树窗格的右键菜单可完成目录树的一些常规操作; * 单击工具栏上的“选择切换图标查看模式”按钮可以切换或选择记录窗格的图标查看模式; * 记录窗格和目录树窗格都支持鼠标拖放功能,强烈建议用户使用该功能前备份RadminM.txt,以免损坏或丢失数据;直接鼠标拖放为移动,Ctrl+鼠标拖放为复制。拖放时状态栏有提示信息; * 程序启动时,记录自动按记录名称升序排列;在记录窗格单击列表框某列表头,可以按该列进行记录排序,再次单击可以反向排序。 (2)、程序的常用快捷键 * Enter :以默认模式连接记录; * Insert :新建记录; * Ctrl+e :编辑记录; * Ctrl+c
Radmin自动登陆器 v3.0 - By: ybmj@vip.163.com 20180106 By: ybmj@vip.163.com , http://dep.yibinu.cn/wgzxnew/ 1、程序功能和使用环境介绍 2、程序操作方法介绍 3、登录信息文件RadminM.txt介绍 4、登录信息文件RadminM.txt的转换和编制 5、v3.0版新增解锁 远程桌面功能 6、相关配置和多种语言支持介绍 7、免责申明 1、程序功能和使用环境介绍 (1)、程序功能 为了安全高效地使用Radmin Viewer来自动登录和管理多台服务器,故编制RadminM (Radmin Connection Manager,Radmin自动登录器)。 v3.0版的可执行文件是RadminM.exe,一台电脑只能运行一个实例,再次运行只是将已运行的实例调到前台。v3.0版之前的老版本的可执行文件是RadminM2.exe。 新版的功能已经比较完善,基本上可以代替Radmin Viewer 3.5进行管理(除Intel AMT功能外),另外还增加了一些实用功能,支持Windows Xp、Vista、Win7、Win8、2003、2000、9x及相应Windows Server版等操作系统。 (2)、程序使用环境要求 使用前请将Radmin Viewer 3.5的Radmin.exe文件直接拷贝到该目录,其它Radmin Viewer 3.x版本也可以,文版、英文版均可; 请设置防火墙允许Radmin.exe和RadminM.exe(仅扫描功能用)访问网络; 若要用到聊天、语音聊天、传送信息等连接模式,必须将相应的8个dll文件也拷贝到该目录:ChatLPCx.dll、raudiox.dll、rchatx.dll、unicows.dll、vcintcx.dll、vcintsx.dll、voicex.dll、WinLpcDl.dll。 (3)、Radmin Server使用权限设置(新版本可选) 注意:在v1.5及以前的老版本,Radmin Server被控端必须将“使用权限...”(Permissions)设置为“Windows NT 安全性”(Security),如果设置为“Radmin安全性”(Security)将不能实现自动登录功能。在新版本,这两种安全性模式下,都可以实现自动登录功能。 (4)、开发环境 v1.5及以前的老版本用AutoIt语言开发,AutoIt是解释性语言,功能和稳定性有限,并且一些防病毒软件会报警。 为了在功能和稳定性方面进一步提高和改进,v2.0版使用VC++ Unicode(MFC)编程,程序在编译时已经集成了VC运行库,可独立运行。 由于MFC越益臃肿笨重,为了提高稳定性和效率,v3.0版使用WTL VC++ Unicode编程,程序短小精悍、可独立运行。WTL是Windows Template Library,可参见 http://wtl.sourceforge.net/ 。 2、程序操作方法介绍 (1)、程序的鼠标操作 * 双击某条记录以默认模式自动连接(等待6秒);若该记录包含私有代理将自动进行代理连接(代理登录和目标登录各等待6秒); * 左上角的选择框或主菜单都可以选择默认连接模式; * 先右击某条记录(或F9)填为强制代理(支持域名),并选强制代理选项,便可对另一条记录强制进行代理连接(将忽略私有代理); * 支持鼠标滚轮; * 主菜单和右键菜单均可完成本程序的常规操作;记录窗格的右键菜单或单击工具栏的相应按钮可直接选择进行指定模式的连接(将忽略默认连接模式); * 主菜单的“配置”菜单可以选择程序的各项相关配置; * 工具栏各个按钮的功能均有提示; * 单击工具栏上的“显示隐藏树状目录”按钮可以显示隐藏目录树窗格,目录树窗格的右键菜单可完成目录树的一些常规操作; * 单击工具栏上的“选择切换图标查看模式”按钮可以切换或选择记录窗格的图标查看模式; * 记录窗格和目录树窗格都支持鼠标拖放功能,强烈建议用户使用该功能前备份RadminM.txt,以免损坏或丢失数据;直接鼠标拖放为移动,Ctrl+鼠标拖放为复制。拖放时状态栏有提示信息; * 程序启动时,记录自动按记录名称升序排列;在记录窗格单击列表框某列表头,可以按该列进行记录排序,再次单击可以反向排序。 (2)、程序的常用快捷键 * Enter :以默认模式连接记录; * Insert :新建记录; * Ctrl+e :编辑记录; * Ctrl+c :复制记录; * Ctrl+x :剪切记录; * Ctrl+v :粘贴记录; * Delete :删除记录或目录(在记录窗格),或删除树状目录(在目录树窗格); * F1 :显示程序信息; * F2 :更名树状目录; * F3 :单条扫描(等待5秒,用于扫描网速较慢的记录); * F5 :全部扫描(多线程同时扫描,每条记录等待5秒); 扫描过程左下角状态栏会有提示,扫描完成后提示消失,扫描过程建议不要新建、修改、删除、粘贴、剪切、排序记录,不然可能出现扫描结果错乱,其它功能可正常使用; * F7 :新建树状目录; * F9 :将选记录填为强制代理(主菜单上“强制代理信息”项显示将从[无]变为[有],打开该菜单可查看信息); * Ctrl+- :隐藏窗口到系统托盘; * Ctrl+= :显示窗口; * 双击系统托盘图标可隐藏或显示窗口; * 窗口大小可调整,支持最大化和还原; * 支持Home、End、PageUp、PageDown等操作。 3、登录信息文件RadminM.txt介绍 (1)、RadminM.txt内容说明 登录信息存放在RadminM.txt文件,若没有会自动创建,密码用RC4加密,请用户注意保管。RadminM.txt是遵循CSV格式的ANSI文本文件,所有字段内容都不能包含英文惊叹号“!”、英文逗号“,”、竖线分隔符“|”。 第一行为登录记录各字段的名称。每行存放一条记录,每条记录包含用17个英文逗号分隔的18个字段。 RecordName 记录名称是关键字段,支持文记录名称,不能为空、不要有重名; IP、Port、User、Password 分别是IP地址、端口、用户名、密码。IP地址不能为空,若端口为空程序将使用缺省端口4899; Domain 是域名,该字段有内容在登录时便会自动填写; ColorDepth 是在“完全控制”或“仅限查看”连接模式,指定传输图像的色彩深度。色彩深度大小与传输速度成反比; Updates 是在“完全控制”或“仅限查看”连接模式,指定屏幕每秒最大刷新率,为1到100之间的数值; UnlockDesktop 是在“完全控制”连接模式连接成功后,若远程桌面已登录锁定、且焦点位于密码输入框,可用连接Radmin的密码解锁远程桌面、或 (当服务器端为Radmin Server v3.5时) 先锁定再解锁远程桌面。具体配置参见后面的介绍; Fullscreen 是在“完全控制”或“仅限查看”连接模式,以全屏幕方式、或全屏伸展方式显示远程PC窗口; Nofullkbcontrol 是在“完全控制”连接模式,阻止系统热键(如ALT-TAB)传递到远程PC; Monitor 是在“完全控制”或“仅限查看”连接模式,若远程PC有多个监视器,可指定显示其某个监视器上的图像。比如:/monitor"\\.\DISPLAY1"。注意:只能指定在已连接窗口的菜单显示出来的监视器; Sendrequest 是请求Radmin服务器发送Radmin服务器激活文件。将忽略其它选项。详情请参见Radmin帮助文档; Pbpath 是以指定的电话薄文件启动Radmin Viewer。比如:/pbpath"C:\my.rpb"。将忽略其它选项; Proxy 是记录的私有代理信息。私有代理格式:记录名称+目录路径。需要先将某条已有记录设置为强制代理,再选作私有代理。 AsProxyBy 是被用作私有代理字段。是指该记录被其它哪些记录用作私有代理,由程序自动处理(只读); Memory 是备注字段; TreePath 是目录路径字段,由若干英文惊叹号“!”(目录分隔符)分隔的字符串构成,支持文目录名,如根目录下DirA子目录下的DirB子目录:!DirA!DirB 。 (2)、私有代理字段Proxy 本程序除了支持强制代理外,每条记录都可以指定私有代理。Proxy字段便是存放用作私有代理的记录信息,只能有一条;注意:只能从已有记录指定私有代理;Proxy字段的格式:记录名称+目录路径;建议先将某条已有记录设置为强制代理,再到新建记录或编辑记录对话框填写为私有代理;当然,若熟悉后也可以手工填写。 (3)、被用作私有代理字段AsProxyBy AsProxyBy是被用作私有代理字段,用于存放该记录被其它哪些记录用作私有代理的信息,多条记录间用竖线分隔符“|”分隔,由程序自动处理(只读);该字段主要用于当该记录名称或目录路径更改时,程序会自动更新将该记录用作私有代理的其它记录的私有代理信息;建议用户不要随意修改RadminM.txt文件该字段的内容,不然可能会出现程序功能错乱。 (4)、格式符合要求的RadminM.txt文件示范 RecordName,IP,Port,User,Password,Domain,ColorDepth,Updates,UnlockDesktop,Fullscreen,Nofullkbcontrol,Monitor,Sendrequest,Pbpath,Proxy,AsProxyBy,Memory,TreePath sample01,192.168.0.6,4899,user01,,,,,,,,,,,,,,! sample02,192.168.0.8,4899,user02,,,,,,,,,,,,,,!DirA!DirB sample03,192.168.0.9,4899,user03,,,,,,,,,,,,,,!DirC!DirD 4、登录信息文件RadminM.txt的转换和编制 (1)、V2.0转V3.0记录文件 单击主菜单、帮助的“V2.0转V3.0记录文件”菜单项,可以将RadminM V2.0的记录文件转换为RadminM V3.0的记录文件。执行转换之前,请先备份好RadminM.txt。新生成的文件可能覆盖RadminM.txt。 (2)、v1.5的RadminM.txt文件需先转换为v2.0的格式,再导入新版本v3.0使用 v1.5的RadminM.txt简单修改一下就可以转换为v2.0的格式。修改的具体方法是: (A)用UltraEdit编辑器打开v1.5的RadminM.txt(用其它编辑器也可参照完成类似修改); (B)Ctrl+R调出替换对话框,在上面需要替换栏输入:^p ,在下面替换为栏输入:,!^p ,(这里,^p代表回车换行),设置好后再单击“全部替换”按钮即可,需要时可单击“帮助”按钮查看帮助信息; (C)将第一行末尾的 “!” 手工改为 “TreePath”; (D)处理完后保存为RadminM.txt。 用其它编辑器也可参照完成类似修改。转换完成后,再用上面介绍的“V2.0转V3.0记录文件”菜单项导入v3.0使用。 (3)、用记事本、UltraEdit、Excel等编制RadminM.txt RadminM.txt可以用记事本、UltraEdit、Excel等编制。也可将已有RadminM.txt导入Excel处理,具体方法是: (A)启动Excel,选择菜单“数据->导入外部数据->导入数据”,选择RadminM.txt文件; (B)文本导入向导第1步,直接单击“下一步”; (C)第2步必须选“逗号”分隔符,再单击“下一步”; (D)第3步必须将所有18列都设置为文本,依次选下面数据预览里的各列,再选择右上面列数据格式里的“文本”。全部设置好后,再单击“完成”、“确定”即可成功导入; (E)处理完后须保存为CSV格式文件,再更名为RadminM.txt便可使用。 5、v3.0版新增解锁远程桌面功能 (1)、解锁远程桌面功能简介 当以“完全控制”连接远程PC成功后,若远程桌面已登录锁定、且焦点位于密码输入框,可用连接Radmin的密码解锁远程桌面、或 (当服务器端为Radmin Server v3.5时) 先锁定再解锁远程桌面。 要正常使用这一功能,必须满足以下条件:远程PC已经登录、锁定远程桌面的用户密码与连接Radmin的密码一致、远程桌面的焦点位于密码输入框。 (2)、可能存在的安全隐患 注意:当服务器端为Radmin Server v3.5之前的老版本、解锁前远程桌面并未锁定而焦点又正好位于文本编辑框,启用该功能可能会出现明文密码。 (3)、相关配置 用户可以为每条记录单独配置解锁远程桌面功能,相关配置信息保存在每条记录的UnlockDesktop字段。慎重起见,默认并未启用该功能。用户可以根据实际情况,单独为每条记录选择不使用(该字段为空白)、或者“UnlockDesktop”、或者“LockThenUnlock”。 该字段为空白,也就是不使用该功能,便不会出现明文密码。 “UnlockDesktop”是指直接解锁远程桌面,适用于Radmin Server各版本,但可能出现明文密码。 “LockThenUnlock”是指若解锁前远程桌面处于未锁定状态、可以先锁定远程桌面再解锁,这样可以避免出现明文密码。但这要求必须使用Radmin Viewer 3.5的Radmin.exe文件,并且只对连接Radmin Server v3.5版本才有效。Radmin Viewer 3.5之前的老版本无法发送锁屏组合键Win+L,Radmin Server v3.5之前的老版本无法接收锁屏组合键Win+L,仍然存在出现明文密码的可能性。 6、相关配置和多种语言支持介绍 (1)、配置文件RadminM.ini 主菜单的“配置”菜单可以选择程序的各项相关配置。程序的各项配置都保存在RadminM.ini配置文件,若不存在程序会自动创建。若由于配置混乱、异常关闭等原因导致程序运行后无法显示主窗口,可以先备份然后删除RadminM.ini文件即可正常运行。 (2)、多种语言支持 本程序使用INI文件实现多种语言支持,每种语言信息用一个扩展名为lng的INI格式文件存放。语言文件可以使用Unicode或ANSI格式,一般建议使用Unicode格式。这种方式具有更多扩展性,用户可以非常简单方便地添加自己的语言文件。 本程序的默认语言是简体文,另外提供英文语言文件English.lng。本程序启动时若没有外部语言文件,将使用内置的默认语言(简体文)。若本程序目录下有*.lng的外部语言,程序启动后便会自动在“关于->语言”菜单下列出外部语言(以语言文件的文件名命名)。用户选择某种外部语言便可以动态切换到新语言界面,无需重新启动程序,用户的语言选择将自动保存到RadminM.ini文件,关闭程序后下次启动也会自动使用用户选择的新语言界面。 用户可以参照English.lng语言文件的格式和内容,方便地编制修改自己的语言文件,比如French.lng。用户只需将自己编制好的语言文件拷贝到本程序目录下,重新启动程序后便会自动在“关于->语言”菜单下列出用户添加的新语言French。选择该语言便可以动态切换到新语言界面,无需重新启动程序,关闭程序后下次启动也会自动使用用户选择的新语言界面。 注意:语言文件间不能有空行,空行就意味文件结束,空行之后就无法查找翻译。若需要空行标识分隔,可以在空行前加英文分号 ;,也即注释行。 语言文件的字符串,若需要前导和后导空格,可以将字符串用英文双引号或英文单引号包含即可。不需要空格的就无需加引号。 本程序的多种语言支持功能参照网友Yonsm提供的方式实现,有兴趣的用户可以访问网站 http://yonsm.net/ini-language-engine/。 (3)、启用Radmin帮助 在本程序,若要启用菜单项“帮助->Radmin帮助”,需要将Radmin的chm帮助拷贝为本程序目录的Radmin35.chm。 7、免责申明 用户可自行斟酌选用该程序,若转载请注明出处。对一切后果,作者不承担任何责任! ======================================================================================== RadminM v3.0 - By: ybmj@vip.163.com 20150615 By: ybmj@vip.163.com , http://dep.yibinu.cn/wgzxnew/ 1. The features and the running environmental of RadminM 2. The operation of RadminM 3. RadminM.txt of login information file 4. Translate and Preparation RadminM.txt 5. UnlockDesktop feature of v3.0 newly additional 6. Related settings and Multilanguage support 7. Disclaimer 1. The features and the running environmental of RadminM (1). The features of RadminM In order to safely and efficiently use Radmin Viewer to automatically login and manage multiple servers, so the program RadminM(Radmin Connection Manager) was intended to develop. The executable file is RadminM.exe of RadminM v3.0. Only one instance can run in a computer, and it only bring the running instance to the foreground if RadminM run again. And the executable file of RadminM before v3.0 is RadminM2.exe. The new version have been more improvement of the function, and user basically can manage instead of Radmin Viewer 3.5 (except Intel AMT technology). And there ars some useful features else. It support for Windows Xp, Vista, Win7, Win8, 2003, 2000, 9x and the corresponding version of Windows Server operating systems. (2). The environmental requirements of RadminM running Before use, please copy the Radmin.exe of Radmin Viewer 3.5 to this directory, Other Radmin Viewer 3.x versions of Chinese or English are also available. Please set the firewall to allow Radmin.exe and RadminM.exe (only scan function used) to access the network. To use Text Chat, Voice Chat, Send Message such as connection mode, user must copy also corresponding 8 dll files to this directory: ChatLPCx.dll, raudiox.dll, rchatx.dll, unicows.dll, vcintcx.dll, vcintsx.dll, voicex.dll, WinLpcDl.dll. (3). To set Radmin Server's Permissions(Option in the new version) Note: In v1.5 and previous versions, Radmin Server's "Permissions ..." must be set to "Windows NT security", RadminM can not be automatically login feature if it was set to "Radmin security". The new version can be automatically login in these two security modes. (4). The development environments of RadminM RadminM v1.5 and the previous version is developed by AutoIt language. As AutoIt is an interpreted language, it is limited in the functionality and stability, and some anti-virus software will alarm. In order to further improve the functionality and stability, the new version using VC++ UNICODE(MFC) programming environment. The program had already integrated VC runtime library when it was compiled, it can run independently. Because the MFC is more and more bloated and heavy, in order to further improve the stability and efficiency, v3.0 using WTL VC++ UNICODE programming environment. The program dapper, and can run independently. WTL is the abbreviation of Windows Template Library, user may refer to http://wtl.sourceforge.net/ . 2. The operation of RadminM (1). The mouse operation of RadminM * Double-click a record, RadminM will automatically connect in the default mode(wait 6 second), or RadminM will automatically Proxy connect if the record has Proxy(each of Proxy login and Target login wait respectively 6 second). * You may select the default connection mode at the ComboBox of the top left corner or the main menu. * Right-click a record (or F9) to fill as Forced Proxy (supports domain name) at first, and check the CheckBox of Forced Proxy or the menu item, you can connect another record via Forced Proxy (the Proxy will be ignored). * Mouse wheel support. * You can complete the normal operation with the main menu and right-click menu. By the right-click menu of records pane (Right Pane) or click the corresponding button on the toolbar, you can directly connect in specify mode (the default connection mode will be ignored). * There is the function prompted for each button on the toolbar. * Clicking "Show or Hide Tree" button on the toolbar will show or hide the directory tree pane. You may complete some normal trees operations by right-click menu in trees pane (Left Pane). * Records pane and trees pane support the mouse drag-and-drop function. To avoid damage or loss of data, we strongly recommended to backup RadminM.txt before useing this function. Directly drag-and-drop to move, Ctrl + drag-and-drop to copy. There is the prompted information at the status bar as drag-and-drop. * Records automatically sort in ascending order by record name when the program starts. Clicking the table head of listctrl in records pane will sort records according to this column, and clicking again will sort reverse. (2). The common Shortcuts of RadminM: * Enter : automatically connection in the default mode. * Insert : new record. * Ctrl+e : edit record. * Ctrl+c : copy record. * Ctrl+x : cut record. * Ctrl+v : paste record. * Delete : delete record and subdir (in records pane). delete subdir (in trees pane). * F1 : help information. * F2 : rename subdir (in trees pane) or edit record(in records pane). * F3 : scan one record (wait 5 seconds, used for slowly network). * F5 : scan all records by multithreading (wait 5 second for each record). There is prompt at the status bar of bottom left corner when the scan is processing, and prompt will disappear after the scan has finished. We are not recommended to create, modify, delete, paste, cut, sort records when the scan is processing, otherwise the scan results may appear confusion. But other functions may be used normally. * F7 : new subdir. * F9 : fill the selected record as Forced Proxy. (The "Forced-Proxy" item of the main menu will show from [No] to [Yes]. To click the menu, you can view the information.) * Ctrl+- : hide RadminM window to the system tray. * Ctrl+= : show RadminM window. * Double-click the system tray icon to hide or show RadminM window. * RadminM window is resizable, maximize and restore support. * RadminM supports Home, End, PageUp, PageDown, etc. 3. RadminM.txt of login information file (1). RadminM.txt description Login information is stored in RadminM.txt file. RadminM will automatically create if RadminM.txt is not exist. PassWord is encrypted by RC4, user keep attention to store. RadminM.txt is text file to follow CSV (ANSI) formatted. The contents of all field can not contain English exclamation mark "!", English comma ",", vertical separator "|". The first line is the the names of login record fields. There is only a record each line, what contains 18 fields delimited by 17 English comma. RecordName (Record Name) is the key field, support Chinese record name, but can not be empty, do not have the same record name. IP, Port, User, Password are the IP address, port, username, password. IP address can not be empty.The program will use the default port 4899 if the Port is empty. Domain is the domain name, it will be used to automatically fill in the login if Domain has content. ColorDepth is used with the "Full Control" connection mode (no mode switches) or "View Only" connection mode (the "/noinput" switch). Defines the color depth of images that Radmin Server will transfer to Radmin Viewer. ColorDepth is in inverse proportion to transmission rate. Updates is used with "Full Control" connection mode or "View Only" connection mode. Will display the remote computer window with no more than the specified number of updates per second. That is the maximum updates per second. Please input number between 1 to 100. UnlockDesktop is used with "Full Control" connection mode . After "Full Control" connection has successed, it can unlock the remote desktop with the connection password if the remote desktop has locked and the focus is in the password input box, or lock first the remote desktop then unlock when remote PC run Radmin Server v3.5. Fullscreen is used with the "Full Control" connection mode or "View Only" connection mode. Will display the remote computer window in full screen, or expanding the image if the screens resolution of the remote and local computer differs. Nofullkbcontrol is used with "Full Control" mode. The key prevents the transfer of system hotkeys (such as ALT-TAB) to the remote computer. Monitor is used with "Full Control" or "View Only" connection mode. If there are several monitors on the remote computer, this key makes it possible for you to display an image on one of them. Example: /monitor"\\.\DISPLAY1" . Note, you can only specify a monitor from which show on the connected window's menu. Sendrequest is to send specified Radmin Server activation request file to the Famatech Activation Server and saves received license file. Will ignore other options. Please refer to Radmin help for details. Pbpath is to start Radmin Viewer with specified phonebook file. Example: /pbpath"C:\my.rpb". Will ignore other options. Proxy is used to store private-proxy information of the record. Proxy Format: RecordName+TreePath. User need to select a record and set to forced-proxy at first, then fill as Proxy in the NewRecord or EditRecord dialog. AsProxyBy is being used as Proxy field. It is automatically processed by the program (Read Only). Memory is memo field. TreePath is the directory path field. TreePath is a string that consist of multiple strings division by English exclamation mark '!' (directory separator). It support Chinese directory name. Example: !DirA!DirB, the DirB under the DirA under the root. (2). The Proxy field This program not noly supports forced-proxy, each record but also can be specified private-proxy (abbreviated as Proxy). The Proxy field is used to store private-proxy information of the record, it can be only one. Note, user can only specify Proxy from existing records. Proxy Format: RecordName+TreePath. We recommend to select a record and set to forced-proxy at first, then fill as Proxy in the NewRecord or EditRecord dialog. Of course, you can also fill it by hand after familiar. (3). The AsProxyBy field The AsProxyBy field is being used as Proxy field, it is used to store the information which other records use this record as Proxy. Multiple records are delimited with vertical separator "|". It is automatically processed by the program (Read Only). This field is mainly used to automatically update the Proxy information of other records which use this record as Proxy when this record's RecordName or TreePath is changed. We recommend that user do not arbitrarily modify the contents of this field in RadminM.txt, otherwise the program may appear functional disorder. (4). Example: a fitting format RadminM.txt RecordName,IP,Port,User,Password,Domain,ColorDepth,Updates,UnlockDesktop,Fullscreen,Nofullkbcontrol,Monitor,Sendrequest,Pbpath,Proxy,AsProxyBy,Memory,TreePath sample01,192.168.0.6,4899,user01,,,,,,,,,,,,,,! sample02,192.168.0.8,4899,user02,,,,,,,,,,,,,,!DirA!DirB sample03,192.168.0.9,4899,user03,,,,,,,,,,,,,,!DirC!DirD 4. Translate and Preparation RadminM.txt (1). V2.0 to V3.0 RadminM.txt User can translate RadminM V2.0 record file to V3.0 by "V2.0 to V3.0 RadminM.txt" menu of Help in the main menu. Please backup RadminM.txt before performing the transfer. New file may overwrite RadminM.txt. (2). The v1.5 RadminM.txt need to translate to v2.0 fromat, then it can be translated to v3.0 The v1.5 RadminM.txt can be used in the new version after simply modification. The modification procedure is: (A) To open the v1.5 RadminM.txt by UltraEdit editor. (B) Ctrl+R to bring up the Replace dialog box, input in the above Find What pane: ^p, input in the below Replace With pane: ,!^p . (^p is CRLF here.). After properly setting, then click "Replace All" button. You may click the "Help" button to get the help information if you need. (C) Replace "!" with "TreePath" by hand at end of the first line. (D) Save the file to RadminM.txt after processed. You can also refer to complete a similar modification with other editors. After this, user can Translate it to v3.0 by fore-mentioned "V2.0 to V3.0 RadminM.txt" menu. Then it can be used in the new version v3.0. (3). To prepare RadminM.txt by Notepad, UltraEdit, Excel, etc RadminM.txt can be prepared using Notepad, UltraEdit, Excel, etc. You can also import RadminM.txt to Excel to process. The procedure is: (A) Start Excel, then click the menu "Data|Import External Data|Import Data", select RadminM.txt file. (B) Text Import Wizard - Step 1 of 3, direct click "Next". (C) Text Import Wizard - Step 2 of 3, you must check the "Comma" delimiter and then click "Next". (D) Text Import Wizard - Step 3 of 3, you must set all 18 columns to text format. You should select the data columns in turn below Data preview, and then check the "Text" above Column data format. After properly setting, to click "Finish" and "OK" to complete successfully import. (E) The file must save as CSV format after processed. The file can be used for RadminM after direct renamed to RadminM.txt. 5. UnlockDesktop feature of v3.0 newly additional (1). The UnlockDesktop feature After "Full Control" connection has successed, it can unlock the remote desktop with the connection password if the remote desktop has locked and the focus is in the password input box, or lock first the remote desktop then unlock when remote PC run Radmin Server v3.5. To successfully use this feature, there must be conditions: remote PC has already logined, and the password for locked remote desktop as same as the password for conneced Radmin Server, and the focus of remote desktop is in the password input box. (2). Possible security risk Note, there may be plaintext password, if the Radmin Server is old version before v3.5, and the remote desktop has not locked before to unlock, and the focus of remote desktop is exactly on a text edit box. (3). UnlockDesktop setting User can singly prepare UnlockDesktop setting for every record. UnlockDesktop setting is saved in UnlockDesktop filed of every record in RadminM.txt. To be deliberate, this feature is not enabled by default. User can choose and use this feature according to the actual situation. User can choose disabled this feature(Blank filed), or "UnlockDesktop", or "LockThenUnlock" for every record. When this filed is blank, that is disabled this feature, and there wiil not be plaintext password. When this filed is “UnlockDesktop”, that is directly unlock remote desktop. That suit each versions of Radmin Server. But there may be plaintext password. When this filed is “LockThenUnlock”, that is locked first the remote desktop then unlocked if the remote desktop has not locked before to unlock. This will avoid to appear plaintext password. But it must use the Radmin.exe of Radmin Viewer 3.5, and it only suit to connect Radmin Server v3.5. It can not send the Win+L LockScreen combination key to the remote computer by old version before Radmin Viewer 3.5. It can not receive the Win+L LockScreen combination key by old version before Radmin Server 3.5. The possibility to appear plaintext password still exists. 6. Related settings and Multilanguage support (1). Settings file RadminM.ini User may select the RadminM's related settings by Settings Menu of the main menu. All RadminM's related settings is stored in file RadminM.ini. RadminM will automatically create if RadminM.ini is not exist. If the RadminM main window can not display, it maybe the settings is confusion, or abnormal shutdown. User may backup the file RadminM.ini and then delete it. After this, user can run RadminM normal. (2). Multilanguage support This program achieve multilingual support by INI file. Each language information is stored in an INI format file with .lng extension. Language files is text file to follow Unicode or ANSI formatted. We generally recommended to use Unicode format. This mode has more scalability, the user can very simply and easily add your own language file. The default language of this program is simplified Chinese, there is other English language file English.lng as example. If there is no external language file, RadminM use the built-in default language(Chinese) when the program starts. If there are any *.lng external languages under this program directory, RadminM will automatically load and list in the "Settings|Language" menu after the program starts. In this menu, the name of external language is used the filename of the language file. By choosed a language in the menu, users can dynamically switch to the new language interface without having to restart the program. The user's language selection will be automatically saved to RadminM.ini file. After closeing the program, RadminM will automatically use the new language interface selected by the user when the next start. Users can refer to the format and content of English.lng, and easily prepared to modify their own language files, such French.lng. Users only need to copy the prepared language file to this program directory. After restarting the program, RadminM will automatically load and list the new language added by the user (such French) in the "Settings|Language" menu. By choosed the new language in the menu, users can dynamically switch to the new language interface without having to restart the program. After closeing the program, RadminM will automatically use the new language interface selected by the user when the next start. Note, Intermediate of language file can not have blank lines. Blank lines will mean the end of the file, the items will not be able to find the translation after the blank line. If you need a blank line identification or separator, you can add english semicolon in front of blank line. That is a comment line. If you need leading or rear guide space, the string of language file may be contained with double quotes or single quotes.Or it need not quotation marks. This program's multilingual support features achieve by reference of Yonsm's way, interested users may visit the website http://yonsm.net/ini-language-engine/. (3). Use Radmin Help If user want to use Help->Radmin Help of this program, user need to copy the chm help file to Radmin35.chm in the RadminM directory. 7. Disclaimer Users can choose and use this program at their discretion. Please indicate the source if reproduced. The author does not assume any responsibility for all the consequences!
CISCO 技术大集合 {适合你们的技术} 二、命令状态 1. router> 路由器处于用户命令状态,这时用户可以看路由器的连接状态,访问其它网络和主机,但不能看到和更改路由器的设置内容。 2. router# 在router>提示符下键入enable,路由器进入特权命令状态router#,这时不但可以执行所有的用户命令,还可以看到和更改路由器的设置内容。 3. router(config)# 在router#提示符下键入configure terminal,出现提示符router(config)#,此时路由器处于全局设置状态,这时可以设置路由器的全局参数。 4. router(config-if)#; router(config-line)#; router(config-router)#;… 路由器处于局部设置状态,这时可以设置路由器某个局部的参数。 5. > 路由器处于RXBOOT状态,在开机后60秒内按ctrl-break可进入此状态,这时路由器不能完成正常的功能,只能进行软件升级和手工引导。 6. 设置对话状态 这是一台新路由器开机时自动进入的状态,在特权命令状态使用SETUP命令也可进入此状态,这时可通过对话方式对路由器进行设置。   返回目录 三、设置对话过程 1. 显示提示信息 2. 全局参数的设置 3. 接口参数的设置 4. 显示结果 利用设置对话过程可以避免手工输入命令的烦琐,但它还不能完全代替手工设置,一些特殊的设置还必须通过手工输入的方式完成。 进入设置对话过程后,路由器首先会显示一些提示信息: --- System Configuration Dialog --- At any point you may enter a question mark '?' for help. Use ctrl-c to abort configuration dialog at any prompt. Default settings are in square brackets '[]'. 这是告诉你在设置对话过程的任何地方都可以键入“?”得到系统的帮助,按ctrl-c可以退出设置过程,缺省设置将显示在‘[]’。然后路由器会问是否进入设置对话: Would you like to enter the initial configuration dialog? [yes]: 如果按y或回车,路由器就会进入设置对话过程。首先你可以看到各端口当前的状况: First, would you like to see the current interface summary? [yes]: Any interface listed with OK? value "NO" does not have a valid configuration Interface IP-Address OK? Method Status Protocol Ethernet0 unassigned NO unset up up Serial0 unassigned NO unset up up ……… ……… … …… … … 然后,路由器就开始全局参数的设置: Configuring global parameters: 1.设置路由器名: Enter host name [Router]: 2.设置进入特权状态的密文(secret),此密文在设置以后不会以明文方式显示: The enable secret is a one-way cryptographic secret used instead of the enable password when it exists. Enter enable secret: cisco 3.设置进入特权状态的密码(password),此密码只在没有密文时起作用,并且在设置以后会以明文方式显示: The enable password is used when there is no enable secret and when using older software and some boot images. Enter enable password: pass 4.设置虚拟终端访问时的密码: Enter virtual terminal password: cisco 5.询问是否要设置路由器支持的各种网络协议: Configure SNMP Network Management? [yes]: Configure DECnet? [no]: Configure AppleTalk? [no]: Configure IPX? [no]: Configure IP? [yes]: Configure IGRP routing? [yes]: Configure RIP routing? [no]: ……… 6.如果配置的是拨号访问服务器,系统还会设置异步口的参数: Configure Async lines? [yes]: 1) 设置线路的最高速度: Async line speed [9600]: 2) 是否使用硬件流控: Configure for HW flow control? [yes]: 3) 是否设置modem: Configure for modems? [yes/no]: yes 4) 是否使用默认的modem命令: Configure for default chat script? [yes]: 5) 是否设置异步口的PPP参数: Configure for Dial-in IP SLIP/PPP access? [no]: yes 6) 是否使用动态IP地址: Configure for Dynamic IP addresses? [yes]: 7) 是否使用缺省IP地址: Configure Default IP addresses? [no]: yes 8) 是否使用TCP头压缩: Configure for TCP Header Compression? [yes]: 9) 是否在异步口上使用路由表更新: Configure for routing updates on async links? [no]: y 10) 是否设置异步口上的其它协议。 接下来,系统会对每个接口进行参数的设置。 1.Configuring interface Ethernet0: 1) 是否使用此接口: Is this interface in use? [yes]: 2) 是否设置此接口的IP参数: Configure IP on this interface? [yes]: 3) 设置接口的IP地址: IP address for this interface: 192.168.162.2 4) 设置接口的IP子网掩码: Number of bits in subnet field [0]: Class C network is 192.168.162.0, 0 subnet bits; mask is /24 在设置完所有接口的参数后,系统会把整个设置对话过程的结果显示出来: The following configuration command script was created: hostname Router enable secret 5 $1$W5Oh$p6J7tIgRMBOIKVXVG53Uh1 enable password pass ………… 请注意在enable secret后面显示的是乱码,而enable password后面显示的是设置的内容。 显示结束后,系统会问是否使用这个设置: Use this configuration? [yes/no]: yes 如果回答yes,系统就会把设置的结果存入路由器的NVRAM,然后结束设置对话过程,使路由器开始正常的工作。 返回目录   四、常用命令 1. 帮助 在IOS操作,无论任何状态和位置,都可以键入“?”得到系统的帮助。 2. 改变命令状态 任务 命令 进入特权命令状态 enable 退出特权命令状态 disable 进入设置对话状态 setup 进入全局设置状态 config terminal 退出全局设置状态 end 进入端口设置状态 interface type slot/number 进入子端口设置状态 interface type number.subinterface [point-to-point | multipoint] 进入线路设置状态 line type slot/number 进入路由设置状态 router protocol 退出局部设置状态 exit 3. 显示命令 任务 命令 查看版本及引导信息 show version 查看运行设置 show running-config 查看开机设置 show startup-config 显示端口信息 show interface type slot/number 显示路由信息 show ip router 4. 拷贝命令 用于IOS及CONFIG的备份和升级 5. 网络命令 任务 命令 登录远程主机 telnet hostname|IP address 网络侦测 ping hostname|IP address 路由跟踪 trace hostname|IP address   6. 基本设置命令 任务 命令 全局设置 config terminal 设置访问用户及密码 username username password password 设置特权密码 enable secret password 设置路由器名 hostname name 设置静态路由 ip route destination subnet-mask next-hop 启动IP路由 ip routing 启动IPX路由 ipx routing 端口设置 interface type slot/number 设置IP地址 ip address address subnet-mask 设置IPX网络 ipx network network 激活端口 no shutdown 物理线路设置 line type number 启动登录进程 login [local|tacacs server] 设置登录密码 password password   五、配置IP寻址   1. IP地址分类 IP地址分为网络地址和主机地址二个部分,A类地址前8位为网络地址,后24位为主机地址,B类地址16位为网络地址,后16位为主机地址,C类地址前24位为网络地址,后8位为主机地址,网络地址范围如下表所示: 种类 网络地址范围 A  1.0.0.0 到126.0.0.0有效 0.0.0.0 和127.0.0.0保留 B 128.1.0.0到191.254.0.0有效 128.0.0.0和191.255.0.0保留 C 192.0.1.0 到223.255.254.0有效 192.0.0.0和223.255.255.0保留 D 224.0.0.0到239.255.255.255用于多点广播 E 240.0.0.0到255.255.255.254保留 255.255.255.255用于广播 2. 分配接口IP地址 任务 命令 接口设置 interface type slot/number 为接口设置IP地址 ip address ip-address mask 掩玛(mask)用于识别IP地址的网络地址位数,IP地址(ip-address)和掩码(mask)相与即得到网络地址。 3. 使用可变长的子网掩码 通过使用可变长的子网掩码可以让位于不同接口的同一网络编号的网络使用不同的掩码,这样可以节省IP地址,充分利用有效的IP地址空间。 如下图所示: Router1和Router2的E0端口均使用了C类地址192.1.0.0作为网络地址,Router1的E0的网络地址为192.1.0.128,掩码为255.255.255.192, Router2的E0的网络地址为192.1.0.64,掩码为255.255.255.192,这样就将一个C类网络地址分配给了二个网,既划分了二个子网,起到了节约地址的作用。 4. 使用网络地址翻译(NAT) NAT(Network Address Translation)起到将内部私有地址翻译成外部合法的全局地址的功能,它使得不具有合法IP地址的用户可以通过NAT访问到外部Internet. 当建立内部网的时候,建议使用以下地址组用于主机,这些地址是由Network Working Group(RFC 1918)保留用于私有网络地址分配的. l Class A:10.1.1.1 to 10.254.254.254 l Class B:172.16.1.1 to 172.31.254.254 l Class C:192.168.1.1 to 192.168.254.254 命令描述如下: 任务 命令 定义一个标准访问列表 access-list access-list-number permit source [source-wildcard] 定义一个全局地址池 ip nat pool name start-ip end-ip {netmask netmask | prefix-length prefix-length} [type rotary] 建立动态地址翻译 ip nat inside source {list {access-list-number | name} pool name [overload] | static local-ip global-ip} 指定内部和外部端口 ip nat {inside | outside} 如下图所示, 路由器的Ethernet 0端口为inside端口,即此端口连接内部网络,并且此端口所连接的网络应该被翻译,Serial 0端口为outside端口,其拥有合法IP地址(由NIC或服务提供商所分配的合法的IP地址),来自网络10.1.1.0/24的主机将从IP地址池c2501选择一个地址作为自己的合法地址,经由Serial 0口访问Internet。命令ip nat inside source list 2 pool c2501 overload的参数overload,将允许多个内部地址使用相同的全局地址(一个合法IP地址,它是由NIC或服务提供商所分配的地址)。命令ip nat pool c2501 202.96.38.1 202.96.38.62 netmask 255.255.255.192定义了全局地址的范围。 设置如下: ip nat pool c2501 202.96.38.1 202.96.38.62 netmask 255.255.255.192 interface Ethernet 0 ip address 10.1.1.1 255.255.255.0 ip nat inside ! interface Serial 0 ip address 202.200.10.5 255.255.255.252 ip nat outside ! ip route 0.0.0.0 0.0.0.0 Serial 0 access-list 2 permit 10.0.0.0 0.0.0.255 ! Dynamic NAT ! ip nat inside source list 2 pool c2501 overload line console 0 exec-timeout 0 0 ! line vty 0 4 end   六、配置静态路由 通过配置静态路由,用户可以人为地指定对某一网络访问时所要经过的路径,在网络结构比较简单,且一般到达某一网络所经过的路径唯一的情况下采用静态路由。 任务 命令 建立静态路由 ip route prefix mask {address | interface} [distance] [tag tag] [permanent] Prefix :所要到达的目的网络 mask :子网掩码 address :下一个跳的IP地址,即相邻路由器的端口地址。 interface :本地网络接口 distance :管理距离(可选) tag tag :tag值(可选) permanent :指定此路由即使该端口关掉也不被移掉。 以下在Router1上设置了访问192.1.0.64/26这个网下一跳地址为192.200.10.6,即当有目的地址属于192.1.0.64/26的网络范围的数据报,应将其路由到地址为192.200.10.6的相邻路由器。在Router3上设置了访问192.1.0.128/26及192.200.10.4/30这二个网下一跳地址为192.1.0.65。由于在Router1上端口Serial 0地址为192.200.10.5,192.200.10.4/30这个网属于直连的网,已经存在访问192.200.10.4/30的路径,所以不需要在Router1上添加静态路由。 Router1: ip route 192.1.0.64 255.255.255.192 192.200.10.6 Router3: ip route 192.1.0.128 255.255.255.192 192.1.0.65 ip route 192.200.10.4 255.255.255.252 192.1.0.65 同时由于路由器Router3除了与路由器Router2相连外,不再与其他路由器相连,所以也可以为它赋予一条默认路由以代替以上的二条静态路由, ip route 0.0.0.0 0.0.0.0 192.1.0.65 即只要没有在路由表里找到去特定目的地址的路径,则数据均被路由到地址为192.1.0.65的相邻路由器。 返回目录   一、HDLC   HDLC是CISCO路由器使用的缺省协议,一台新路由器在未指定封装协议时默认使用HDLC封装。 1. 有关命令 端口设置 任务 命令 设置HDLC封装 encapsulation hdlc 设置DCE端线路速度 clockrate speed 复位一个硬件接口 clear interface serial unit 显示接口状态 show interfaces serial [unit] 1 注:1.以下给出一个显示Cisco同步串口状态的例子. Router#show interface serial 0 Serial 0 is up, line protocol is up Hardware is MCI Serial Internet address is 150.136.190.203, subnet mask is 255.255.255.0 MTU 1500 bytes, BW 1544 Kbit, DLY 20000 usec, rely 255/255, load 1/255 Encapsulation HDLC, loopback not set, keepalive set (10 sec) Last input 0:00:07, output 0:00:00, output hang never Output queue 0/40, 0 drops; input queue 0/75, 0 drops Five minute input rate 0 bits/sec, 0 packets/sec Five minute output rate 0 bits/sec, 0 packets/sec 16263 packets input, 1347238 bytes, 0 no buffer Received 13983 broadcasts, 0 runts, 0 giants 2 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 2 abort 22146 packets output, 2383680 bytes, 0 underruns 0 output errors, 0 collisions, 2 interface resets, 0 restarts 1 carrier transitions 2. 举例     设置如下: Router1: interface Serial0 ip address 192.200.10.1 255.255.255.0 clockrate 1000000 Router2: interface Serial0 ip address 192.200.10.2 255.255.255.0 ! 3. 举例使用E1线路实现多个64K专线连接. 相关命令: 任务 命令 进入controller配置模式 controller {t1 | e1} number 选择帧类型 framing {crc4 | no-crc4} 选择line-code类型 linecode {ami | b8zs | hdb3} 建立逻辑通道组与时隙的映射 channel-group number timeslots range1 显示controllers接口状态 show controllers e1 [slot/port]2 注: 1. 当链路为T1时,channel-group编号为0-23, Timeslot范围1-24; 当链路为E1时, channel-group编号为0-30, Timeslot范围1-31. 2.使用show controllers e1观察controller状态,以下为帧类型为crc4时controllers正常的状态. Router# show controllers e1 e1 0/0 is up. Applique type is Channelized E1 - unbalanced Framing is CRC4, Line Code is HDB3 No alarms detected. Data in current interval (725 seconds elapsed): 0 Line Code Violations, 0 Path Code Violations 0 Slip Secs, 0 Fr Loss Secs, 0 Line Err Secs, 0 Degraded Mins 0 Errored Secs, 0 Bursty Err Secs, 0 Severely Err Secs, 0 Unavail Secs Total Data (last 24 hours) 0 Line Code Violations, 0 Path Code Violations, 0 Slip Secs, 0 Fr Loss Secs, 0 Line Err Secs, 0 Degraded Mins, 0 Errored Secs, 0 Bursty Err Secs, 0 Severely Err Secs, 0 Unavail Secs 以下例子为E1连接3条64K专线, 帧类型为NO-CRC4,非平衡链路,路由器具体设置如下: shanxi#wri t Building configuration... Current configuration: ! version 11.2 no service udp-small-servers no service tcp-small-servers ! hostname shanxi ! enable secret 5 $1$XN08$Ttr8nfLoP9.2RgZhcBzkk/ enable password shanxi ! ! ip subnet-zero ! controller E1 0 framing NO-CRC4 channel-group 0 timeslots 1 channel-group 1 timeslots 2 channel-group 2 timeslots 3 ! interface Ethernet0 ip address 133.118.40.1 255.255.0.0 media-type 10BaseT ! interface Ethernet1 no ip address shutdown ! interface Serial0:0 ip address 202.119.96.1 255.255.255.252 no ip mroute-cache ! interface Serial0:1 ip address 202.119.96.5 255.255.255.252 no ip mroute-cache ! interface Serial0:2 ip address 202.119.96.9 255.255.255.252 no ip mroute-cache ! no ip classless ip route 133.210.40.0 255.255.255.0 Serial0:0 ip route 133.210.41.0 255.255.255.0 Serial0:1 ip route 133.210.42.0 255.255.255.0 Serial0:2 ! line con 0 line aux 0 line vty 0 4 password shanxi login ! end 广域网设置:   一、HDLC   HDLC是CISCO路由器使用的缺省协议,一台新路由器在未指定封装协议时默认使用HDLC封装。 1. 有关命令 端口设置 任务 命令 设置HDLC封装 encapsulation hdlc 设置DCE端线路速度 clockrate speed 复位一个硬件接口 clear interface serial unit 显示接口状态 show interfaces serial [unit] 1 注:1.以下给出一个显示Cisco同步串口状态的例子. Router#show interface serial 0 Serial 0 is up, line protocol is up Hardware is MCI Serial Internet address is 150.136.190.203, subnet mask is 255.255.255.0 MTU 1500 bytes, BW 1544 Kbit, DLY 20000 usec, rely 255/255, load 1/255 Encapsulation HDLC, loopback not set, keepalive set (10 sec) Last input 0:00:07, output 0:00:00, output hang never Output queue 0/40, 0 drops; input queue 0/75, 0 drops Five minute input rate 0 bits/sec, 0 packets/sec Five minute output rate 0 bits/sec, 0 packets/sec 16263 packets input, 1347238 bytes, 0 no buffer Received 13983 broadcasts, 0 runts, 0 giants 2 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 2 abort 22146 packets output, 2383680 bytes, 0 underruns 0 output errors, 0 collisions, 2 interface resets, 0 restarts 1 carrier transitions 2. 举例     设置如下: Router1: interface Serial0 ip address 192.200.10.1 255.255.255.0 clockrate 1000000 Router2: interface Serial0 ip address 192.200.10.2 255.255.255.0 ! 3. 举例使用E1线路实现多个64K专线连接. 相关命令: 任务 命令 进入controller配置模式 controller {t1 | e1} number 选择帧类型 framing {crc4 | no-crc4} 选择line-code类型 linecode {ami | b8zs | hdb3} 建立逻辑通道组与时隙的映射 channel-group number timeslots range1 显示controllers接口状态 show controllers e1 [slot/port]2 注: 1. 当链路为T1时,channel-group编号为0-23, Timeslot范围1-24; 当链路为E1时, channel-group编号为0-30, Timeslot范围1-31. 2.使用show controllers e1观察controller状态,以下为帧类型为crc4时controllers正常的状态. Router# show controllers e1 e1 0/0 is up. Applique type is Channelized E1 - unbalanced Framing is CRC4, Line Code is HDB3 No alarms detected. Data in current interval (725 seconds elapsed): 0 Line Code Violations, 0 Path Code Violations 0 Slip Secs, 0 Fr Loss Secs, 0 Line Err Secs, 0 Degraded Mins 0 Errored Secs, 0 Bursty Err Secs, 0 Severely Err Secs, 0 Unavail Secs Total Data (last 24 hours) 0 Line Code Violations, 0 Path Code Violations, 0 Slip Secs, 0 Fr Loss Secs, 0 Line Err Secs, 0 Degraded Mins, 0 Errored Secs, 0 Bursty Err Secs, 0 Severely Err Secs, 0 Unavail Secs 以下例子为E1连接3条64K专线, 帧类型为NO-CRC4,非平衡链路,路由器具体设置如下: shanxi#wri t Building configuration... Current configuration: ! version 11.2 no service udp-small-servers no service tcp-small-servers ! hostname shanxi ! enable secret 5 $1$XN08$Ttr8nfLoP9.2RgZhcBzkk/ enable password shanxi ! ! ip subnet-zero ! controller E1 0 framing NO-CRC4 channel-group 0 timeslots 1 channel-group 1 timeslots 2 channel-group 2 timeslots 3 ! interface Ethernet0 ip address 133.118.40.1 255.255.0.0 media-type 10BaseT ! interface Ethernet1 no ip address shutdown ! interface Serial0:0 ip address 202.119.96.1 255.255.255.252 no ip mroute-cache ! interface Serial0:1 ip address 202.119.96.5 255.255.255.252 no ip mroute-cache ! interface Serial0:2 ip address 202.119.96.9 255.255.255.252 no ip mroute-cache ! no ip classless ip route 133.210.40.0 255.255.255.0 Serial0:0 ip route 133.210.41.0 255.255.255.0 Serial0:1 ip route 133.210.42.0 255.255.255.0 Serial0:2 ! line con 0 line aux 0 line vty 0 4 password shanxi login ! end 返回目录   二、PPP   PPP(Point-to-Point Protocol)是SLIP(Serial Line IP protocol)的继承者,它提供了跨过同步和异步电路实现路由器到路由器(router-to-router)和主机到网络(host-to-network)的连接。 CHAP(Challenge Handshake Authentication Protocol)和PAP(Password Authentication Protocol) (PAP)通常被用于在PPP封装的串行线路上提供安全性认证。使用CHAP和PAP认证,每个路由器通过名字来识别,可以防止未经授权的访问。 CHAP和PAP在RFC 1334上有详细的说明。 1. 有关命令 端口设置 任务 命令 设置PPP封装 encapsulation ppp1 设置认证方法 ppp authentication {chap | chap pap | pap chap | pap} [if-needed][list-name | default] [callin] 指定口令 username name password secret 设置DCE端线路速度 clockrate speed 注:1、要使用CHAP/PAP必须使用PPP封装。在与非Cisco路由器连接时,一般采用PPP封装,其它厂家路由器一般不支持Cisco的HDLC封装协议。 2. 举例 路由器Router1和Router2的S0口均封装PPP协议,采用CHAP做认证,在Router1应建立一个用户,以对端路由器主机名作为用户名,即用户名应为router2。同时在Router2应建立一个用户,以对端路由器主机名作为用户名,即用户名应为router1。所建的这两用户的password必须相同。 设置如下: Router1: hostname router1 username router2 password xxx interface Serial0 ip address 192.200.10.1 255.255.255.0 clockrate 1000000 ppp authentication chap ! Router2: hostname router2 username router1 password xxx interface Serial0 ip address 192.200.10.2 255.255.255.0 ppp authentication chap !   返回目录   三、x.25 1. X25技术 X.25规范对应OSI三层,X.25的第三层描述了分组的格式及分组交换的过程。X.25的第二层由LAPB(Link Access Procedure, Balanced)实现,它定义了用于DTE/DCE连接的帧格式。X.25的第一层定义了电气和物理端口特性。 X.25网络设备分为数据终端设备(DTE)、数据电路终端设备(DCE)及分组交换设备(PSE)。DTE是X.25的末端系统,如终端、计算机或网络主机,一般位于用户端,Cisco路由器就是DTE设备。DCE设备是专用通信设备,如调制解调器和分组交换机。PSE是公共网络的主干交换机。 X.25定义了数据通讯的电话网络,每个分配给用户的x.25 端口都具有一个x.121地址,当用户申请到的是SVC(交换虚电路)时,x.25一端的用户在访问另一端的用户时,首先将呼叫对方x.121地址,然后接收到呼叫的一端可以接受或拒绝,如果接受请求,于是连接建立实现数据传输,当没有数据传输时挂断连接,整个呼叫过程就类似我们拨打普通电话一样,其不同的是x.25可以实现一点对多点的连接。其x.121地址、htc均必须与x.25服务提供商分配的参数相同。X.25 PVC(永久虚电路),没有呼叫的过程,类似DDN专线。 2. 有关命令: 任务 命令 设置X.25封装 encapsulation x25 [dce] 设置X.121地址 x25 address x.121-address 设置远方站点的地址映射 x25 map protocol address [protocol2 address2[...[protocol9 address9]]] x121-address [option] 设置最大的双向虚电路数 x25 htc citcuit-number1 设置一次连接可同时建立的虚电路数 x25 nvc count2 设置x25在清除空闲虚电路前的等待周期 x25 idle minutes 重新启动x25,或清一个svc,启动一个pvc相关参数 clear x25 {serial number | cmns-interface mac-address} [vc-number] 3 清x25虚电路 clear x25-vc 显示接口及x25相关信息 show interfaces serial show x25 interface show x25 map show x25 vc 注:1、虚电路号从1到4095,Cisco路由器默认为1024,国内一般分配为16。 2、虚电路计数从1到8,缺省为1。 3、在改变了x.25各层的相关参数后,应重新启动x25(使用clear x25 {serial number | cmns-interface mac-address} [vc-number]或clear x25-vc命令),否则新设置的参数可能不能生效。同时应对照服务提供商对于x.25交换机端口的设置来配置路由器的相关参数,若出现参数不匹配则可能会导致连接失败或其它意外情况。 3. 实例: 3.1. 在以下实例每二个路由器间均通过svc实现连接。 路由器设置如下: Router1: interface Serial0 encapsulation x25 ip address 192.200.10.1 255.255.255.0 x25 address 110101 x25 htc 16 x25 nvc 2 x25 map ip 192.200.10.2 110102 broadcast x25 map ip 192.200.10.3 110103 broadcast ! Router2: interface Serial0 encapsulation x25 ip address 192.200.10.2 255.255.255.0 x25 address 110102 x25 htc 16 x25 nvc 2 x25 map ip 192.200.10.1 110101 broadcast x25 map ip 192.200.10.3 110103 broadcast ! Router: interface Serial0 encapsulation x25 ip address 192.200.10.3 255.255.255.0 x25 address 110103 x25 htc 16 x25 nvc 2 x25 map ip 192.200.10.1 110101 broadcast x25 map ip 192.200.10.2 110102 broadcast ! 相关调试命令: clear x25-vc show interfaces serial show x25 map show x25 route show x25 vc 3.2. 在以下实例路由器router1和router2均通过svc与router连接,但router1和router2不通过svc直接连接,此三个路由器的串口运行RIP路由协议,使用了子接口的概念。由于使用子接口,router1和router2均学习到了访问对方局域网的路径,若不使用子接口,router1和router2将学不到到对方局域网的路由。 子接口(Subinterface)是一个物理接口上的多个虚接口,可以用于在同一个物理接口上连接多个网。我们知道为了避免路由循环,路由器支持split horizon法则,它只允许路由更新被分配到路由器的其它接口,而不会再分配路由更新回到此路由被接收的接口。 无论如何,在广域网环境使用基于连接的接口(象 X.25和Frame Relay),同一接口通过虚电路(vc)连接多台远端路由器时,从同一接口来的路由更新信息不可以再被发回到相同的接口,除非强制使用分开的物理接口连接不同的路由器。Cisco提供子接口(subinterface)作为分开的接口对待。你可以将路由器逻辑地连接到相同物理接口的不同子接口, 这样来自不同子接口的路由更新就可以被分配到其他子接口,同时又满足split horizon法则。 Router1: interface Serial0 encapsulation x25 ip address 192.200.10.1 255.255.255.0 x25 address 110101 x25 htc 16 x25 nvc 2 x25 map ip 192.200.10.3 110103 broadcast ! router rip network 192.200.10.0 ! Router2: interface Serial0 encapsulation x25 ip address 192.200.11.2 255.255.255.0 x25 address 110102 x25 htc 16 x25 nvc 2 x25 map ip 192.200.11.3 110103 broadcast ! router rip network 192.200.11.0 ! Router: interface Serial0 encapsulation x25 x25 address 110103 x25 htc 16 x25 nvc 2 ! interface Serial0.1 point-to-point ip address 192.200.10.3 255.255.255.0 x25 map ip 192.200.10.1 110101 broadcast ! interface Serial0.2 point-to-point ip address 192.200.11.3 255.255.255.0 x25 map ip 192.200.11.2 110102 broadcast ! router rip network 192.200.10.0 network 192.200.11.0 ! 返回目录   帧继是一种高性能的WAN协议,它运行在OSI参考模型的物理层和数据链路层。它是一种数据包交换技术,是X.25的简化版本。它省略了X.25的一些强健功能,如提供窗口技术和数据重发技术,而是依靠高层协议提供纠错功能,这是因为帧继工作在更好的WAN设备上,这些设备较之X.25的WAN设备具有更可靠的连接服务和更高的可靠性,它严格地对应于OSI参考模型的最低二层,而X.25还提供第三层的服务,所以,帧继比X.25具有更高的性能和更有效的传输效率。 帧继广域网的设备分为数据终端设备(DTE)和数据电路终端设备(DCE),Cisco路由器作为 DTE设备。 帧继技术提供面向连接的数据链路层的通信,在每对设备之间都存在一条定义好的通信链路,且该链路有一个链路识别码。这种服务通过帧继虚电路实现,每个帧继虚电路都以数据链路识别码(DLCI)标识自己。DLCI的值一般由帧继服务提供商指定。帧继即支持PVC也支持SVC。 帧继本地管理接口(LMI)是对基本的帧继标准的扩展。它是路由器和帧继交换机之间信令标准,提供帧继管理机制。它提供了许多管理复杂互联网络的特性,其包括全局寻址、虚电路状态消息和多目发送等功能。 2. 有关命令: 端口设置 任务 命令 设置Frame Relay封装 encapsulation frame-relay[ietf] 1 设置Frame Relay LMI类型 frame-relay lmi-type {ansi | cisco | q933a}2 设置子接口 interface interface-type interface-number.subinterface-number [multipoint|point-to-point] 映射协议地址与DLCI frame-relay map protocol protocol-address dlci [broadcast]3 设置FR DLCI编号 frame-relay interface-dlci dlci [broadcast] 注:1.若使Cisco路由器与其它厂家路由设备相连,则使用Internet工程任务组(IETF)规定的帧继封装格式。 2.从Cisco IOS版本11.2开始,软件支持本地管理接口(LMI)“自动感觉”, “自动感觉”使接口能确定交换机支持的LMI类型,用户可以不明确配置LMI接口类型。 3.broadcast选项允许在帧继网络上传输路由广播信息。 3. 帧继point to point配置实例: Router1: interface serial 0 encapsulation frame-relay ! interface serial 0.1 point-to-point ip address 172.16.1.1 255.255.255.0 frame-reply interface-dlci 105 ! interface serial 0.2 point-to-point ip address 172.16.2.1 255.255.255.0 frame-reply interface-dlci 102 ! interface serial 0.3 point-to-point ip address 172.16.4.1 255.255.255.0 frame-reply interface-dlci 104 ! Router2: interface serial 0 encapsulation frame-relay ! interface serial 0.1 point-to-point ip address 172.16.2.2 255.255.255.0 frame-reply interface-dlci 201 ! interface serial 0.2 point-to-point ip address 172.16.3.1 255.255.255.0 frame-reply interface-dlci 203 ! 相关调试命令: show frame-relay lmi show frame-relay map show frame-relay pvc show frame-relay route show interfaces serial go top 4. 帧继 Multipoint 配置实例: Router1: interface serial 0 encapsulation frame-reply ! interface serial 0.1 multipoint ip address 172.16.1.2 255.255.255.0 frame-reply map ip 172.16.1.1 201 broadcast frame-reply map ip 172.16.1.3 301 broadcast frame-reply map ip 172.16.1.4 401 broadcast ! Router2: interface serial 0 encapsulation frame-reply ! interface serial 0.1 multipoint ip address 172.16.1.1 255.255.255.0 frame-reply map ip 172.16.1.2 102 broadcast frame-reply map ip 172.16.1.3 102 broadcast frame-reply map ip 172.16.1.4 102 broadcast ! 五、ISDN   1. 综合数字业务网(ISDN) 综合数字业务网(ISDN)由数字电话和数据传输服务两部分组成,一般由电话局提供这种服务。ISDN的基本速率接口(BRI)服务提供2个B信道和1个D信道(2B+D)。BRI的B信道速率为64Kbps,用于传输用户数据。D信道的速率为16Kbps,主要传输控制信号。在北美和日本,ISDN的主速率接口(PRI)提供23个B信道和1个D信道,总速率可达1.544Mbps,其D信道速率为64Kbps。而在欧洲、澳大利亚等国家,ISDN的PRI提供30个B信道和1个64Kbps D信道,总速率可达2.048Mbps。我国电话局所提供ISDN PRI为30B+D。 2. 基本命令 任务 命令 设置ISDN交换类型 isdn switch-type switch-type1 接口设置 interface bri 0 设置PPP封装 encapsulation ppp 设置协议地址与电话号码的映射 dialer map protocol next-hop-address [name hostname] [broadcast] [dial-string] 启动PPP多连接 ppp multilink 设置启动另一个B通道的阈值 dialer load-threshold load 显示ISDN有关信息 show isdn {active | history | memory | services | status [dsl | interface-type number] | timers} 注:1.交换机类型如下表,国内交换机一般为basic-net3。 按区域分关键字 交换机类型 Australia basic-ts013 Australian TS013 switches Europe basic-1tr6 German 1TR6 ISDN switches basic-nwnet3 Norway NET3 switches (phase 1) basic-net3 NET3 ISDN switches (UK, Denmark, and other nations); covers the Euro-ISDN E-DSS1 signalling system primary-net5 NET5 switches (UK and Europe) vn2 French VN2 ISDN switches vn3 French VN3 ISDN switches Japan ntt Japanese NTT ISDN switches primary-ntt Japanese ISDN PRI switches North America basic-5ess AT&T basic rate switches basic-dms100 NT DMS-100 basic rate switches basic-ni1 National ISDN-1 switches primary-4ess AT&T 4ESS switch type for the U.S. (ISDN PRI only) primary-5ess AT&T 5ESS switch type for the U.S. (ISDN PRI only) primary-dms100 NT DMS-100 switch type for the U.S. (ISDN PRI only) New Zealand basic-nznet3 New Zealand Net3 switches 3. ISDN实现DDR(dial-on-demand routing)实例: 设置如下: Router1: hostname router1 user router2 password cisco ! isdn switch-type basic-net3 ! interface bri 0 ip address 192.200.10.1 255.255.255.0 encapsulation ppp dialer map ip 192.200.10.2 name router2 572 dialer load-threshold 80 ppp multilink dialer-group 1 ppp authentication chap ! dialer-list 1 protocol ip permit ! Router2: hostname router2 user router1 password cisco ! isdn switch-type basic-net3 ! interface bri 0 ip address 192.200.10.2 255.255.255.0 encapsulation ppp dialer map ip 192.200.10.1 name router1 571 dialer load-threshold 80 ppp multilink dialer-group 1 ppp authentication chap ! dialer-list 1 protocol ip permit ! Cisco路由器同时支持回拨功能,我们将路由器Router1作为Callback Server,Router2作为Callback Client。 与回拨相关命令: 任务 命令 映射协议地址和电话号码,并在接口上使用在全局模式下定义的PPP回拨的映射类别。 dialer map protocol address name hostname class classname dial-string 设置接口支持PPP回拨 ppp callback accept 在全局模式下为PPP回拨设置映射类别 map-class dialer classname 通过查找注册在dialer map里的主机名来决定回拨. dialer callback-server [username] 设置接口要求PPP回拨 ppp callback request 设置如下: Router1: hostname router1 user router2 password cisco ! isdn switch-type basic-net3 ! interface bri 0 ip address 192.200.10.1 255.255.255.0 encapsulation ppp dialer map ip 192.200.10.2 name router2 class s3 572 dialer load-threshold 80 ppp callback accept ppp multilink dialer-group 1 ppp authentication chap ! map-class dialer s3 dialer callback-server username dialer-list 1 protocol ip permit ! Router2: hostname router2 user router1 password cisco ! isdn switch-type basic-net3 ! interface bri 0 ip address 192.200.10.2 255.255.255.0 encapsulation ppp dialer map ip 192.200.10.1 name router1 571 dialer load-threshold 80 ppp callback request ppp multilink dialer-group 1 ppp authentication chap ! dialer-list 1 protocol ip permit ! 相关调试命令: debug dialer debug isdn event debug isdn q921 debug isdn q931 debug ppp authentication debug ppp error debug ppp negotiation debug ppp packet show dialer show isdn status 举例:执行debug dialer命令观察router2呼叫router1,router1回拨router2的过程. router1#debug dialer router2#ping 192.200.10.1 router1# 00:03:50: %LINK-3-UPDOWN: Interface BRI0:1, changed state to up 00:03:50: BRI0:1:PPP callback Callback server starting to router2 572 00:03:50: BRI0:1: disconnecting call 00:03:50: %LINK-3-UPDOWN: Interface BRI0:1, changed state to down 00:03:50: BRI0:1: disconnecting call 00:03:50: BRI0:1: disconnecting call 00:03:51: %LINK-3-UPDOWN: Interface BRI0:2, changed state to up 00:03:52: callback to router2 already started 00:03:52: BRI0:2: disconnecting call 00:03:52: %LINK-3-UPDOWN: Interface BRI0:2, changed state to down 00:03:52: BRI0:2: disconnecting call 00:03:52: BRI0:2: disconnecting call 00:04:05: : Callback timer expired 00:04:05: BRI0:beginning callback to router2 572 00:04:05: BRI0: Attempting to dial 572 00:04:05: Freeing callback to router2 572 00:04:05: %LINK-3-UPDOWN: Interface BRI0:1, changed state to up 00:04:05: BRI0:1: No callback negotiated 00:04:05: %LINK-3-UPDOWN: Interface Virtual-Access1, changed state to up 00:04:05: dialer Protocol up for Vi1 00:04:06: %LINEPROTO-5-UPDOWN: Line protocol on Interface BRI0:1, changed state to up 00:04:06: %LINEPROTO-5-UPDOWN: Line protocol on Interface Virtual-Access1, chang ed state to up 00:04:11: %ISDN-6-CONNECT: Interface BRI0:1 is now connected to 572 #router1 4. ISDN访问首都在线263网实例: 本地局部网地址为10.0.0.0/24,属于保留地址,通过NAT地址翻译功能,局域网用户可以通过ISDN上263网访问Internet。263的ISDN电话号码为2633,用户为263,口令为263,所涉及的命令如下表: 任务 命令 指定接口通过PPP/IPCP地址协商获得IP地址 ip address negotiated 指定内部和外部端口 ip nat {inside | outside} 使用ppp/pap作认证 ppp authentication pap callin 指定接口属于拨号组1 dialer-group 1 定义拨号组1允许所有IP协议 dialer-list 1 protocol ip permit 设定拨号,号码为2633 dialer string 2633 设定登录263的用户名和口令 ppp pap sent-username 263 password 263 设定默认路由 ip route 0.0.0.0 0.0.0.0 bri 0 设定符合访问列表2的所有源地址被翻译为bri 0所拥有的地址 ip nat inside source list 2 interface bri 0 overload 设定访问列表2,允许所有协议 access-list 2 permit any 具体配置如下: hostname Cisco2503 ! isdn switch-type basic-net3 ! ip subnet-zero no ip domain-lookup ip routing ! interface Ethernet 0 ip address 10.0.0.1 255.255.255.0 ip nat inside no shutdown ! interface Serial 0 shutdown no description no ip address ! interface Serial 1 shutdown no description no ip address ! interface bri 0 ip address negotiated ip nat outside encapsulation ppp ppp authentication pap callin ppp multilink dialer-group 1 dialer hold-queue 10 dialer string 2633 dialer idle-timeout 120 ppp pap sent-username 263 password 263 no cdp enable no ip split-horizon no shutdown ! ip classless ! ! Static Routes ! ip route 0.0.0.0 0.0.0.0 bri 0 ! ! Access Control List 2 ! access-list 2 permit any ! dialer-list 1 protocol ip permit ! ! Dynamic NAT ! ip nat inside source list 2 interface bri 0 overload snmp-server community public ro ! line console 0 exec-timeout 0 0 ! line vty 0 4 ! end 5. Cisco765M通过ISDN拨号上263 由于Cisco765的设置命令与我们常用的Cisco路由器的命令不同,所以以下列举了通过Cisco765上263访问Internet的具体命令行设置步骤。 >set system c765 c765> set multidestination on c765> set switch net3 c765> set ppp multilink on c765> cd lan c765:LAN> set ip routing on c765:LAN> set ip address 10.0.0.1 c765:LAN> set ip netmask 255.0.0.0 c765:LAN> set briding off c765:LAN>cd c765> set user remotenet New user remotenet being created c765:remotenet> set ip routing on c765:remotenet> set bridging off c765:remotenet> set ip framing none c765:remotenet> set ppp clientname 263 c765:remotenet> set ppp password client Enter new Password: 263 Re-Type new Password: 263 c765:remotenet> set ppp authentication out none c765:remotenet> set ip address 0.0.0.0 c765:remotenet> set ip netmask 0.0.0.0 c765:remotenet> set ppp address negotiation local on c765:remotenet> set ip pat on c765:remotenet> set ip route destination 0.0.0.0/0 gateway 0.0.0.0 c765:remotenet> set number 2633 c765:remotenet> set active 命令描述如下: 任务 命令 设置路由器系统名称 set system c765 允许路由器呼叫多个目的地 set multidestination on 设置ISDN交换机类型为NET3 set switch net3 允许点到点间多条通道连接实现负载均衡 set ppp multilink on 关掉桥接 set briding off 建立用户预制文件用于设置拨号连接参数- 可以设置多个用户预制文件用于相同的物理端口对应于不同的连接。 set user remotenet 使用PPP/IPCP set ip framing none 设置上网用户帐号 set ppp clientname 263 设置上网口令 set ppp password client Enter new Password: 263 Re-Type new Password: 263 不用PPP/CHAP或PAP做认证 set ppp authentication out none 允许地址磋商 set ppp address negotiation local on 设置地址翻译 set ip pat on 设置默认路由 set ip route destination 0.0.0.0/0 gateway 0.0.0.0 设置ISP的电话号码 set number 2633 激活用户预制文件 set active   返回目录   六、PSTN   电话网络(PSTN)是目前普及程度最高、成本最低的公用通讯网络,它在网络互连也有广泛的应用。电话网络的应用一般可分为两种类型,一种是同等级别机构之间以按需拨号(DDR)的方式实现互连,一种是ISP为拨号上网为用户提供的远程访问服务的功能。 1. 远程访问 1.1.Access Server基本设置: 选用Cisco2511作为访问服务器,采用IP地址池动态分配地址.远程工作站使用WIN95拨号网络实现连接。 全局设置: 任务 命令 设置用户名和密码 username username password password 设置用户的IP地址池 ip local pool {default | pool-name low-ip-address [high-ip-address]} 指定地址池的工作方式 ip address-pool [dhcp-proxy-client | local] 基本接口设置命令: 任务 命令 设置封装形式为PPP encapsulation ppp 启动异步口的路由功能 async default routing 设置异步口的PPP工作方式 async mode {dedicated | interactive} 设置用户的IP地址 peer default ip address {ip-address | dhcp | pool [pool-name]} 设置IP地址与Ethernet0相同 ip unnumbered ethernet0 line拨号线设置: 任务 命令 设置modem的工作方式 modem {inout|dialin} 自动配置modem类型 modem autoconfig discovery 设置拨号线的通讯速率 speed speed 设置通讯线路的流控方式 flowcontrol {none | software [lock] [in | out] | hardware [in | out]} 连通后自动执行命令 autocommand command 访问服务器设置如下: Router: hostname Router enable secret 5 $1$EFqU$tYLJLrynNUKzE4bx6fmH// ! interface Ethernet0 ip address 10.111.4.20 255.255.255.0 ! interface Async1 ip unnumbered Ethernet0 encapsulation ppp keepalive 10 async mode interactive peer default ip address pool Cisco2511-Group-142 ! ip local pool Cisco2511-Group-142 10.111.4.21 10.111.4.36 ! line con 0 exec-timeout 0 0 password cisco ! line 1 16 modem InOut modem autoconfigure discovery flowcontrol hardware ! line aux 0 transport input all line vty 0 4 password cisco ! end 相关调试命令: show interface show line 1.2. Access Server通过Tacacs服务器实现安全认证: 使用一台WINDOWS NT服务器作为Tacacs服务器,地址为10.111.4.2,运行Cisco2511随机带的Easy ACS 1.0软件实现用户认证功能. 相关设置: 任务 命令 激活AAA访问控制 aaa new-model 用户登录时默认起用Tacacs+做AAA认证 aaa authentication login default tacacs+ 列表名为no_tacacs使用ENABLE口令做认证 aaa authentication login no_tacacs enable 在运行PPP的串行线上采用Tacacs+做认证 aaa authentication ppp default tacacs+ 由TACACS+服务器授权运行EXEC aaa authorization exec tacacs+ 由TACACS+服务器授权与网络相关的服务请求。 aaa authorization network tacacs+ 为EXEC会话运行记帐.进程开始和结束时发通告给TACACS+服务器。 aaa accounting exec start-stop tacacs+ 为与网络相关的服务需求运行记帐包括SLIP,PPP,PPP NCPs,ARAP等.在进程开始和结束时发通告给TACACS+服务器。 aaa accounting network start-stop tacacs+ 指定Tacacs服务器地址 tacacs-server host 10.111.4.2 在Tacacs+服务器和访问服务器设定共享的关键字,访问服务器和Tacacs+服务器使用这个关键字去加密口令和响应信息。这里使用tac作为关键字。 tacacs-server key tac 访问服务器设置如下: hostname router ! aaa new-model aaa authentication login default tacacs+ aaa authentication login no_tacacs enable aaa authentication ppp default tacacs+ aaa authorization exec tacacs+ aaa authorization network tacacs+ aaa accounting exec start-stop tacacs+ aaa accounting network start-stop tacacs+ enable secret 5 $1$kN4g$CvS4d2.rJzWntCnn/0hvE0 ! interface Ethernet0 ip address 10.111.4.20 255.255.255.0 ! interface Serial0 no ip address shutdown interface Serial1 no ip address shutdown ! interface Group-Async1 ip unnumbered Ethernet0 encapsulation ppp async mode interactive peer default ip address pool Cisco2511-Group-142 no cdp enable group-range 1 16 ! ip local pool Cisco2511-Group-142 10.111.4.21 10.111.4.36 tacacs-server host 10.111.4.2 tacacs-server key tac ! line con 0 exec-timeout 0 0 password cisco login authentication no_tacacs line 1 16 login authentication tacacs modem InOut modem autoconfigure type usr_courier autocommand ppp transport input all stopbits 1 rxspeed 115200 txspeed 115200 flowcontrol hardware line aux 0 transport input all line vty 0 4 password cisco ! end 2. DDR(dial-on-demand routing)实例 此例通过Cisco 2500系列路由器的aux端口实现异步拨号DDR连接。Router1拨号连接到Router2。其采用PPP/CHAP做安全认证,在Router1应建立一个用户,以对端路由器主机名作为用户名,即用户名应为Router2。同时在Router2应建立一个用户,以对端路由器主机名作为用户名,即用户名应为Router1。所建的这两用户的password必须相同。 相关命令如下: 任务 命令 设置路由器与modem的接口指令 chat-script script-name EXPECT SEND EXPECT SEND (etc.) 设置端口在挂断前的等待时间 dialer idle-timeout seconds 设置协议地址与电话号码的映射 dialer map protocol next-hop-address [name hostname] [broadcast] [modem-script modem-regexp] [system-script system-regexp] [dial-string] 设置电话号码 dialer string dial-string 指定在特定线路下路由器默认 使用的chat-script script {dialer|reset} script-name Router1: hostname Router1 ! enable secret 5 $1$QKI7$wXjpFqC74vDAyKBUMallw/ ! username Router2 password cisco chat-script cisco-default "" "AT" TIMEOUT 30 OK "ATDT \T" TIMEOUT 30 CONNECT \c ! interface Ethernet0 ip address 10.0.0.1 255.255.255.0 ! interface Async1 ip address 192.200.10.1 255.255.255.0 encapsulation ppp async default routing async mode dedicated dialer in-band dialer idle-timeout 60 dialer map ip 192.200.10.2 name Router2 modem-script cisco-default 573 dialer-group 1 ppp authentication chap ! ip route 10.0.1.0 255.255.255.0 192.200.10.2 dialer-list 1 protocol ip permit ! line con 0 line aux 0 modem InOut modem autoconfigure discovery flowcontrol hardware Router2: hostname Router2 ! enable secret 5 $1$F6EV$5U8puzNt2/o9g.t56PXHo. ! username Router1 password cisco ! interface Ethernet0 ip address 10.0.1.1 255.255.255.0 ! interface Async1 ip address 192.200.10.2 255.255.255.0 encapsulation ppp async default routing async mode dedicated dialer in-band dialer idle-timeout 60 dialer map ip 192.200.10.1 name Router1 dialer-group 1 ppp authentication chap ! ip route 10.0.0.0 255.255.255.0 192.200.10.1 dialer-list 1 protocol ip permit ! line con 0 line aux 0 modem InOut modem autoconfigure discovery flowcontrol hardware ! 相关调试命令: debug dialer debug ppp authentication debug ppp error debug ppp negotiation debug ppp packet show dialer 3. 异步拨号备份DDN专线: 此例主连接采用DDN专线,备份线路为电话拨号。当DDN专线连接正常时,主端口S0状态为up,line protocol亦为up,则备份线路状态为standby,line protocol为down,此时所有通信均通过主接口进行。当主接口连接发生故障时,端口状态为down,则激活备份接口,完成数据通信。此方法不适合为X.25做备份。因为,配置封装为X.25的接口只要和X.25交换机之间的连接正常其接口及line protocol的状态亦为 up,它并不考虑其它地方需与之通信的路由器的状态如何,所以若本地路由器状态正常,而对方路由器连接即使发生故障,本地也不会激活备份线路。例4将会描述如何为X.25做拨号备份。 以下是相关命令: 任务 命令 指定主线路改变后,次线路状态发生改变的延迟时间 backup delay {enable-delay | never} {disable-delay | never} 指定一个接口作为备份接口 backup interface type number hostname c2522rb ! enable secret 5 $1$J5vn$ceYDe2FwPhrZi6qsIIz6g0 enable password cisco ! username c4700 password 0 cisco ip subnet-zero chat-script cisco-default "" "AT" TIMEOUT 30 OK "ATDT \T" TIMEOUT 30 CONNECT \c chat-script reset atz ! interface Ethernet0 ip address 16.122.51.254 255.255.255.0 no ip mroute-cache ! interface Serial0 backup delay 10 10 backup interface Serial2 ip address 16.250.123.18 255.255.255.252 no ip mroute-cache no fair-queue ! interface Serial1 no ip address no ip mroute-cache shutdown ! interface Serial2 physical-layer async ip address 16.249.123.18 255.255.255.252 encapsulation ppp async mode dedicated dialer in-band dialer idle-timeout 60 dialer map ip 16.249.123.17 name c4700 6825179 dialer-group 1 ppp authentication chap ! interface Serial3 no ip address shutdown no cdp enable ! interface Serial4 no ip address shutdown no cdp enable ! interface Serial5 no ip address no ip mroute-cache shutdown ! interface Serial6 no ip address no ip mroute-cache shutdown ! interface Serial7 no ip address no ip mroute-cache shutdown ! interface Serial8 no ip address no ip mroute-cache shutdown ! interface Serial9 no ip address no ip mroute-cache shutdown ! interface BRI0 no ip address no ip mroute-cache shutdown ! router eigrp 200 network 16.0.0.0 ! ip classless ! dialer-list 1 protocol ip permit ! line con 0 line 2 script dialer cisco-default script reset reset modem InOut modem autoconfigure discovery rxspeed 38400 txspeed 38400 flowcontrol hardware line aux 0 line vty 0 4 password cisco login ! end c2522rb# 4. 异步拨号备份X.25: 设置X.25的拨号备份,首先X.25连接的端口必须运行动态路由协议,异步拨号口必须使用静态路由.本例选择EIGRP作为路由选择协议,将静态路由的Metric的值设置为200,由于EIGRP的默认Metric为90,所以当同时有两条路径通往同一网段时,其Metric值小的路径生效,而当X.25连接出现问题时,路由器无法通过路由协议学习到路由表,则此时静态路由生效,访问通过拨号端口实现。当X.25连接恢复正常时,路由器又可以学习到路由表,则由于 Metric值的不同,静态路由自动被动态路由所代替,这样就实现了备份的功能。 路由器Router1配置如下: hostname router1 ! enable secret 5 $1$UTvD$99YiY2XsRMxHudcYeHn.Y. enable password cisco ! username router2 password cisco ip subnet-zero chat-script cisco-default "" "AT" TIMEOUT 30 OK "ATDT \T" TIMEOUT 30 CONNECT \c chat-script reset atz interface Ethernet0 ip address 202.96.38.100 255.255.255.0 ! interface Serial0 ip address 202.96.0.1 255.255.255.0 encapsulation x25 x25 address 10112227 x25 htc 16 x25 map ip 202.96.0.2 10112225 broadcast ! interface Serial1 no ip address shutdown ! ! interface Async 1 ip address 202.96.1.1 255.255.255.252 encapsulation ppp dialer in-band dialer idle-timeout 60 dialer map ip 202.96.1.2 name router2 modem-script cisco-default 2113470 dialer-group 1 ppp authentication chap ! router eigrp 200 redistribute connected network 202.96.0.0 ! ip route 202.96.37.0 255.255.255.0 202.96.1.2 200 dialer-list 1 protocol ip permit line con 0 line aux 0 script dialer cisco-default script reset reset modem InOut modem autoconfigure discovery transport input all rxspeed 38400 txspeed 38400 flowcontrol hardware line vty 0 4 password cisco login ! end 路由器Router2配置如下: hostname router2 ! enable secret 5 $1$T4IU$2cIqak8f/E4Ug6dLT0k.J0 enable password cisco ! username router1 password cisco ip subnet-zero chat-script cisco-default "" "AT" TIMEOUT 30 OK "ATDT \T" TIMEOUT 30 CONNECT \c chat-script reset atz ! interface Ethernet0 ip address 202.96.37.100 255.255.255.0 ! interface Serial0 ip address 202.96.0.2 255.255.255.0 no ip mroute-cache encapsulation x25 x25 address 10112225 x25 htc 16 x25 map ip 202.96.0.1 10112227 broadcast ! interface Serial1 no ip address shutdown ! interface Async1 ip address 202.96.1.2 255.255.255.252 encapsulation ppp keepalive 30 async default routing async mode dedicated dialer in-band dialer idle-timeout 60 dialer wait-for-carrier-time 120 dialer map ip 202.96.1.1 name router1 modem-script cisco-default 2113469 dialer-group 1 ppp authentication chap ! router eigrp 200 redistribute static network 202.96.0.0 ! no ip classless ip route 202.96.38.0 255.255.255.0 202.96.1.1 200 dialer-list 1 protocol ip permit ! line con 0 exec-timeout 0 0 line aux 0 script reset reset modem InOut modem autoconfigure discovery transport input all rxspeed 38400 txspeed 38400 flowcontrol hardware line vty 0 4 password cisco login ! end   路由协议: 一、RIP协议   RIP(Routing information Protocol)是应用较早、使用较普遍的内部网关协议(Interior Gateway Protocol,简称IGP),适用于小型同类网络,是典型的距离向量(distance-vector)协议。文档见RFC1058、RFC1723。 RIP通过广播UDP报文来交换路由信息,每30秒发送一次路由信息更新。RIP提供跳跃计数(hop count)作为尺度来衡量路由距离,跳跃计数是一个包到达目标所必须经过的路由器的数目。如果到相同目标有二个不等速或不同带宽的路由器,但跳跃计数相同,则RIP认为两个路由是等距离的。RIP最多支持的跳数为15,即在源和目的网间所要经过的最多路由器的数目为15,跳数16表示不可达。 1. 有关命令 任务 命令 指定使用RIP协议 router rip 指定RIP版本 version {1|2}1 指定与该路由器相连的网络 network network 注:1.Cisco的RIP版本2支持验证、密钥管理、路由汇总、无类域间路由(CIDR)和变长子网掩码(VLSMs) 2. 举例 Router1: router rip version 2 network 192.200.10.0 network 192.20.10.0 ! 相关调试命令: show ip protocol show ip route   返回目录   二、IGRP协议   IGRP (Interior Gateway Routing Protocol)是一种动态距离向量路由协议,它由Cisco公司八十年代期设计。使用组合用户配置尺度,包括延迟、带宽、可靠性和负载。 缺省情况下,IGRP每90秒发送一次路由更新广播,在3个更新周期内(即270秒),没有从路由的第一个路由器接收到更新,则宣布路由不可访问。在7个更新周期即630秒后,Cisco IOS 软件从路由表清除路由。 1. 有关命令 任务 命令 指定使用RIP协议 router igrp autonomous-system1 指定与该路由器相连的网络 network network 指定与该路由器相邻的节点地址 neighbor ip-address 注:1、autonomous-system可以随意建立,并非实际意义上的autonomous-system,但运行IGRP的路由器要想交换路由更新信息其autonomous-system需相同。 2.举例 Router1: router igrp 200 network 192.200.10.0 network 192.20.10.0 ! 三、OSPF协议   OSPF(Open Shortest Path First)是一个内部网关协议(Interior Gateway Protocol,简称IGP),用于在单一自治系统(autonomous system,AS)内决策路由。与RIP相对,OSPF是链路状态路有协议,而RIP是距离向量路由协议。 链路是路由器接口的另一种说法,因此OSPF也称为接口状态路由协议。OSPF通过路由器之间通告网络接口的状态来建立链路状态数据库,生成最短路径树,每个OSPF路由器使用这些最短路径构造路由表。 文档见RFC2178。 1.有关命令 全局设置 任务 命令 指定使用OSPF协议 router ospf process-id1 指定与该路由器相连的网络 network address wildcard-mask area area-id2 指定与该路由器相邻的节点地址 neighbor ip-address 注:1、OSPF路由进程process-id必须指定范围在1-65535,多个OSPF进程可以在同一个路由器上配置,但最好不这样做。多个OSPF进程需要多个OSPF数据库的副本,必须运行多个最短路径算法的副本。process-id只在路由器内部起作用,不同路由器的process-id可以不同。 2、wildcard-mask 是子网掩码的反码, 网络区域ID area-id在0-4294967295内的十进制数,也可以是带有IP地址格式的x.x.x.x。当网络区域ID为0或0.0.0.0时为主干域。不同网络区域的路由器通过主干域学习路由信息。 2.基本配置举例: Router1: interface ethernet 0 ip address 192.1.0.129 255.255.255.192 ! interface serial 0 ip address 192.200.10.5 255.255.255.252 ! router ospf 100 network 192.200.10.4 0.0.0.3 area 0 network 192.1.0.128 0.0.0.63 area 1 ! Router2: interface ethernet 0 ip address 192.1.0.65 255.255.255.192 ! interface serial 0 ip address 192.200.10.6 255.255.255.252 ! router ospf 200 network 192.200.10.4 0.0.0.3 area 0 network 192.1.0.64 0.0.0.63 area 2 ! Router3: interface ethernet 0 ip address 192.1.0.130 255.255.255.192 ! router ospf 300 network 192.1.0.128 0.0.0.63 area 1 ! Router4: interface ethernet 0 ip address 192.1.0.66 255.255.255.192 ! router ospf 400 network 192.1.0.64 0.0.0.63 area 1 ! 相关调试命令: debug ip ospf events debug ip ospf packet show ip ospf show ip ospf database show ip ospf interface show ip ospf neighbor show ip route 3. 使用身份验证 为了安全的原因,我们可以在相同OSPF区域的路由器上启用身份验证的功能,只有经过身份验证的同一区域的路由器才能互相通告路由信息。 在默认情况下OSPF不使用区域验证。通过两种方法可启用身份验证功能,纯文本身份验证和消息摘要(md5)身份验证。纯文本身份验证传送的身份验证口令为纯文本,它会被网络探测器确定,所以不安全,不建议使用。而消息摘要(md5)身份验证在传输身份验证口令前,要对口令进行加密,所以一般建议使用此种方法进行身份验证。 使用身份验证时,区域内所有的路由器接口必须使用相同的身份验证方法。为起用身份验证,必须在路由器接口配置模式下,为区域的每个路由器接口配置口令。 任务 命令 指定身份验证 area area-id authentication [message-digest] 使用纯文本身份验证 ip ospf authentication-key password 使用消息摘要(md5)身份验证 ip ospf message-digest-key keyid md5 key 以下列举两种验证设置的示例,示例的网络分布及地址分配环境与以上基本配置举例相同,只是在Router1和Router2的区域0上使用了身份验证的功能。: 例1.使用纯文本身份验证 Router1: interface ethernet 0 ip address 192.1.0.129 255.255.255.192 ! interface serial 0 ip address 192.200.10.5 255.255.255.252 ip ospf authentication-key cisco ! router ospf 100 network 192.200.10.4 0.0.0.3 area 0 network 192.1.0.128 0.0.0.63 area 1 area 0 authentication ! Router2: interface ethernet 0 ip address 192.1.0.65 255.255.255.192 ! interface serial 0 ip address 192.200.10.6 255.255.255.252 ip ospf authentication-key cisco ! router ospf 200 network 192.200.10.4 0.0.0.3 area 0 network 192.1.0.64 0.0.0.63 area 2 area 0 authentication ! 例2.消息摘要(md5)身份验证: Router1: interface ethernet 0 ip address 192.1.0.129 255.255.255.192 ! interface serial 0 ip address 192.200.10.5 255.255.255.252 ip ospf message-digest-key 1 md5 cisco ! router ospf 100 network 192.200.10.4 0.0.0.3 area 0 network 192.1.0.128 0.0.0.63 area 1 area 0 authentication message-digest ! Router2: interface ethernet 0 ip address 192.1.0.65 255.255.255.192 ! interface serial 0 ip address 192.200.10.6 255.255.255.252 ip ospf message-digest-key 1 md5 cisco ! router ospf 200 network 192.200.10.4 0.0.0.3 area 0 network 192.1.0.64 0.0.0.63 area 2 area 0 authentication message-digest ! 相关调试命令: debug ip ospf adj debug ip ospf events   返回目录   四、重新分配路由   在实际工作,我们会遇到使用多个IP路由协议的网络。为了使整个网络正常地工作,必须在多个路由协议之间进行成功的路由再分配。 以下列举了OSPF与RIP之间重新分配路由的设置范例: Router1的Serial 0端口和Router2的Serial 0端口运行OSPF,在Router1的Ethernet 0端口运行RIP 2,Router3运行RIP2,Router2有指向Router4的192.168.2.0/24网的静态路由,Router4使用默认静态路由。需要在Router1和Router3之间重新分配OSPF和RIP路由,在Router2上重新分配静态路由和直连的路由。 范例所涉及的命令 任务 命令 重新分配直连的路由 redistribute connected 重新分配静态路由 redistribute static 重新分配ospf路由 redistribute ospf process-id metric metric-value 重新分配rip路由 redistribute rip metric metric-value Router1: interface ethernet 0 ip address 192.168.1.1 255.255.255.0 ! interface serial 0 ip address 192.200.10.5 255.255.255.252 ! router ospf 100 redistribute rip metric 10 network 192.200.10.4 0.0.0.3 area 0 ! router rip version 2 redistribute ospf 100 metric 1 network 192.168.1.0 ! Router2: interface loopback 1 ip address 192.168.3.2 255.255.255.0 ! interface ethernet 0 ip address 192.168.0.2 255.255.255.0 ! interface serial 0 ip address 192.200.10.6 255.255.255.252 ! router ospf 200 redistribute connected subnet redistribute static subnet network 192.200.10.4 0.0.0.3 area 0 ! ip route 192.168.2.0 255.255.255.0 192.168.0.1 ! Router3: interface ethernet 0 ip address 192.168.1.2 255.255.255.0 ! router rip version 2 network 192.168.1.0 ! Router4: interface ethernet 0 ip address 192.168.0.1 255.255.255.0 ! interface ethernet 1 ip address 192.168.2.1 255.255.255.0 ! ip route 0.0.0.0 0.0.0.0 192.168.0.2 !   五、IPX协议设置   IPX协议与IP协议是两种不同的网络层协议,它们的路由协议也不一样,IPX的路由协议不象IP的路由协议那样丰富,所以设置起来比较简单。但IPX协议在以太网上运行时必须指定封装形式。 1. 有关命令 启动IPX路由 ipx routing 设置IPX网络及以太网封装形式 ipx network network [encapsulation encapsulation-type]1 指定路由协议,默认为RIP ipx router {eigrp autonomous-system-number | nlsp [tag] | rip} 注:1.network 范围是1 到FFFFFFFD. IPX封装类型列表 接口类型 封装类型 IPX帧类型 Ethernet novell-ether (默认) arpa sap snap Ethernet_802.3 Ethernet_II Ethernet_802.2 Ethernet_Snap Token Ring sap (默认) snap Token-Ring Token-Ring_Snap FDDI snap (默认) sap novell-fddi Fddi_Snap Fddi_802.2 Fddi_Raw 举例: 在此例,WAN的IPX网络为3a00,Router1所连接的局域网IPX网络号为2a00,在此局域网有一台Novell服务器,IPX网络号也是2a00, 路由器接口的IPX网络号必须与在同一网络的Novell服务器上设置的IPX网络号相同。路由器通过监听SAP来建立已知的服务及自己的网络地址表,并每60秒发送一次自己的SAP表。 Router1: ipx routing interface ethernet 0 ipx network 2a00 encapsulation sap ! interface serial 0 ipx network 3a00 ! ipx router eigrp 10 network 3a00 network 2a00 ! Router2: ipx routing interface ethernet 0 ipx network 2b00 encapsulation sap ! interface serial 0 ipx network 3a00 ! ipx router eigrp 10 network 2b00 network 3a00 ! 相关调试命令: debug ipx packet debug ipx routing debug ipx sap debug ipx spoof debug ipx spx show ipx eigrp interfaces show ipx eigrp neighbors show ipx eigrp topology show ipx interface show ipx route show ipx servers show ipx spx-spoof   五、IPX协议设置   IPX协议与IP协议是两种不同的网络层协议,它们的路由协议也不一样,IPX的路由协议不象IP的路由协议那样丰富,所以设置起来比较简单。但IPX协议在以太网上运行时必须指定封装形式。 1. 有关命令 启动IPX路由 ipx routing 设置IPX网络及以太网封装形式 ipx network network [encapsulation encapsulation-type]1 指定路由协议,默认为RIP ipx router {eigrp autonomous-system-number | nlsp [tag] | rip} 注:1.network 范围是1 到FFFFFFFD. IPX封装类型列表 接口类型 封装类型 IPX帧类型 Ethernet novell-ether (默认) arpa sap snap Ethernet_802.3 Ethernet_II Ethernet_802.2 Ethernet_Snap Token Ring sap (默认) snap Token-Ring Token-Ring_Snap FDDI snap (默认) sap novell-fddi Fddi_Snap Fddi_802.2 Fddi_Raw 举例: 在此例,WAN的IPX网络为3a00,Router1所连接的局域网IPX网络号为2a00,在此局域网有一台Novell服务器,IPX网络号也是2a00, 路由器接口的IPX网络号必须与在同一网络的Novell服务器上设置的IPX网络号相同。路由器通过监听SAP来建立已知的服务及自己的网络地址表,并每60秒发送一次自己的SAP表。 Router1: ipx routing interface ethernet 0 ipx network 2a00 encapsulation sap ! interface serial 0 ipx network 3a00 ! ipx router eigrp 10 network 3a00 network 2a00 ! Router2: ipx routing interface ethernet 0 ipx network 2b00 encapsulation sap ! interface ser

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧