WS_EX_NOACTIVATEWindows 2000/XP: A top-level
window created with this style does not become the foreground window
when the user clicks it. The system does not bring this window to the
foreground when the user minimizes or closes the foreground window.To
activate the window, use the SetActiveWindow or SetForegroundWindow
function.The window does not appear on the taskbar by default.
To force the window to appear on the taskbar, use the WS_EX_APPWINDOW
style.
我遇到的问题是:我的RichEdit控件所在的Dialog在启动的时候总是获得不到焦点,即使我把光标点到RichEdit里面,能够看到光标在闪,也不能进行输入,但是当我切换窗口后再切换回来.一切OK.我能够看到很明显的原因是当这个Dialog第一次启动时, Dialog本身没有获得焦点,处于不活动状态(NO ACTIVE),而当切换一次了, Dialog就得到了焦点.那怎样让Dialog第一次被创建进来时就是有焦点的呢?去掉WS_EX_NOACTIVATE风格即可.代码如下:
- BOOL CTestDlg::OnInitDialog()
- {
- ...
-
-
-
- ModifyStyleEx(WS_EX_NOACTIVATE, 0);
- }
BOOL CTestDlg::OnInitDialog()
{
...
// LONG style = ::GetWindowLong(m_hWnd, GWL_EXSTYLE);
// style &= ~WS_EX_NOACTIVATE;
// ::SetWindowLong(m_hWnd, GWL_EXSTYLE, style);
ModifyStyleEx(WS_EX_NOACTIVATE, 0);
} 第一种方法是SDK的做法,第二种方法是MFC的标准化做法.