C ++ Builder 2009 - 如何确定控件的窗口是否可见 [英] C++ Builder 2009 - How to Determine if Control's Window is Visible

查看:224
本文介绍了C ++ Builder 2009 - 如何确定控件的窗口是否可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 TWinControl ,并尝试确定父窗口是否可见。



我看到 TWinControl 具有属性 ParentWindow ParentWindow 的返回类型为 void * 。所以我很好奇,如果我必须投射到一个特定的类型,这将让我访问检查窗口是否可见。



有没有人知道我需要投放的类型,或以其他方式完成此操作?






其他疑难解答备注,第1部分:



我试图通过以下方式获取ParentWindows类:

  String parentWindowClassName =((TObject *)(Control-> ParentWindow)) - > ClassName(); 

但是这会导致访问冲突。我也试过铸造到TForm,这也给了访问违例,这使我相信父窗口可能由窗口控制。如果是这样,有没有人知道任何技巧检查,如果它是可见的?例如。任何COM技巧或任何?



其他疑难解答说明,第2部分:

此问题的答案可能有助于解决我的其他问题:



这可能是额外的信息,我需要...将发布一个解决方案,如果我得到它的工作。 Thx。

解决方案

@KenWhite,你的建议给了我需要的,谢谢!



以下是解决我的问题的代码:

 包括winuser.h

...

void SafeSetFocus(TWinControl * Control)
{
HWND hWnd = Control-> ParentWindow;
bool parentIsVisible = IsWindowVisible(hWnd);

if(Control-> Enabled&& Control-> Visible&& amp; parentIsVisible)
{
Control-> SetFocus
}
}


I have a TWinControl and am trying to determine if the parent window is visible.

I see TWinControl has a property of ParentWindow. The return type of ParentWindow is void *. So I'm curious if I must cast to a particular type, which would then give me access to check if the window is visible or not.

Does anyone know the type I need to cast to, or another way to accomplish this?


Additional Troubleshooting Notes, Part 1:

I tried to get the ParentWindows class by:

String parentWindowClassName = ((TObject *)(Control->ParentWindow))->ClassName();

But this gave an access violation. I also tried casting to TForm, which also gave an access violation, which makes me believe the parent window may be controlled by windows. If so, does anyone know of any trick to check if it is visible? E.g. Any COM tricks or anything?

Additional Troubleshooting Notes, Part 2:

The answer to this question may help solve my other question: C++ Builder 2009 - Cannot focus a disabled or invisible window

However the other question may be solved without this approach, which is why I posted a different question.

Additional Troubleshooting Notes, Part 3:

Thanks for the extra info Ken. I got my info off code assist:

However I see your HWND return type from: http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/Controls_TWinControl_ParentWindow.html

That might be the extra info I need... will post a solution if I get it working. Thx.

解决方案

@KenWhite, your suggestions gave me what I needed, thanks!

The following is the code that solved my problem:

#include "winuser.h"

...

void SafeSetFocus(TWinControl *Control)
{
    HWND hWnd = Control->ParentWindow;
    bool parentIsVisible = IsWindowVisible(hWnd);

    if(Control->Enabled && Control->Visible && parentIsVisible)
    {
        Control->SetFocus();
    }
}

这篇关于C ++ Builder 2009 - 如何确定控件的窗口是否可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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