IntersectRect    两矩形相交形成的新矩形

The IntersectRect function calculates the intersection of two source rectangles and places the coordinates of the intersection rectangle into the destination rectangle. If the source rectangles do not intersect, an empty rectangle (in which all coordinates are set to zero) is placed into the destination rectangle.

BOOL IntersectRect(
LPRECT
lprcDst, // intersection buffer
CONST RECT*lprcSrc1, // first rectangle
CONST RECT*lprcSrc2 // second rectangle
);
 

Parameters

lprcDst
[out] Pointer to the RECT structure that is to receive the intersection of the rectangles pointed to by the lprcSrc1 and lprcSrc2 parameters. This parameter cannot be NULL.
lprcSrc1
[in] Pointer to the RECT structure that contains the first source rectangle.
lprcSrc2
[in] Pointer to the RECT structure that contains the second source rectangle.

Return Values

If the rectangles intersect, the return value is nonzero.

If the rectangles do not intersect, the return value is zero.

Windows NT/2000/XP: To get extended error information, call GetLastError.

Remarks

Because applications can use rectangles for different purposes, the rectangle functions do not use an explicit unit of measure. Instead, all rectangle coordinates and dimensions are given in signed, logical values. The mapping mode and the function in which the rectangle is used determine the units of measure.

wcsrchr 获取一个字符在字符串中最后一次出现的位置

Scan a string for the last occurrence of a character.

 
char *strrchr(
const char *str,
int c
); // C only
char *strrchr(
char *str,
int c
); // C++ only
const char *strrchr(
const char *str,
int c
); // C++ only
wchar_t *wcsrchr(
const wchar_t *str,
wchar_t c
); // C only
wchar_t *wcsrchr(
wchar_t *str,
wchar_t c
); // C++ only
const wchar_t *wcsrchr(
const wchar_t *str,
wchar_t c
); // C++ only
unsigned char *_mbsrchr(
const unsigned char *str,
unsigned int c
); // C only
unsigned char *_mbsrchr(
unsigned char *str,
unsigned int c
); // C++ only
const unsigned char *_mbsrchr(
const unsigned char *str,
unsigned int c
); // C++ only
unsigned char *_mbsrchr_l(
const unsigned char *str,
unsigned int c,
_locale_t locale
); // C only
unsigned char *_mbsrchr_l(
unsigned char *str,
unsigned int c,
_locale_t locale
); // C++ only
const unsigned char *_mbsrchr_l(
const unsigned char *str,
unsigned int c,
_locale_t locale
); // C++ only

Parameters

str

Null-terminated string to search.

c

Character to be located.

locale

Locale to use.

Return Value

Returns a pointer to the last occurrence of c in str, or NULL if c is not found.

CComPtr用法

COM接口指针很危险,因为使用过程中需要每一个使用者都要严格并且正确的AddRef和Release,一旦出现问题,就会造成对象不能被正常释放,或者对象被重复删除,造成程序崩溃。所以使用COM接口,必须小心翼翼才行。
但是,即使所有的代码中,都正确的AddRef和Release,也不一定能保证万无一失,例如:
void SomeApp( IHello * pHello )
{
IHello* pCopy = pHello;
pCopy->AddRef(); 
OtherApp();
pCopy->Hello();
pCopy->Release();
}
看起来好像无懈可击,但是假设OtherApp中抛出了异常,那么pCopy->Release不就被跳过去了吗?
幸好,所有的问题都从简单到复杂,再从复杂到简单的,因为我们有CComPtr!

