Solved

Checking visibility of dialog?? Not so simple?

Posted on 1998-07-29
5
157 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:Haho
5 Comments
 
LVL 3

Expert Comment

by:danny_pav
ID: 1319890
Regardless of MFC, use the IsWindowVisible with the HWND.  HWND's are unique accross the system, not just to a process.
0
 
LVL 2

Expert Comment

by:duneram
ID: 1319891
or if you have the HWND you do a


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

0
 
LVL 1

Accepted Solution

by:
Arkadiy earned 70 total points
ID: 1319892
You need to declare a static member in your dialog class. Something like

class CMyDialog : public CDialog
{
public:
    static BOOL IsDialogVisible(){return m_bNowVisible;};
private:
    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
}
0
 
LVL 1

Author Comment

by:Haho
ID: 1319893
Thanks , sorry for the late reply... I was busy with my project...

0
 
LVL 2

Expert Comment

by:duneram
ID: 1319894
There are cases where this solution won't work, but good luck anyways.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
not able to insert into temp table 68 157
Define unique primary key 9 89
Looking for a specific application/software 2 104
matchUp  challenge 6 53
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now