Solved

Checking visibility of dialog?? Not so simple?

Posted on 1998-07-29
5
160 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Separate files macro - Errors on larger data set 18 77
Process filename extension 3 218
fizzArray2 challenge 1 112
no14 challenge 14 78
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

752 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