网络资源的拷贝粘贴 备份参考之用


5 September 2008

Martin Seligman on the State of Psychology [Translated Version]


   心理学向来以负面的心理状态作为自己的研究重点,以"抑郁"、"焦虑"、"分裂"为主题的论文在心理学文献中汗牛充栋。然而在过去的几年中,心理学家开 始意识到,除了减少人们的消极情绪,心理学还应该增加人们的积极情绪;除了帮助病患过上正常人的生活,心理学还应该帮助正常人过上更好、更充实的生活。于 是,一门名为"积极心理学"(positive psychology)的学科应运而生。在下面的演讲中,积极心理学的代表人物Martin Seligman就与听众分享了积极人生的诀窍。

原文视频照例在TED:http://www.ted.com/index.php/talks/martin_seligman_on_the_state_of_psychology.html

积极的心理学,积极的人生

Martin Seligman

红猪 译  

我在美国心理学会当主席的时候,电视台的人想要教我如何面对媒体。我在CNN做了一期节目,我在节目里说的话可以概括今天要讲的主题:我们应当保持乐观的第十一个理由。Discover的编辑告诉了我们前十个,我来告诉各位第十一个。

  CNN的人来找我,对我说:"Seligman教授,能不能跟我们说说心理学的现状?我们想要知道一下您的看法。"我说"那好啊。"他们说:"但有一点,这可是CNN,您只能说一句警句。"

  "那么,我可以说几个字呢?"

 "一个。"

  摄像开拍,主持人问:Seligman教授,心理学的现状如何?

  我:好。

  主持人:卡,卡,这可不行,您得把警句说长点。

  我:这次能说几个字?

  主持人:嗯,两个吧……Seligman博士,心理学的现状如何?

  我:不好。

  主持人:我跟您说博士,我们知道您对我们这种媒体不适应,您还是说句真正的警句吧,这次可以说三个字……Seligman教授,心理学的现状如何?

  我:不够好。

  这就是我要说的。我想谈谈心理学为什么好?为什么不好?在未来十年里如何可能变得足够好?同时我也想谈谈技术、娱乐和设计,因为我觉得这几项活动的现状和心理学的现状十分相似。

  好了,我为什么说心理 学的现状还好呢?因为过去六十多年里,心理学建立起了一个疾病模型。十年之前,我在飞机上向邻座进行自我介绍,说到我是干什么的时候,他们就退避三舍,因 为他们觉得心理学的目标就是发现你哪里出了问题,并找出谁是疯子。现在,当我说到我是干什么的时候,人们却对我趋之若鹜。国家卫生研究所对心理研究投入了300亿, 这些投入产生了什么效果呢?六十年前,所有的失调都无法治疗。而现在,十四种失调能够治疗,其中的两种能够治愈。另外一方面,我们发展出了一种科学,一种 关于精神疾病的科学。我们现在能够对模糊的疾病类别进行精确测量,比如抑郁症和酒精依赖。我们提出了精神疾病的分类,还能够理解精神疾病的前因后果。我们 能追踪一个人群的变化,比如在基因上对精神分裂症易感的人群,并找出基因在其中起到的作用。我们能够用实验方法分离出导致精神疾病的变量。最好的是成就, 是我们在过去几十年里发明了药物疗法和心理疗法。其结果就是,心理学和精神病学在过去六十年的发展,能让痛苦者减轻痛苦。我觉得这很棒,我为此感到骄傲。

  那么,心理学的现状不好在什么地方呢?上 述发展产生了三个后果:第一个和道德有关,心理学家和精神病学家把人看作罪犯和病人。我们一度认为人在疾病面前无能为力,忘记了人们还可以做选择、做决 定,并承担责任。这是第一个代价。第二个代价,是我们忽略了在座的诸位。我们忽略了对正常人生活的改善,忽略了如何让比较正常的人们过得更快乐、更充实、 更有成就。"天才"成了一个肮脏的字眼,没人去研究天才了。疾病模型存在的第三问题,是我们急于帮助困于疾患的人,急于修补损伤,我们从没想过怎样才能人 们变得更快乐,怎样进行积极干预。这些就是不好的地方。这就是为什么Nancy Etcoff,Dan Gilbert和我会去研究我称作"积极心理学"(positive psychology)的这个领域。

  积 极心理学有三个目标:一是心理学不仅要关注人的弱点,同样要关注人的长处;二是心理学不仅要关注如何修复损伤,还要关注如何给人力量;三是心理学不仅要让 普通人生活得充实,还要让有天赋的人获得成就。在过去十年里,我们见证了一门新科学的诞生,一门让生活值得一过的科学,那就是积极心理学。我们发现,不同 形式的幸福感原来是可以测量的。各位有空可以去上一下authentichappiness.org,做一下整套幸福感量表,你们可以看看自己在积极情绪、幸福感、和涌动体验(flow)方面的得分,并和其他数万人进行对比。我们提出了和精神障碍诊断和统计手册(DSM)相反的标准。我们发现,积极状态中的因果关系是可以加以确定的、幸福感是由左右脑半球活动之间的关系决定的。

  我的一生都在帮助痛苦 的人,我一度想知道痛苦的人和其他人之间有什么不同。大约六年之前,我开始探索非常幸福的人和其他人之间有什么不同。结果发现,他们并没有特别虔诚、身材 没有特别好、也没有特别富有,他们和别人不同的一点,是他们特别合群。他们不会在周六早晨去参加研讨会(众笑),他们不花时间独处,其中的每一个都处在一 段恋情中,每一个都很多朋友。但是,注意了,这只是相关数据,不是因果关系。而且他们的幸福都是好莱坞式的幸福,即开怀大笑式的幸福。我待会就会告诉你 们,这是不够的。人们在过去的一个世纪已经发现了一百二十来种号称能使人幸福的干预手段。我们做了一番研究,试图确定何种手段能使人获得持续的幸福。除了 把病人治好、让痛苦的人不再痛苦之外,心理学还应该具有使人幸福的目标。

  我不大用"幸福"这个词,我觉得该把它替换成适合提问解答的术语。在我看来,总共存在三种不同的幸福生活。第一种是快乐的生活(pleasant life),你在其中拥有尽可能多的积极情绪。第二种是参与的生活(life of engagement),当你工作、哺育、恋爱、休闲时,你觉得时间停止,亚里士多德说的就是这种生活。第三种是有意义的生活(meaningful life)。我想分别谈谈这三种生活,谈谈我们对它们知道些什么。

  第一种是快乐的生活。 你在这种生活里尽量找乐子,获取尽可能多的积极情绪;为此你需要掌握增加快乐的技巧。然而快乐的生活有三点缺陷,这就是为什么积极心理学不是快乐学、不只 研究如何取乐。第一点缺陷:快乐的生活,也就是对积极情绪的体验,看来是可以遗传的。就快乐而言,遗传起了百分之五十的作用,并且快乐的状态很难更改。第 二点缺陷:人们很快会对积极情绪产生适应。快乐就像法国香草冰淇淋,第一次品尝是百分之百的美味,六次之后,滋味全无。第三点缺陷就是我刚才说的难以更改 了。

  下面就要谈谈第二种幸福生活了。我想说说我朋友Len。他的例子告诉我们:幸福不仅仅是积极情绪,不仅仅是寻欢作乐。三十岁的时候,Len在生活中的三个领域中的两个非常成功。第一个领域是工作,他是个期权交易商,二十五岁时就已经身价百万,还拥有自己的期权交易公司。第二个领域是玩乐,他是位全国桥牌冠军。但在第三个领域,也就是爱情方面,Len却一败涂地。原因在于Len是个缺乏激情的人(底下的科学家发出会意的笑声),性格很内向。Len和美国女性约会时,对方都会说他没意思,说他没有积极情绪,还叫他滚蛋。Len很有钱,请得起最好的心理医生,医生花了五年时间,试图发掘将积极情绪压抑在他心底的性创伤,但结果什么性创伤都没有找到。Len在积极情绪(positive affectivity)方面处于人群中的末百分之五。我们能说Len不幸福吗?我认为不能。我觉得在我认识的人当中,Len属于最幸福的那群。这是因为Len和各位一样,很擅于获得涌动体验。他早上九点去美国证券交易所上班时,就觉得时间停止了;桥牌巡回赛开始时,他同样觉得时间停止。这就是我们所说的"涌动"了。涌动和快乐有一个重要的区别。快乐的时候,你能感觉到自己的快乐;可是Len昨 天跟我说,在涌动体验中,你什么都感觉不到,你觉得时间停止,心无旁鹜,而这就是我们所谓的"好生活"的特征。获得涌动的诀窍,就是了解你自己还有什么未 被发挥的长处。在我们的网站上还有个量表,能测量你在五个方面的长处。知道结果之后,你就可以重新设计自己的生活,以尽可能多地发挥自己的长处。重新设计 的方面包括工作、恋爱、玩乐、交友、和哺育。你从中获得的好处并非欢笑,而是获得更大的专注。

  好了。第一条路径是积极情绪,第二条路径是涌动体验。第三条路径呢,就是意义了,这是幸福感中最可敬的方面。意义和涌动有相似之处,它包含了几点要素:了解你的长处在哪里;使用你的长处,投身于超出个人的事业。

  刚才谈了三种生活:快 乐的生活,参与的生活,和有意义的生活。我们目前研究的问题是:有没有什么东西能持续改变这三种生活?答案看来是肯定的,下面我就给各位看几个例子。我们 的研究很严格,用的方法和药物测试相同。我们对被试进行了随机分配,对安慰剂效应进行了控制,对不同的干预方式进行了长期研究。

  我们发现了几种有效的干预方法:当我们指导人们如何获得快乐的生活时,我们发现,有效的方法是运用留意技巧(mindfulness skills)和品位技巧(savoring skills)来为自己设计美好的一天。我们可以证明,被试生活中的快乐感确实增强了。

  另一种干预方法是感恩拜访(Gratitude visit),希望各位能跟我一起做:闭上双眼,回忆一下在你的生活中造成巨大转变、使你的人生得到改善、而你又没有认真感谢过的那个人,必须是个仍然健在的人。好了,现在请睁眼,相信各位心目中都有这样一个人吧。诸位的任务是给那个人写一封300字的感谢信,然后给对方打个电话,问他你能否登门拜访,别告诉他原因,见面时,你对他念出这封信,在场的人都会感动到哭。一周后、一个月、三个月之后,双方都变得更快乐、不再抑郁了。

  还有一种干预方法是长处约会(strengths date),我们让伴侣说出各自的长处,接着我们设计一个晚间约会,让他们各自的长处都能在其中得到施展,我们发现,这样的约会能让双方的关系变得牢固。

  "快乐对慈善"(Fun vs Philanthropy) 也是一种方法。这种方法对在座各位不大适用,因为你们中的很多人已经投身慈善了。而我教的本科生和我的委托人还不了解这点,于是我让他们做些协助他人的 事,再做些快乐的事,然后比较两种活动后的感受,他们发现,取乐所获得的乐趣很快消退,但帮助他们所获得的乐趣持续了下去。

  积极干预的例子说到这 里。下面我们谈谈人们的生活满意度。我们想知道对快乐、参与、和意义的追求各自在生活满意度中起到什么作用,于是我们对上千人进行了调查。结果出人意料, 我们发现,对快乐的追求几乎不起什么作用。对意义的追求起的作用最大。对参与的追求同样起很大作用。当你对某事有参与感,也获得了意义感,快乐就如锦上添 花。如果你在生活中同时获得了三者,你就拥有了充实的人生,整体大于部分之和。如果你没有获得三者,你的人生就是空虚的,那么整体就小于部分之和了。在企 业中,生产效率是否是参与、意义、和快乐的函数?同样,健康是否是三者的函数?答案或许是肯定的。

  Chirs说, 最后演讲的人能对他听到的内容做一番总结,很高兴我能有这个机会。在我看来,心理学所面临的问题,和技术、娱乐、以及设计所面临的问题是相似的。我们都知 道,技术、娱乐、和设计可以用作毁灭性目的。我们还知道,三者能用来减轻痛苦。顺便说一句,减轻痛苦和建立幸福之间的关系至关重要。三十年前,我刚做治疗 师,那时候,我觉得只要能让病人不再抑郁、不再焦虑、不再愤怒,那么,我就能使他们幸福。事实并非如此,最佳疗效是让病人归零,他们的内心变得空虚。我后 来发现,获得幸福生活的技巧,也就是获得快乐、参与、和意义的技巧,与减轻病患痛苦的技巧并不相同。我相信,技术、娱乐、和设计方面也是一样。人类社会的 这三种动力能用来增加幸福感,增加积极情绪,人们也确实在这样使用它们。然而,如果各位像我这样分析幸福,不仅仅着眼于快乐,同时也看到涌动体验和意义 感,那么设计、技术、和娱乐也能用来增强生活中的这两个方面。

  总 而言之,我们应当保持乐观的第十一个理由,就是我相信,设计、技术和娱乐能增强全世界人类的幸福感。如果技术能在未来的十到二十年内能帮助人们获得快乐的 生活、参与的生活、和有意义的生活,那么,它就是足够好的。如果娱乐也能起到这三个作用,那么,它就是足够好的。如果设计能起到这三个作用,那么,它就是 足够好的。谢谢各位。

