3-2

If AfxGetMainWnd is called from theapplication's primary thread, 
it returns the application'smain window according to the above rules. 
If the function is called from a secondary thread in the application, 
the function returns the main window associated with the thread that made thecall.

今天好像找到原因了~ 我那个线程是用CreateThread创建的,而 CreateThread是由
操作系统提供的接口,在 CreateThread创建的线程中用MFC的函数AfxGetMainWnd()会有问题.

摘自:BBS 水木清华站∶精华区

 如果用MFC编程,不要用CreateThread,如果只是使用Runtime Library,用 
_BegingThread,总之,不要轻易使用CreateThread 
这是因为在MFC和RTL中的函数有可能会用到些它们所封装的公用变量,也就是 
说AfxBeginThread和_BeginThread都有自己的启动代码是CreateThread所没有的 
在用CreateThread所创建的线程中使用MFC的类和RTL函数就有可能出现问题 
如果你是用汇编编写win32程序并且在线程函数中也不调用MFC和RTL的函数,那用 
CreateThread就没问题,或者你虽然是用C写线程函数,但你很小心没调用RTL函数 
也不会有问题 
// 这段看的云里雾里,有待深入?

CreateThread是由操作系统提供的接口,而AfxBeginThread和_BeginThread则是编译 
器对它的封装 

 

CWinApp* AFXAPI AfxGetApp( ); 
The pointer returned by this function can be used to access applicationinformation such as the main message-dispatch code or the topmost window.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值