CComPtr被称为智能指针,是ATL提供的一个模版类,能够从语法上自动完成AddRef和Release。(源代码在atlbase.h中)
CComPtr的用法很简单,以IHello*为例,将程序中所有接口指针类型(除了参数),都使用CComPtr<IHello> 代替即可。即程序中除了参数之外,再也不要使用IHello*,全部以CComPtr<IHello>代替。
CComPtr的用法和普通COM指针几乎一样,另外使用中有以下几点需要注意。
1. CComPtr已经保证了AddRef和Release的正确调用,所以不需要,也不能够再调用AddRef和Release。
2. 如果要释放一个智能指针,直接给它赋NULL值即可。(这一点要牢记曾因为没有设置为null而出错)
3. CComPtr本身析构的时候会释放COM指针。
4. 当对CComPtr使用&运算符(取指针地址)的时候,要确保CComPtr为NUL。(因为通过CComPtr的地址对CComPtr赋值时,不会自动调用AddRef,若不为NULL,则前面的指针不能释放,CComPtr会使用assert报警)
以刚才的程序为例:
void SomeApp( IHello * pHello )
{
CComPtr<IHello> pCopy = pHello;
OtherApp();
pCopy->Hello();
}
由于pCopy是一个局部的对象,所以即使OtherApp()抛出异常,pCopy也会被析构,指针能够被释放。
如果不想在程序临近发布前,还因为COM指针的引用计数造成崩溃的话,就牢记这一点吧:程序中除了参数之外,不要直接使用COM指针类型,一定要全部以CComPtr<IXXX>代替

DWORD GetFileAttributes(LPCTSTR lpFilename); 为一个指定的文件或目录返回文件系统的属性

参数:

hFileName: 输入参数,为需要获取属性的文件或目录

返回值:

返回DWORD值,表示文件属性。如果返回INVALID_FILE_ATTRIBUTES,则表示失败,可使用GetLastError函数获取错误信息

使用说明:
    要判断文件属性,需要使用“&”与属性常量进行运算,如果运行结果为真,则表示具有这种属性

注意:INVALID_FILE_ATTRIBUTES 实为DWORD(-1). 因此在判断文件属性之前,首先要确保函数返回值不是INVALID_FILE_ATTRIBUTES,因为和INVALID_FILE_ATTRIBUTES 做 ‘&’ 操作,结果总是非零,从而带来误判。