转载原创文章请注明,转载自:科学松鼠会[http://songshuhui.net/]
本文链接: http://songshuhui.net/archives/1066.html



20 August 2008

c与c#数据类型对应关系

API与C#数据结构类型对应关系表

API与C#的数据类型对应关系表
API数据类型 类型描述 C#类型 API数据类型 类型描述 C#类型
WORD 16位无符号整数 ushort CHAR 字符 char
LONG 32位无符号整数 int DWORDLONG 64位长整数 long
DWORD 32位无符号整数 uint HDC 设备描述表句柄 int
HANDLE 句柄,32位整数 int HGDIOBJ GDI对象句柄 int
UINT 32位无符号整数 uint HINSTANCE 实例句柄 int
BOOL 32位布尔型整数 bool HWM 窗口句柄 int
LPSTR 指向字符的32位指针 string HPARAM 32位消息参数 int
LPCSTR 指向常字符的32位指针 String LPARAM 32位消息参数 int
BYTE 字节 byte WPARAM 32位消息参数 int


C# 数据类型

简单类型
描 述
示 例
sbyte 8-bit 有符号整数 sbyte val = 12;
short 16-bit 有符号整数 short val = 12;
int 32-bit有符号整数 int val = 12;
long 64-bit有符号整数 long val1 = 12; long val2 = 34L;
byte 8-bit无符号整数 byte val1 = 12; byte val2 = 34U;
ushort 16-bit 无符号整数 ushort val1 = 12; ushort val2 = 34U;
uint 32-bit 无符号整数 uint val1 = 12; uint val2 = 34U;
ulong  64-bit 无符号整数 ulong val1 = 12; ulong val2 = 34U; ulong val3 = 56L; ulong val4 = 78UL;
float 32-bit单精度浮点数 float val = 1.23F;
double 64-bit双精度浮点数 double val1 = 1.23; double val2 = 4.56D;
l 布尔类型 bool val1 = true; bool val2 = false;
char 字符类型 ,Unicode编码 char val = 'h';
decimal 28个有效数字的128-bit十进制类型 decimal val = 1.23M;

 

C#中调用Windows API时的数据类型对应关系

BOOL=System.Int32
BOOLEAN=System.Int32
BYTE=System.UInt16
CHAR=System.Int16
COLORREF=System.UInt32
DWORD=System.UInt32
DWORD32=System.UInt32
DWORD64=System.UInt64
FLOAT=System.Float
HACCEL=System.IntPtr
HANDLE=System.IntPtr
HBITMAP=System.IntPtr
HBRUSH=System.IntPtr
HCONV=System.IntPtr
HCONVLIST=System.IntPtr
HCURSOR=System.IntPtr
HDC=System.IntPtr
HDDEDATA=System.IntPtr
HDESK=System.IntPtr
HDROP=System.IntPtr
HDWP=System.IntPtr
HENHMETAFILE=System.IntPtr
HFILE=System.IntPtr
HFONT=System.IntPtr
HGDIOBJ=System.IntPtr
HGLOBAL=System.IntPtr
HHOOK=System.IntPtr
HICON=System.IntPtr
HIMAGELIST=System.IntPtr
HIMC=System.IntPtr
HINSTANCE=System.IntPtr
HKEY=System.IntPtr
HLOCAL=System.IntPtr
HMENU=System.IntPtr
HMETAFILE=System.IntPtr
HMODULE=System.IntPtr
HMONITOR=System.IntPtr
HPALETTE=System.IntPtr
HPEN=System.IntPtr
HRGN=System.IntPtr
HRSRC=System.IntPtr
HSZ=System.IntPtr
HWINSTA=System.IntPtr
HWND=System.IntPtr
INT=System.Int32
INT32=System.Int32
INT64=System.Int64
LONG=System.Int32
LONG32=System.Int32
LONG64=System.Int64
LONGLONG=System.Int64
LPARAM=System.IntPtr
LPBOOL=System.Int16[]
LPBYTE=System.UInt16[]
LPCOLORREF=System.UInt32[]
LPCSTR=System.String
LPCTSTR=System.String
LPCVOID=System.UInt32
LPCWSTR=System.String
LPDWORD=System.UInt32[]
LPHANDLE=System.UInt32
LPINT=System.Int32[]
LPLONG=System.Int32[]
LPSTR=System.String
LPTSTR=System.String
LPVOID=System.UInt32
LPWORD=System.Int32[]
LPWSTR=System.String
LRESULT=System.IntPtr
PBOOL=System.Int16[]
PBOOLEAN=System.Int16[]
PBYTE=System.UInt16[]
PCHAR=System.Char[]
PCSTR=System.String
PCTSTR=System.String
PCWCH=System.UInt32
PCWSTR=System.UInt32
PDWORD=System.Int32[]
PFLOAT=System.Float[]
PHANDLE=System.UInt32
PHKEY=System.UInt32
PINT=System.Int32[]
PLCID=System.UInt32
PLONG=System.Int32[]
PLUID=System.UInt32
PSHORT=System.Int16[]
PSTR=System.String
PTBYTE=System.Char[]
PTCHAR=System.Char[]
PTSTR=System.String
PUCHAR=System.Char[]
PUINT=System.UInt32[]
PULONG=System.UInt32[]
PUSHORT=System.UInt16[]
PVOID=System.UInt32
PWCHAR=System.Char[]
PWORD=System.Int16[]
PWSTR=System.String
REGSAM=System.UInt32
SC_HANDLE=System.IntPtr
SC_LOCK=System.IntPtr
SHORT=System.Int16
SIZE_T=System.UInt32
SSIZE_=System.UInt32
TBYTE=System.Char
TCHAR=System.Char
UCHAR=System.Byte
UINT=System.UInt32
UINT32=System.UInt32
UINT64=System.UInt64
ULONG=System.UInt32
ULONG32=System.UInt32
ULONG64=System.UInt64
ULONGLONG=System.UInt64
USHORT=System.UInt16
WORD=System.UInt16
WPARAM=System.IntPtr


附:举一个声明API的例子

[ DllImport( "Kernel32.dll" )]
public static extern System.UInt32 VirtualAllocEx(
System.IntPtr hProcess,
System.UInt32 lpAddress,
System.UInt32 dwSize,
System.UInt32 flAllocationType,
System.UInt32 flProtect
);

 

29 July 2008

Christian the Lion

John Rendall and Ace Berg found a cub for sale at Harrod's in a cramped space. They bought the cub and named him Christian. They played with Christian on the grounds of a church until he became to big to keep at home. The introduced him back into the wild of Africa.
One year later they went to see Christian in the wild. They were told that the lion was wild now, the head of his own pride and would not remember them. Here is their
courageous story.

Christian, the lion who lived in my London living room

By VICTORIA MOORE
Last updated at 23:24 04 May 2007
 
He travelled by Bentley, ate in fine London restaurants and spent his days lounging in a furniture shop. The story of Christian the pet lion - and his eventual release into the wild - is as moving as it is incredible.

The furniture shop was on the King's Road in London. It sold tables, wardrobes, chairs and desks - but anybody peering through its plate-glass window on a Sunday might have noticed something rather more unusual.

Amid all the pine and oak, stretched out languidly on a bench, there was a lion. And it wasn't stuffed.

Scroll down for more...

Tiger feet: Christian enjoyed living in swinging London

Tiger feet: Christian enjoyed living in swinging London

"Christian used to lie beside me while I did the accounts at weekends," remembers Jennifer Mary Taylor, who worked there.

"And every so often, if I'd ignored him for too long, he'd sock me across the head with one of his great big paws.

"He was very loving and affectionate - he liked to stand and put his paws on your shoulders. But he was...", she pauses. "I mean, he was a lion. Does that sound silly?"

Christian the lion (named by someone with a Biblical sense of humour) arrived in

Chelsea at a time when the King's Road - home to Mick Jagger - was the very heart of the Swinging Sixties.

For a year, the Big Cat was part of it all, cruising the streets in the back of a Bentley, popping in for lunch at Casserole, a local restaurant, even posing for a Biba fashion advert.

He eventually grew too big to be kept as a pet and was taken to Kenya, where he was rehabilitated into the wild by the 'Lion Man', George Adamson.

Now, his story is to be told in a new book, written by the Australian John Rendall who, along with his friend Ace Berg, bought Christian from Harrods in 1969.

John Rendall's Chelsea flat

London pride: At home in John Rendall's Chelsea flat

So what possessed them to buy a lion cub in the first place?

"A friend had been to the 'exotic animals' department at Harrods and announced, rather grandly, that she wanted a camel," says Rendall.

"To which the manager very coolly replied: 'One hump or two, madam?'

"Ace and I thought this was the most sophisticated repartee we'd ever heard, so we went along to check it out - and there, in a small cage, was a gorgeous little lion cub. We were shocked. We looked at each other and said something's got to be done about that."

Harrods, it turned out, was also quite keen to be rid of Christian, who had escaped one night, sneaked into the neighbouring carpet department - then in the throes of a sale of goatskin rugs - and wreaked havoc.

The store, which had acquired the cub from Ilfracombe zoo, happily agreed to part with him for 250 guineas. So began Christian's year as an urban lion.

Today, it would be unthinkable for a shop to take such a cavalier attitude towards selling exotic animals (though Harrods did, at least, provide Ace and Rendall with diet sheets).

And it is hard to imagine either the animal rights lobby or any local council condoning a shop as a suitable habitat for a lion. But, back then, no one minded at all.

Christian was given his own living quarters (and a very large kitty-litter tray, which he used unfailingly) in the basement of the appropriately named Sophistocat furniture shop.

"He had a beautiful musky smell that was very distinct," says Rendall. "But he was clean."

The vicar of the Moravian Chapel nearby was approached to allow Christian the run of the graveyard, and every day he was taken there to roar around and play football.

Once, when he was brought along to a seaside picnic, he dipped his toes reluctantly in the water and intimated with a shudder that it was disagreeably cold. But he was eventually persuaded to swim in the English Channel.

"He was a lot of work," says Rendall. "It took all four of us - me, my then girlfriend Jennifer Mary, Ace Berg and an actress called Unity Jones - to look after him.

Cat's pyjamas: Christian, rummaging through the drawers

Cat's pyjamas: Christian, rummaging through the drawers

"He also ate a lot, four meals (two liquid, two solid) plus supplements every day, which cost about £30 a week - a lot of money back then."

He pauses, then adds, "And he had a very good sense of humour."

Really?

"Oh yes. Sometimes, he'd see people staring at him through the back window of the car, keep very still on purpose - and then, just when they were convinced he was a stuffed toy, he would very slowly turn his head and freak them out."

Everyone loved Christian and he became a popular local figure. In 1970, when Chelsea beat Leeds in the FA Cup Final, Sophistocat received a call from a policeman, 'The football fans are going to be boisterous, so you'd better get your bloody lion out of the window or they'll smash it in,' he warned.

Christian himself was beautifully behaved, and though he never hurt anyone, you underestimated his strength at your peril.

Jennifer Mary remembers taking a friend to see him, "after I'd had one or two glasses of wine -and when he put his paws on my shoulders, one of them slipped, his claw caught my dress and he pulled the whole front of it off."

He grew and grew - from 35lb when he first arrived to a rather more serious and imposing 185lb a year later - and he was beginning to acquire a mane that made him look more fearsome.

He clearly could not stay with his two young owners for ever.

His future was decided by a chance encounter - when the actors Bill Travers and Virginia McKenna walked into the shop to buy a pine desk.

They had recently starred in the film Born Free, which tells the true story of the wildlife conservationist George Adamson and his wife Joy, who raised a lion cub called Elsa in Kenya then rehabilitated it into the wild.

And they immediately suggested that Adamson might be able to help.

Certainly, the conservationist was intrigued by the challenge of introducing a King's Road lion to the wilds of Africa.

"But," he warned, '"ou must be prepared for this not to work. Elsa was born in Africa and she knew its smells. Taking a British-born lion, whose parents were also raised in captivity, is going to be a very different thing."

Christian was flown to Kenya in a specially-made crate emblazoned with the words, 'East African Airways. London-Nairobi. Christian - male lion, 12 months'. John and Ace went with him.

"I think George Adamson got quite a shock when he met us," says Rendall. "Straight from the King's Road, in all our gear - flares from Granny Takes A Trip, and with hair everywhere.

"We looked rather different from everyone else in Nairobi. But then so did Christian. He'd come from winter in England, so had a very thick coat - he was almost as hairy as we were."

Adamson wanted to drive straight to the Kora Reserve, close to the Tana river, where there was no human habitation. This, he felt, would be the ideal spot to build a camp.

Because lions live and hunt in prides, and it is hard to impose a new male on an existing one, the plan was to introduce Christian into the wild in tandem with Boy, one of the tame beasts who had starred in Born Free.

Together, they would form the nucleus of a new pride - and the whole project would be funded by a TV programme.

Christian was marshalled into the back of a Land Rover, with straw on the floor and chicken-wire separating him from his friends on the front seat. It was all rather confusing for a lion accustomed to the butter-soft leather of a Bentley. And he was hot. And dusty. And confused.

Not long into the journey, Rendall ventured, "Mr Adamson, he needs to go to the loo."

Adamson was impatient.

"We're miles from anywhere. If we stop here and he runs away, we will never, ever catch him."

"Mr Adamson," promised Rendall, "that is not going to happen."

The great Lion Man turned his head, sucked on his pipe and pulled over on the dirt road.

Rendall opened the back of the car, and Christian jumped out to take his first real steps on African soil.

To his evident disgust, it was prickly and hot. He clearly didn't like it one bit.

Rendall picks up the story, "So he went tip-toeing along and went to the loo.

Considerably. Then he looked around and I said, 'OK, come on, back in,' pointed back at the car - and in he jumped.

"I got back in the car, too, shut the door and George Adamson turned round and said to me, 'That is quite remarkable. You may call me George.'"

Kora, an area that now has National Park status, lies about 220 miles to the north-east of Nairobi. The scenery is rugged - densely packed with knotty thorn bushes, with just a narrow corridor of greenery that follows the course of the Tana river.

And so Christian arrived at the camp, which Adamson's brother had built from macuti - palm fronds - chicken-wire and mud.

The conservationist went off again and returned a couple of days later with Boy, the lion from Born Free.

At that time, Boy was very fragile, as his shoulder had been shattered in a nasty encounter with a buffalo. But he was the first fully-grown lion that Christian had seen since leaving Ilfracombe zoo as a cub.

The first meeting was explosive. Normal lion protocol dictates that the younger male should be subservient to the dominant male.

But Christian, more schooled in Sloane than feline etiquette, sashayed fearlessly towards Boy.

Fortunately, Christian and Boy, though in adjacent compounds, were separated by a wire fence. In fury at the perceived slight, Boy flung himself against it - until Christian, suddenly realising his faux pas, slunk away with his belly close to the ground.

This process was repeated over and over again until Adamson felt confident enough to allow the pair to meet without the safety barrier of the fence.

"First, Boy left his compound," recalls Rendall. "Then Christian went out to meet him.

"Boy took one look - and he clobbered him. Christian didn't fight back. He rolled over on his back. That went on for day after day, until Boy was obviously satisfied that Christian knew who was boss - and they became totally inseparable."

Adamson had also acquired a female lion cub, Katania, to add to the pride, and she seemed to act as an intermediary between the two males.

Each day, the three lions would go out for a walk in the bush, Boy first, Katania in the middle, then Christian - with Adamson, carrying a rifle in case he needed to scare anything off, at the rear.

For Christian, there were some tricky moments, such as the time he spied a rhino and tried to stalk it, only for the beast to hurl him through the air in a cloud of dust.

"I saw Boy turn and look at Christian," says Rendall. "There was a look on his face, as if to say: 'You absolute fool. What a howler of a blunder.'"

Slowly, progress was made. The biggest threat to Christian and Boy were the wild lions that stalked the reserve, which Boy was fighting to establish as his territory.

Then, one day, there was a tragedy that caused the whole project to be called into question. A chef called Stanley had left the safety of the compound to look for wild honey. He hadn't realised Boy was nearby, and when he saw him, he tried to flee.

Running away was the worst action he could have taken. Adamson, hearing Stanley's screams, came running and shot Boy through the heart - but it was too late. Stanley had been bitten through the jugular and died an hour later.

The outcry that followed almost brought the lion project to a halt, but Adamson found some support for his work among other conservationists, dug in his heels and carried on.

John Rendall and Ace Berg continued to make sporadic visits to Kenya, but mostly they followed Christian's adventures from afar.

Finally, in 1974, George Adamson wrote to say that the pride was self-sufficient. Christian was defending it. There was a litter of cubs. They were feeding themselves and rarely returned to camp.

The King's Road lion had finally adapted to the wild.

This was a bittersweet moment for all concerned. Rendall and Ace decided to travel to Kora one last time, in the hope of being able to say goodbye, though Adamson warned them that it would almost certainly be a wasted mission.

"Christian hasn't been here for nine months. We have no reason to think he's dead - there have been no reports of lions poached or killed. But he may never come back," he said.

Rendall recalls, "We said: 'OK. We appreciate that, but we'll come anyway and see you.'"

They flew to Nairobi then took a small plane to the camp in Kora, where Adamson came out to meet them.

"Christian arrived last night, " he said simply. "He's here with his lionesses and his cubs. He's outside the camp on his favourite rock. He's waiting for you."

Adamson and his wife Joy often talked about the mysterious, apparently telepathic communication skills of lions - particularly between lions and men.

Both believed that lions were possessed of a sixth sense and George was convinced that a scientific explanation would one day be found.

And here, it seemed, was the proof.

"Christian stared at us in a very intense way," says Rendall. "I knew his expressions and I could see he was interested. We called him and he stood up and started to walk towards us very slowly.

"Then, as if he had become convinced it was us, he ran towards us, threw himself on to us, knocked us over, knocked George over and hugged us, like he used to, with his paws on our shoulders.

"Everyone was crying. We were crying, George was crying, even the lion was nearly crying."

"The lionesses were far from pleased. There was a lot of growling and spitting," continues Rendall.

"'George said: 'This isn't safe - we'd better go.' So we each put a hand on Christian's back and he walked with us back to camp."

The reunion party went on all night and into the morning. Leaving his exhausted companions to go to their beds, Christian returned to his pride.

"We watched him go back to the two lionesses, who were not at all happy with this man, smelling of nicotine, whisky and humans," says Rendall.

"He just walloped the two of them with his paw, then collapsed."

And that was the last anyone ever saw of him.

For the next 14 years, George Adamson remained at Kora, rehabilitating several other lions and ignoring warnings from the authorities, who did not consider it safe for him to stay.

Then, in 1989, he was ambushed and murdered by bandits.

He died with a gun in his hand and, in accordance with his wishes, was buried at Kora.

Following his death, his supporters formed the George Adamson Wildlife Preservation Trust, which now does work in Kora as well as in Tanzania, where it is reintroducing the endangered black rhino and hunting dog.

The trust's chief aim is keep alive Adamson's dream of a place where animals can roam free - a fitting epitaph not just for the great conservationist but also for the lion who once lived in Chelsea.
 
 
 

24 July 2008

什么是回调函数 (Call Back)

 1)
