Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Checking visibility of dialog?? Not so simple?

Posted on 1998-07-29
5
Medium Priority
?
163 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 210 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

Technology Partners: 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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

885 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