请问使用什么函数激活某个窗口

panyf_2k 2002-05-17 01:01:48
我是使用sdk写的,如下代码:
TopHwnd=FindWindow(NULL,TEXT("MyProg"));
BringWindowToTop(TopHwnd);

这样就把标题为MyProg的窗口置于所有窗口的最上面,可是它的标题栏还是呈灰色,即未被激活,那请问怎样使该窗口激活?

...全文
109 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
panyf_2k 2002-05-17
  • 打赏
  • 举报
回复
那请问我可以获得第二个应用程序的对话框的子控件的句柄吗?
cyber_girl 2002-05-17
  • 打赏
  • 举报
回复
AttachThreadInput,只能这样做,具体的请查MSDN或查老贴子,google也行

chen_fu 2002-05-17
  • 打赏
  • 举报
回复
无论GetFocus还是SetFocus,都需要有需要激活的窗口句柄
onell 2002-05-17
  • 打赏
  • 举报
回复
HWND hwndPrev ;
hwndPrev = FindWindow( CN_MAIN, m_lpszTitle) ;

if( hwndPrev)
{
PostMessage( hwndPrev, WM_SYSCOMMAND,SC_RESTORE, 0L);
SetForegroundWindow( hwndPrev) ;
SetWindowPos( hwndPrev, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE) ;
SetActiveWindow( hwndPrev) ;
return FALSE;
}
jackdong 2002-05-17
  • 打赏
  • 举报
回复
不好意思,上面是pWnd->SetFocus()
jackdong 2002-05-17
  • 打赏
  • 举报
回复
得到该窗口指针pWnd
执行pWnd->GetFocus()就行
zxs218 2002-05-17
  • 打赏
  • 举报
回复
SetForegroundWindow
The SetForegroundWindow function puts the thread that created the specified window into the foreground and activates the window. Keyboard input is directed to the window, and various visual cues are changed for the user. The system assigns a slightly higher priority to the thread that created the foreground window than it does to other threads.

TopHwnd=FindWindow(NULL,TEXT("MyProg"));

SetForegroundWindow(TopHwnd);0D

BOOL SetForegroundWindow(
0A HWND hWnd // handle to window
);
Parameters
hWnd
[in] Handle to the window that should be activated and brought to the foreground.
Return Values
If the window was brought to the foreground, the return value is nonzero.

If the window was not brought to the foreground, the return value is zero.


================================================================

CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!

★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。

★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。

Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar
Http://www.ChinaOK.net/csdn/csdn.exe [自解压]

zxs218 2002-05-17
  • 打赏
  • 举报
回复
SetForegroundWindow
The SetForegroundWindow function puts the thread that created the specified window into the foreground and activates the window. Keyboard input is directed to the window, and various visual cues are changed for the user. The system assigns a slightly higher priority to the thread that created the foreground window than it does to other threads.

BOOL SetForegroundWindow(
0A HWND hWnd // handle to window
);
Parameters
hWnd
[in] Handle to the window that should be activated and brought to the foreground.
Return Values
If the window was brought to the foreground, the return value is nonzero.

If the window was not brought to the foreground, the return value is zero.


================================================================

CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!

★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。

★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。

Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar
Http://www.ChinaOK.net/csdn/csdn.exe [自解压]

fhbkyo 2002-05-17
  • 打赏
  • 举报
回复
不需要用什么函数的吧,程序运行时获得焦点,即为当前窗口(激活状态)
cyber_girl 2002-05-17
  • 打赏
  • 举报
回复
先AttachThreadInput,然后才能真正地激活
Hover 2002-05-17
  • 打赏
  • 举报
回复
SetFocus()

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