最简单的说就是由你编写,但由Windows调用的函数
其实跟一般的函数没有什么特别区别,只是回调函数的形式是规定好的(就是返回值,形参数等等),你可以改变的值就是函数的名称:)
回调函数不用你去直接调用,而是由调用这个回调函数的函数来调用
2)
回调函数的形式是规定好的(就是返回值,形参数等等),实质是函数指针,传给调用函数的参数是函数指针
3)
回调函数简单的说就是在每个时间要用的函数,但是当时没有函数体,
相当于纯虚函数!
 
4)
个人观点:
回调函数,用户写系统调用的函数。
系统:广义,可能是函数、程序、操作系统,不局限于windows
用户:广义,与系统对应
 
5)
回调函数其实跟普通函数是一样的,只不过调用者不是你,而是系统,系统会根据你设计的回调的函数完成相关的工作。比如,你创建一个窗口时,你要设计一个回调函数,告诉它窗口的消息如何映射;再如创建一个定时(NUL器时,用SetTimer(L,1000,TimerProc);这个TimerProc就是一个回调函数,你可以这个函数里写一些你要的操作,它就会在1秒内重复做一样的事
 
 
6) 转载:
回调函数,就是由你自己写的。你需要调用另外一个函数,而这个函数的其中一个参数,就
是你的这个回调函数名。这样,系统在必要的时候,就会调用你写的回调函数,这样你就可
以在回调函数里完成你要做的事。
模块A有一个函数foo,它向模块B传递foo的地址,然后在B里面发生某种事件(event)时,通过从A里面传递过来的foo的地址调用foo,通知A发生了什么事情,让A作出相应反应。 那么我们就把foo称为回调函数。
  
