Solved

Checking visibility of dialog?? Not so simple?

Posted on 1998-07-29
5
156 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ORA-01403: no data found 43 83
Tab names are off by one 5 49
ffmpeg - "rtsp://...... Operation not permitted" 4 69
fix34  challenge 9 98
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

9 Experts available now in Live!

Get 1:1 Help Now