CWnd.wndTopMost用法

时间:2014-10-20 09:13:08

标签: visual-c++ mfc

CWnd.wndTopMost用于什么?

在定义中我发现它是:

static AFX_DATA const CWnd wndTopMost;

宏AFX_DATA如何影响此行?

此代码:

this->wndTopMost.SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);

返回错误

'CWnd::SetWindowPos' : cannot convert 'this' pointer from 'const CWnd' to 'CWnd &'

为什么需要参考?此方法返回任何内容。

1 个答案:

答案 0 :(得分:2)

wndTopMost仅用于SetWindowPos的第一个参数。此变量用于在此窗口后的Z顺序中插入Window。

因此它被定义为const,因为它自己的窗口没有被修改。

在内部,它只是一个特殊句柄,其值为-1(外观here

通过这个技巧(const CWnd),没有人可以做你尝试过的事情。

如果你真的想对最顶层的窗口做一些事情,你必须使用GetTopWindow,GetActiveWindow或其他函数来检索句柄。