例子:
     回调函数是一个很有用,也很重要的概念。当发生某种事件时,系统或其他函数将会自动调用你定义的一段函数。回调函数在windows编程使用的场合很多,比如Hook回调函数:MouseProc,GetMsgProc以及EnumWindows,DrawState的回调函数等等,还有很多系统级的回调过程。本文不准备介绍这些函数和过程,而是谈谈实现自己的回调函数的一些经验。
     之所以产生使用回调函数这个想法,是因为现在使用VC和Delphi混合编程,用VC写的一个DLL程序进行一些时间比较长的异步工作,工作完成之后,需要通知使用DLL的应用程序:某些事件已经完成,请处理事件的后续部分。开始想过使用同步对象,文件影射,消息等实现DLL函数到应用程序的通知,后来突然想到可不可以在应用程序端先写一个函数,等需要处理后续事宜的时候,在DLL里直接调用这个函数即可。  
      于是就动手,写了个回调函数的原形。在VC和 Delphi里都进行了测试
一:声明回调函数类型。
       vc版
              typedef int (WINAPI *PFCALLBACK)(int Param1,int Param2) ;
       Delph版
              PFCALLBACK = function(Param1:integer;Param2:integer):integer;stdcall;
       实际上是声明了一个返回值为int,传入参数为两个int的指向函数的指针。
       由于C++和PASCAL编译器对参数入栈和函数返回的处理有可能不一致,把函数类型用WINAPI(WINAPI宏展开就是__stdcall)或stdcall统一修饰。
