Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1639188
  • 博文数量: 584
  • 博客积分: 13857
  • 博客等级: 上将
  • 技术积分: 11883
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-16 09:34

分类: WINDOWS

2011-04-06 22:17:46

WS_EX_NOACTIVATE MSDN解释:



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风格即可.代码如下:
  1. BOOL CTestDlg::OnInitDialog()  
  2. {  
  3.     ...  
  4.     // LONG style = ::GetWindowLong(m_hWnd, GWL_EXSTYLE);  
  5.     // style &= ~WS_EX_NOACTIVATE;  
  6.     // ::SetWindowLong(m_hWnd, GWL_EXSTYLE, style);  
  7.     ModifyStyleEx(WS_EX_NOACTIVATE, 0);  
  8. }  
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的标准化做法.
阅读(1483) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~