IntersectRect、wcsrchr、CComPtr、GetFileAttributes的更多相关文章

  1. .NET 基础 一步步 一幕幕[面向对象之方法、方法的重载、方法的重写、方法的递归]

    方法.方法的重载.方法的重写.方法的递归 方法: 将一堆代码进行重用的一种机制. 语法: [访问修饰符] 返回类型 <方法名>(参数列表){ 方法主体: } 返回值类型:如果不需要写返回值 ...

  2. JavaScript学习笔记(一)——延迟对象、跨域、模板引擎、弹出层、AJAX示例

    一.AJAX示例 AJAX全称为“Asynchronous JavaScript And XML”(异步JavaScript和XML) 是指一种创建交互式网页应用的开发技术.改善用户体验,实现无刷新效 ...

  3. atitit.管理学三大定律:彼得原理、墨菲定律、帕金森定律

    atitit.管理学三大定律:彼得原理.墨菲定律.帕金森定律 彼得原理(The Peter Principle) 1 彼得原理解决方案1 帕金森定律 2 如何理解墨菲定律2 彼得原理(The Pete ...

  4. 【完全开源】知乎日报UWP版(下篇):商店APP、github源码、功能说明。Windows APP 良心出品。

    目录 说明 功能 截图+视频 关于源码和声明 说明 陆陆续续大概花了一个月的时间,APP算是基本完成了.12月份一直在外出差,在出差期间进行了两次功能完善,然后断断续续修补了一些bug,到目前为止,我 ...

  5. Windows Server 2012 磁盘管理之 简单卷、跨区卷、带区卷、镜像卷和RAID-5卷

    今天给客户配置故障转移群集,在Windows Server 2012 R2的系统上,通过iSCSI连接上DELL的SAN存储后,在磁盘管理里面发现可以新建 简单卷.跨区卷.带区卷.镜像卷.RAID-5 ...

  6. react+redux教程(五)异步、单一state树结构、componentWillReceiveProps

    今天,我们要讲解的是异步.单一state树结构.componentWillReceiveProps这三个知识点. 例子 这个例子是官方的例子,主要是从Reddit中请求新闻列表来显示,可以切换reac ...

  7. 记2016腾讯 TST 校招面试经历,电面、笔试写代码、技术面、hr面,共5轮

    (出处:http://www.cnblogs.com/linguanh/) 前序: 距离  2016 腾讯 TST 校招面试结束已经5天了,3月27日至今,目前还在等待消息.从投简历到两轮电面,再到被 ...

  8. JavaScript学习总结(一)——延迟对象、跨域、模板引擎、弹出层、AJAX示例

    一.AJAX示例 AJAX全称为“Asynchronous JavaScript And XML”(异步JavaScript和XML) 是指一种创建交互式网页应用的开发技术.改善用户体验,实现无刷新效 ...

  9. CSS3与页面布局学习总结(二)——Box Model、边距折叠、内联与块标签、CSSReset

    一.盒子模型(Box Model) 盒子模型也有人称为框模型,HTML中的多数元素都会在浏览器中生成一个矩形的区域,每个区域包含四个组成部分,从外向内依次是:外边距(Margin).边框(Border ...

  10. C#基础回顾(二)—页面值传递、重载与重写、类与结构体、装箱与拆箱

    一.前言 -孤独的路上有梦想作伴,乘风破浪- 二.页面值传递 (1)C#各页面之间可以进行数据的交换和传递,页面之间可根据获取的数据,进行各自的操作(跳转.计算等操作).为了实现多种方式的数据传递,C ...

随机推荐

  1. python学习笔记(17)--eclipse和pydev的安装及汉化

    说明: 1. 本来一直用sublime的REPL跑python,不过在用爬虫下载图片输出页数的时候,由于输出太多行会卡住,而IDLE已经受够了,写起代码来实在是不好用.之前其实也写过一篇文章探讨过各种 ...

  2. 实现qsort(和qsort差一个数量级啊,伤自尊了)

    #include <cstdio> #include <cstdint> #include <ctime> #include <cstring> #in ...

  3. 有关一道printf 的面试题

    今天有个学生面试,面试题目里面有一道有关 printf 的输出问题 源代码如下: #include <stdio.h> int main(void) { int a = 10, b = 2 ...

  4. git 远程仓库版本的回退以及git reset 几种常用方式记录

    由于 github push 了两个比较潦草的commit, 自己很不满意,又不想重新开vpn进行上传,所以找了一下相关的教程. 最后研究了一下,原理为先在本地还原到你想要的commit,然后强制pu ...

  5. Activiti 获取定义

    ProcessDefinitionEntity d = (ProcessDefinitionEntity)((RepositoryServiceImpl)repositoryService).getD ...

  6. u-boot可ping通PC,PC不可ping通u-boot

    http://blog.csdn.net/ce123_zhouwei/article/details/7339134 开发板运行U-Boot,在终端下使用Ping命令是能Ping通PC机,但PC机Pi ...

  7. 关于trunk、access以及hybrid的一些简单知识

    关于trunk.access以及hybrid的一些简单知识:Access 类型的端口只能属于 1 个 VLAN ,一般用于连接计算机的端口: Trunk 类型的端口可以允许多个 VLAN 通过,可以接 ...

  8. [LintCode]判断一个字符串是否包含另一个字符串的所有字符

    问题描述: 比较两个字符串A和B,确定A中是否包含B中所有的字符.字符串A和B中的字符都是 大写字母. 样例 给出 A = "ABCD" B = "ACD",返 ...

  9. CentOS6 配置FTP服务器

    编辑 删除 1.先检查有没有安装   rpm -q vsftpd 如果没有安装   yum install vsftpd 2.先关闭防火墙进行调试. service iptables stop 或者一 ...

  10. 机器学习理论之SVM

    支持向量机系列 (1) 算法理论理解 http://blog.pluskid.org/?page_id=683 手把手教你实现SVM算法(一) (2) 算法应用 算法应用----python 实现实例 ...