二:声明回调函数原形
       声明函数原形
      vc版
               int WINAPI CBFunc(int Param1,int Param2);
       Delphi版
          function CBFunc(Param1,Param2:integer):integer;stdcall;            
      以上函数为全局函数,如果要使用一个类里的函数作为回调函数原形,把该类函数声明为静态函数即可。

三: 回调函数调用调用者
         调用回调函数的函数我把它放到了DLL里,这是一个很简单的VC生成的WIN32 DLL.并使用DEF文件输出其函数名 TestCallBack。实现如下:
              PFCALLBACK  gCallBack=0;

            void WINAPI TestCallBack(PFCALLBACK Func)
           {
                  if(Func==NULL)return;
                  gCallBack=Func;
                  DWORD ThreadID=0;
                  HANDLE hThread = CreateThread(  NULL,  NULL,  Thread1,   LPVOID(0),          &ThreadID );
                   return;
             }
      此函数的工作把传入的 PFCALLBACK Func参数保存起来等待使用,并且启动一个线程。声明了一个函数指针PFCALLBACK gCallBack保存传入的函数地址。
四: 回调函数如何被使用:
          TestCallBack函数被调用后,启动了一个线程,作为演示,线程人为的进行了延时处理,并且把线程运行的过程打印在屏幕上.
