VC++技术内幕(第四版)笔记(第14章)

/****************************/

第十四章:可重用框架窗口类


1, 可重用基类的设计:为某个工程所设计的类应该能够被提取出来 ,使它进一步一般化后被应用于其他的应用程序。

2, 一些重要函数:
1)CFrameWnd::ActivateFrame
virtual void ActivateFrame( int nCmdShow = -1 );
//以nCmdShow作为参数调用CWnd::ShowWindow函数来显示框架窗口(其菜单视图控制栏窗口也会被同时显示)。nCmdShow决定窗口是最大化还是最小化等。
//在派生类中重载ActivateFrame ,在nCmdShow传递给CFrameWnd::ActivateFrame之前修改nCmdShow的值。还可以调用CWnd::SetWindowPlacement设置框架窗口的位置和尺寸并还可以设置控制栏的可视状态。
2)CWnd::PreCreateWindow
virtual BOOL PreCreateWindow( CREATESTRUCT& cs );
//PreCreateWindow在调用ActivateFrame函数之前被框架调用,用以在窗口显示之前改变其窗口的特性(特性主要参考:CREATESTRUCT结构。
//在派生类中重载它,在CS传给基类之前改变CS结构中值,从而实现定制(显示)窗口。
3)在MDI中,主框架窗口的ShowWindow函数是由应用程序类InitInstance函数调用,不是由CFrameWnd::ActivateFrame函数调用。故要控制MDI主框架窗口的一些特性,应该在应用程序类InitInstance函数中添加相应的代码。

3,Window注册表
1)Window注册表是一组系统文件,由Window管理,Windows和其他的应用程序可以在注册表中保存一些永久的信息。
Windows 注册表被组织成一个层次的数据库,字符和整型数据可以通过一个多部分键值来访问。
2)操作:
SetRegistryKey   Causes application settings to be stored in the registry instead of .INI files.

GetProfileInt   Retrieves an integer from an entry in the application’s .INI file.
WriteProfileInt  Writes an integer to an entry in the application’s .INI file.
GetProfileString  Retrieves a string from an entry in the application’s .INI file.
WriteProfileString  Writes a string to an entry in the application’s .INI file.
说明:
1)vc5开始,AppWziard在应用程序类的InitInstance函数中有对CWinApp::SetRegistryKey函数的调用,如下:
 SetRegistryKey(_T("Local AppWizard-Generated Applications"));
该函数的调用使应用程序使用注册表,如果去掉则应用程序不使用注册表,仅在Windows目录下创建一个INI文件,并使用该文件。
SetRegistryKey的字符串参数建立最上层键,其后的注册表函数定义下面的两层(称为头名和入口名)。
2)为能够使用注册表访问函数,需要一个指向应用实例对象的指针,可以通过AfxGetApp函数获得。如下:
AfxGetApp()->WriteProfileString("Text formatting","Font","Times Roman");
AfxGetApp()->WriteProfileInt("Text Formatting","Points",10);
3)注册表访问函数可以将注册表当成CString对象或无符号整数来处理。


4,CString类中,LPCTSTR并不是一个指向CString对象的指针,而是一个用来代替const char*的Unicode版本。
1) CString str;
 char ch[]="abcdefg";
 strcpy(str.GetBuffer(strlen(ch)),ch);
 str.ReleaseBuffer();
 pDC->TextOut(0,0,str);
输出:abcdefg
2) CString str("abcdefg");
 char ch[20];
 strcpy(ch,LPCTSTR(str));
 pDC->TextOut(0,0,ch);
输出:abcdefg
说明:
char *strcpy( char *strDestination, const char *strSource );
3)编写带字符串参数的函数原则:
a,如果不改变字符串内容:可以使用const char*形参,可以使用CString&类型形参
b,如果改变字符串内容,可以使用CString&类型形参(当然可以使用指针,但这儿不建议)。


5,获取窗口坐标
GetWindowPlacement
//Retrieves the show state and the normal (restored), minimized, and maximized positions of a window.
SetWindowPlacement(可以返回最大化前的屏幕坐标)
//Sets the show state and the normal (restored), minimized, and maximized positions for a window.
GetWindowRect
//Gets the screen coordinates of CWnd.


/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值