ImageVerifierCode 换一换
格式:DOCX , 页数:11 ,大小:1.45MB ,
资源ID:3662483      下载积分:12 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3662483.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(VC++66教材.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

VC++66教材.docx

1、VC+66教材VC+教材第一课宏定义_cplusplus是C+编译相关的默认宏_stdc_是C编译相关的默认宏。_STDC_是预定义宏。当它被定义后,编译器将按照ansic标准来编译你的c程序。ANSIC标准定义了以下6种可供C语言使用的预定义宏: _LINE_ 在源代码中插入当前源代码行号 _FILE_ 在源代码中插入当前源代码文件名 _DATE_ 在源代码中插入当前编译日期注意和当前系统日期区别开来 _TIME_ 在源代码中插入当前编译时间注意和当前系统时间区别开来 _STDC_ 当要求程序严格遵循ANSIC标准时该标识符被赋值为1。 _cplusplus 标识符_LINE_和_FILE_

2、通常用来调试程序; 标识符_DATE_和_TIME_通常用来在编译后的程序中加入一个时间标志,以区分程序的不同版本; 当要求程序严格遵循ANSIC标准时,标识符_STDC_就会被赋值为1; 当用C+编译程序编译时,标识符_cplusplus就会被定义。根据以上定义,说明C+都是按着宏定义来解释C+代码的,目前分俩种跟编译器相关的宏定义。还有#define _EXTERN_C extern C 也是为了C和C+互相调用相关的定义。Extern本意是“外部”的意思。C语句里常出现,C+里一般不建议使用,因为面向对象封装的原因。一般用于将C+代码以标准C形式输出(即以C的形式被调用),这是因为C+虽

3、然常被认为是C的超集,但是C+的编译器还是与C的编译器不同的。C中调用C+中的代码这样定义会是安全的。一般的考虑跨平台使用方法如下:#ifdefined(_cplusplus)|defined(c_plusplus) /跨平台定义方法extern C#endif/. 正常的声明段#ifdefined(_cplusplus)|defined(c_plusplus)#endif 简单的用在windows下可以如下定义:#ifdef _cplusplusextern C/. 正常的声明段#endiftypedef int LONG32, *PLONG32;typedef int INT32, *PI

4、NT32;这跟宏定义差不多,学名是“类型定义”。C+为了跟C区别就定义了很多这类大写的类型名LONG UINT INT等等。当然同时支持C的小写类型名。Int long等。例如:typedef unsigned int ULONG32, *PULONG32;typedef unsigned int DWORD32, *PDWORD32;typedef unsigned int UINT32, *PUINT32;另:对于32,64位数据类型,目前多数是32位使用的比较多。64位基本上没有。因为32位基本上满足了我们的需求。64位的宏开关是这样写的:#ifdef _WIN64 typedef _i

5、nt64 INT_PTR, *PINT_PTR;typedef unsigned _int64 UINT_PTR, *PUINT_PTR;指针类型和整形类型之间的转换函数定义:_inlineunsigned longHandleToUlong( void *h ) return(unsigned long) h );_inlineunsigned longPtrToUlong( void *p ) return(unsigned long) p );_inlineunsigned shortPtrToUshort( void *p ) return(unsigned short) p );_i

6、nlinelongPtrToLong( void *p ) return(long) p );_inlineshortPtrToShort( void *p ) return(short) p );#endif#pragma warning(3:4311) / type cast truncation#elsetypedef long INT_PTR, *PINT_PTR;typedef unsigned long UINT_PTR, *PUINT_PTR;#define MAXINT_PTR (0x7fffffffL) 指针类型的数据最大值#define MININT_PTR (0x8000

7、0000L) 指针类型的数据最小值#define MAXUINT_PTR (0xffffffffUL) 指针类型的数据最大值typedef unsigned short UHALF_PTR, *PUHALF_PTR; short短无符号整形定义的短指针类型(小指针)typedef short HALF_PTR, *PHALF_PTR;short短有符号整形定义的短指针类型(小指针)#define MAXUHALF_PTR 0xffff 短指针类型的最大值#define MAXHALF_PTR 0x7fff 短指针类型的最大值#define MINHALF_PTR 0x8000 短指针类型的最小

8、值/函数形式的宏定义#define HandleToUlong( h ) (ULONG) (h) ) #define PtrToUlong( p ) (ULONG) (p) )#define PtrToLong( p ) (LONG) (p) )#define PtrToUshort( p ) (unsigned short) (p) )#define PtrToShort( p ) (short) (p) )#endifinline 的函数必须和函数定义一起用才起作用, 而且调用方必须能够看到这个函数的定义, 如:/ a.hinline void foo(void);/ a.cinline