本段线程的代码也在DLL工程里实现
      ULONG  WINAPI Thread1(LPVOID Param)
     {

             TCHAR Buffer[256];
             HDC hDC = GetDC(HWND_DESKTOP);
             int Step=1;
             MSG Msg;
              DWORD StartTick;
        //一个延时循环
             for(;Step<200;Step++)
             {
                        StartTick = GetTickCount();
                  /*这一段为线程交出部分运行时间以让系统处理其他事务*/
                       for(;GetTickCount()-StartTick<10;)
                         {
                                 if(PeekMessage(&Msg,NULL,0,0,PM_NOREMOVE) )
                                 {
                                   TranslateMessage(&Msg);
                                   DispatchMessage(&Msg);
                                   }
                           }                               
                      /*把运行情况打印到桌面,这是vcbear调试程序时最喜欢干的事情*/
           sprintf(Buffer,"Running %04d",Step);
                         if(hDC!=NULL)
                                  TextOut(hDC,30,50,Buffer,strlen(Buffer));
                   }

                /*延时一段时间后调用回调函数*/ 
                (*gCallback)(Step,1);

                 /*结束*/
                   ::ReleaseDC (HWND_DESKTOP,hDC);
                  return 0;
      }
五:万事具备
        使用vc和Delphi各建立了一个工程,编写回调函数的实现部分
       VC版
     int WINAPI CBFunc(int Param1,int Param2)
       {
               int res= Param1+Param2;
             TCHAR Buffer[256]="";
            sprintf(Buffer,"callback result = %d",res);
            MessageBox(NULL,Buffer,"Testing",MB_OK);  //演示回调函数被调用
             return res;           
       }  

         Delphi版
          function CBFunc(Param1,Param2:integer):integer;
          begin
                  result:= Param1+Param2;
                  TForm1.Edit1.Text:=inttostr(result);    / /演示回调函数被调用
           end;
       
       使用静态连接的方法连接DLL里的出口函数 TestCallBack,在工程里添加 Button( 对于Delphi的工程,还需要在Form1上放一个Edit控件,默认名为Edit1)。
        响应ButtonClick事件调用 TestCallBack

              TestCallBack(CBFunc) //函数的参数CBFunc为回调函数的地址

        函数调用创建线程后立刻返回,应用程序可以同时干别的事情去了。现在可以看到屏幕上不停的显示字符串,表示dll里创建的线程运行正常。一会之后,线程延时部分结束结束,vc的应用程序弹出MessageBox,表示回调函数被调用并显示根据Param1,Param2运算的结果,Delphi的程序edit控件里的文本则被改写成Param1,Param2 的运算结果。
        可见使用回调函数的编程模式,可以根据不同的需求传递不同的回调函数地址,或者定义各种回调函数的原形(同时也需要改变使用回调函数的参数和返回值约定),实现多种回调事件处理,可以使程序的控制灵活多变,也是一种高效率的,清晰的程序模块之间的耦合方式。在一些异步或复杂的程序系统里尤其有用 -- 你可以在一个模块(如DLL)里专心实现模块核心的业务流程和技术功能,外围的扩展的功能只给出一个回调函数的接口,通过调用其他模块传递过来的回调函数地址的方式,将后续处理无缝地交给另一个模块,随它按自定义的方式处理。
      本文的例子使用了在DLL里的多线程延时后调用回调函数的方式,只是为了突出一下回调函数的效果,其实只要是在本进程之内,都可以随你高兴可以把函数地址传递来传递去,当成回调函数使用。
       这样的编程模式原理非常简单单一:就是把函数也看成一个指针一个地址来调用,没有什么别的复杂的东西,仅仅是编程里的一个小技巧。至于回调函数模式究竟能为你带来多少好处,就看你是否使用,如何使用这种编程模式了。
