• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

Checking visibility of dialog?? Not so simple?

Hi guys, ... :) my problem is how to check if a dialog is visible( modal or non-modal ) . Easy, right?
Use IsWindowVisible...!! BUT I want to check it from another class and if possible , not by passing in
 pointers to the dialog object. Meaning, I want to use MFC function/s to get the object instance of the
dialog class with the id IDD_XXXXX and check whether that particulat object is visible or not, and/or call
the object's member functions. There should only be one object instance of that class at any one time...
simply, there will always be only one dialog of that particular class...

Thanks.... have a nice day!!

David Chong
1 Solution
Regardless of MFC, use the IsWindowVisible with the HWND.  HWND's are unique accross the system, not just to a process.
or if you have the HWND you do a

long x = GetWindowLong(hwnd);
if (x & WS_VISIBLE)
   /* its visible */
 /* its not visible */

You need to declare a static member in your dialog class. Something like

class CMyDialog : public CDialog
    static BOOL IsDialogVisible(){return m_bNowVisible;};
    static BOOL m_bNowVisible;

    afx_msg void OnShowWindow(BOOL bShow, UINT)

In the implementation:

BOOL CMyDialog::m_bNowVisible = FALSE;

void CMyDialog::OnShowWindow(BOOL bShow, UINT)
    ASSERT(m_bNowVisible != bShow); //this will fire when we have
       //more than 1 dialog shown/hidden

    m_bNowVisible = bShow;

This will set m_bNowVisible when the dialog is shown and reset it when it is hidden. You test tes the value the following way:

if (CMyDialog::IsDialogVisible())
    //whatever you need to do
HahoAuthor Commented:
Thanks , sorry for the late reply... I was busy with my project...

There are cases where this solution won't work, but good luck anyways.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now