如何将焦点设置为所有者或其他窗口? [英] How to set focus to owner or another window?

查看:104
本文介绍了如何将焦点设置为所有者或其他窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CreateWindow创建一个窗口,比如窗口'A',窗口'A'创建窗口'B'。当'B'关闭时,焦点是'A',这是合理的。 buf如果在关闭'B'之前我点击另一个应用程序的窗口然后关闭'B',那么系统将焦点转移到该应用程序,而不是'A'。我想改变这种行为并直接尝试setfocus到窗口'A',但是我没有成功。我试过这些代码

I use CreateWindow to create a window, say window 'A', and window 'A' creates window 'B'. when 'B' is closed, focus is given to 'A', which is reasonable. buf if before closing 'B' I click on the window of another application and then close 'B', then the systems transfers focus to that application, not 'A'. I want to change this behaviour and try setfocus to window 'A' directly, buf I was not successfull. I tried these codes

SetFocus( hWndA );
SendMessage( hWndA, WM_SETFOCUS, 0, 0 );
PostMessage( hWndA, WM_SETFOCUS, 0, 0 );
SendMessage( hWndA, WM_APP, 0, 0 );
PostMessage( hWndA, WM_APP, 0, 0 );



其中窗口'A'通过将焦点设置为自身来响应WM_APP,并且没有一个工作。 SetFocus只是简单易行,任何身体都可以帮助我吗?


where window 'A' responds to WM_APP by setting focus to itself, and none of them workded. SetFocus simply failes, Can any body help me?

推荐答案

对于一个窗口,你应该激活它。焦点是控件的属性。更准确地说,这个键盘焦点;整个系统中一次只能控制一个控件。



你需要使用这个Windows API:

http://msdn.microsoft.com/en-us/library/ windows / desktop / ms646311%28v = vs.85%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/windows/desktop/ms633539%28v=vs.85% 29.aspx [ ^ ]。



当窗口完成前景并激活时,您可以对其中一个控件进行聚焦。



-SA
For a Window, you should activate it. A focus is a property of a control. More exactly, this keyboard focus; only one control at a time in the whole system can have it.

You need to use this Windows API:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646311%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633539%28v=vs.85%29.aspx[^].

When a window is done foreground and activated, you can focus one of its controls.

—SA


嗨。

一种方法,我想。

当'A '创建'B'窗口,你可以继承'A'的窗口句柄到'B'窗口。

,在windowprocmessage'B'中你可以实现WM_DESTROY如下。

1.通过把手将焦点设置为'A'窗口,从'A'窗口给出。

并关闭'B'window。

2 。使用ShowWindow函数作为参数,使用从'A'窗口获得的句柄。
Hi.
one method, I think.
When 'A' create 'B' window, you can inherit the 'A''s windows handle to 'B' window.
and in windowprocmessage of 'B', you can implement WM_DESTROY as follow.
1.set focus to 'A' window by handles, which is given from 'A' window.
and close 'B'window.
2.use ShowWindow function as parameter with the handles which you got from 'A' window.


最好使用ShowWindow(HWND hwnd)函数代替SetFocus()函数。 />
就这样做。

ShowWindow(hWndA,SW_HIDE);

ShowWindow(hWndA,SW_SHOW);



它将焦点设置为'A'窗口。
You might be better to use ShowWindow(HWND hwnd) function instead of SetFocus() function.
Just do like this.
ShowWindow(hWndA, SW_HIDE);
ShowWindow(hWndA, SW_SHOW);

it will set focus to 'A' window.


这篇关于如何将焦点设置为所有者或其他窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