另外的解释:cdxiaogan
msdn上这么说的:
有关函数指针的知识
使用例子可以很好地说明函数指针的用法。首先,看一看 Win32 API 中的 EnumWindows 函数:
Declare Function EnumWindows lib "user32" _
(ByVal lpEnumFunc as Long, _
ByVal lParam as Long ) As Long
EnumWindows 是一个枚举函数,它能够列出系统中每一个打开的窗口的句柄。EnumWindows 的工作方式是重复地调用传递给它的第一个参数(lpEnumFunc,函数指针)。每当 EnumWindows 调用函数,EnumWindows 都传递一个打开窗口的句柄。
在代码中调用 EnumWindows 时,可以将一个自定义函数作为第一个参数传递给它,用来处理一系列的值。例如,可以编写一个函数将所有的值添加到一个列表框中,将 hWnd 值转换为窗口的名字,以及其它任何操作!
为了表明传递的参数是一个自定义函数,在函数名称的前面要加上 AddressOf 关键字。第二个参数可以是合适的任何值。例如,如果要把 MyProc 作为函数参数,可以按下面的方式调用 EnumWindows:
x = EnumWindows(AddressOf MyProc, 5)
在调用过程时指定的自定义函数被称为回调函数。回调函数(通常简称为"回调")能够对过程提供的数据执行指定的操作。
回调函数的参数集必须具有规定的形式,这是由使用回调函数的 API 决定的。关于需要什么参数,如何调用它们,请参阅 API 文档。