9、void foo(void)/ b.c#include a.hvoid bar(void)foo();这种用法 inline 是不起任何作用的, 只有这样:/ a.hinline void foo(void)/ b.c#include a.hvoid bar(void)foo();这样才能真正的内联; 内联是在编译期间处理的, 第一种情况, 如果编译器编译 b.c 的时候, 只看到 foo 的声明, 而看不到其定义, 编译器就没办法把 foo 函数内联到调用处!所谓的内联就是把函数里面的代码直接拷贝到执行的代码里面再编译,而不是按着函数实现体来编译。(以上是basetsd.h文件。Stdafx

10、.h文件是用来包含标准头文件的,一般C+的函数找不到时就是因为头文件没有包含进来。)总结:宏定义本身其实就是替换掉代码里的宏名为定义体。只是置换的作用。函数形式的宏定义用来实现复杂的一些代码形式。比如参数类型的互换,C+重载功能的宏实现等。 VC+教材第二课MFC类库介绍CWinApp类:应用程序入口类,一般从这里开始执行代码。先简单介绍一下C+类头文件H和实现体文件CPP基本结构。1,头文件里有针对类的宏定义/ test.h : main header file for the TEST application/#if !defined(AFX_TEST_H_67369212_1733_4E

11、81_8D0C_4EB216B09392_INCLUDED_)#define AFX_TEST_H_67369212_1733_4E81_8D0C_4EB216B09392_INCLUDED_#if _MSC_VER 1000#pragma once#endif / _MSC_VER 1000#ifndef _AFXWIN_H_ #error include stdafx.h before including this file for PCH#endif#include resource.h / main symbols/ CTestApp:/ See test.cpp for the im

12、plementation of this class/class CTestApp : public CWinApppublic: CTestApp();/ Overrides / ClassWizard generated virtual function overrides /AFX_VIRTUAL(CTestApp) public: virtual BOOL InitInstance(); /AFX_VIRTUAL/ Implementation /AFX_MSG(CTestApp) / NOTE - the ClassWizard will add and remove member

13、functions here. / DO NOT EDIT what you see in these blocks of generated code ! /AFX_MSG DECLARE_MESSAGE_MAP();/AFX_INSERT_LOCATION/ Microsoft Visual C+ will insert additional declarations immediately before the previous line.#endif / !defined(AFX_TEST_H_67369212_1733_4E81_8D0C_4EB216B09392_INCLUDED_

14、)2,实现体文件/ test.cpp : Defines the class behaviors for the application./#include stdafx.h#include test.h#include testDlg.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CTestAppBEGIN_MESSAGE_MAP(CTestApp, CWinApp) /AFX_MSG_MAP(CTestApp) / NOTE - the ClassWizar

15、d will add and remove mapping macros here. / DO NOT EDIT what you see in these blocks of generated code! /AFX_MSG ON_COMMAND(ID_HELP, CWinApp:OnHelp)END_MESSAGE_MAP()/ CTestApp constructionCTestApp:CTestApp() / TODO: add construction code here, / Place all significant initialization in InitInstance/

16、 The one and only CTestApp objectCTestApp theApp;/ CTestApp initializationBOOL CTestApp:InitInstance() if (!AfxSocketInit() AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; AfxEnableControlContainer(); / Standard initialization / If you are not using these features and wish to reduce the size /

17、 of your final executable, you should remove from the following / the specific initialization routines you do not need.#ifdef _AFXDLL Enable3dControls(); / Call this when using MFC in a shared DLL#else Enable3dControlsStatic(); / Call this when linking to MFC statically#endif CTestDlg dlg; m_pMainWn

18、d = &dlg; int nResponse = dlg.DoModal(); if (nResponse = IDOK) / TODO: Place code here to handle when the dialog is / dismissed with OK else if (nResponse = IDCANCEL) / TODO: Place code here to handle when the dialog is / dismissed with Cancel / Since the dialog has been closed, return FALSE so that

19、 we exit the / application, rather than start the applications message pump. return FALSE;3,CWinApp的InitInstance函数:应用程序的事例初始化函数,包括初始化代码和初期窗口显示代码。 CTestDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal();/建立模式对话框 if (nResponse = IDOK) / TODO: Place code here to handle when the dialog is / dismi

20、ssed with OK else if (nResponse = IDCANCEL) / TODO: Place code here to handle when the dialog is / dismissed with Cancel 这是对话框模式的代码。 CSingleDocTemplate* pDocTemplate;/文档模版的创建 pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CViewDoc), RUNTIME_CLASS(CMainFrame), / main SDI frame wi

21、ndow RUNTIME_CLASS(CViewView); AddDocTemplate(pDocTemplate);/解析SHELL命令行 / Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo);/执行SHELL命令行 / Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo) return FALSE;/显示窗口 / The one and only window has been initialized, so show and update it. m_pMainWnd-ShowWindow(SW_SHOW); m_pMainWnd-UpdateWindow();这是文档模式的代码。

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1