C++ Builder 2009 - How to Determine if Control's Window is Visible

我与影子孤独终老i 提交于 2019-12-11 18:05:38

问题


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.


回答1:


@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();
    }
}


来源:https://stackoverflow.com/questions/15444503/c-builder-2009-how-to-determine-if-controls-window-is-visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!