我谈一下自己对回调函数的一点理解, 不对的地方请指教.
    我刚开始接触回调时, 也是一团雾水.很多人解释这个问题时, 总是拿API来举例子, 本来菜鸟最惧怕的就是API, ^_^. 回调跟API没有必然联系.
    其实回调就是一种利用函数指针进行函数调用的过程.
   
    为什么要用回调呢?比如我要写一个子模块给你用, 来接收远程socket发来的命令.当我接收到命令后, 需要调用你的主模块的函数, 来进行相应的处理.但是我不知道你要用哪个函数来处理这个命令,  我也不知道你的主模块是什么.cpp或者.h, 或者说, 我根本不用关心你在主模块里怎么处理它, 也不应该关心用什么函数处理它...... 怎么办?
    使用回调.
    我在我的模块里先定义回调函数类型, 以及回调函数指针.
    typedef void (CALLBACK *cbkSendCmdToMain) (AnsiString sCmd);
    cbkSendCmdToMain    SendCmdToMain;
    这样SendCmdToMain就是一个指向拥有一个AnsiString形参, 返回值为void的函数指针.
    这样, 在我接收到命令时, 就可以调用这个函数啦.
    ...
    SendCmdToMain(sCommand);
    ...
    但是这样还不够, 我得给一个接口函数(比如Init), 让你在主模块里调用Init来注册这个回调函数.
    在你的主模块里, 可能这样
    void CALLBACK YourSendCmdFun(AnsiString sCmd);  //声明
    ...
    void CALLBACK YourSendCmdFun(AnsiString sCmd);  //定义
    {
        ShowMessage(sCmd);
    }
    ...
    调用Init函数向我的模块注册回调.可能这样:
    Init(YourSendCmdFun, ...);
    这样, 预期目的就达到了.

    需要注意一点, 回调函数一般都要声明为全局的. 如果要在类里使用回调函数, 前面需要加上 static  , 其实也相当于全局的.

 

Google