Click here to Skip to main content
15,899,474 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Disable bitmap button Pin
Jijo.Raj13-Aug-08 22:30
Jijo.Raj13-Aug-08 22:30 
AnswerRe: Disable bitmap button Pin
Hamid_RT13-Aug-08 23:50
Hamid_RT13-Aug-08 23:50 
QuestionHow can Check .chm file is open or not? Pin
Le@rner13-Aug-08 19:14
Le@rner13-Aug-08 19:14 
AnswerRe: How can Check .chm file is open or not? Pin
sashoalm13-Aug-08 20:24
sashoalm13-Aug-08 20:24 
GeneralRe: How can Check .chm file is open or not? Pin
Le@rner13-Aug-08 20:33
Le@rner13-Aug-08 20:33 
GeneralRe: How can Check .chm file is open or not? Pin
sashoalm13-Aug-08 20:45
sashoalm13-Aug-08 20:45 
GeneralRe: How can Check .chm file is open or not? Pin
Le@rner13-Aug-08 20:54
Le@rner13-Aug-08 20:54 
QuestionUsing Notes C++ API to access Lotus Notes DBs on Visual C++/MFC Pin
afterruins13-Aug-08 19:13
afterruins13-Aug-08 19:13 
AnswerRe: Using Notes C++ API to access Lotus Notes DBs on Visual C++/MFC [modified] Pin
Jijo.Raj13-Aug-08 22:34
Jijo.Raj13-Aug-08 22:34 
QuestionInternet Explorer Socket Programming? [modified] Pin
Ehsan Baghaki13-Aug-08 19:11
Ehsan Baghaki13-Aug-08 19:11 
QuestionHow cab Bold the Caption of Property Pages? Pin
Le@rner13-Aug-08 18:28
Le@rner13-Aug-08 18:28 
AnswerRe: How cab Bold the Caption of Property Pages? Pin
Paresh Chitte13-Aug-08 21:20
Paresh Chitte13-Aug-08 21:20 
GeneralRe: How cab Bold the Caption of Property Pages? Pin
Le@rner13-Aug-08 21:45
Le@rner13-Aug-08 21:45 
GeneralRe: How cab Bold the Caption of Property Pages? Pin
Mark Salsbery14-Aug-08 4:58
Mark Salsbery14-Aug-08 4:58 
QuestionFTPConnection Stalls - Won't Restart or Finish Pin
Stan Bartsch13-Aug-08 15:35
Stan Bartsch13-Aug-08 15:35 
QuestionCan I use _beginthread in a MFC OCX project? Pin
fantasy121513-Aug-08 14:44
fantasy121513-Aug-08 14:44 
AnswerRe: Can I use _beginthread in a MFC OCX project? Pin
Stephen Hewitt13-Aug-08 16:36
Stephen Hewitt13-Aug-08 16:36 
QuestionRe: Can I use _beginthread in a MFC OCX project? Pin
fantasy121513-Aug-08 16:56
fantasy121513-Aug-08 16:56 
AnswerRe: Can I use _beginthread in a MFC OCX project? Pin
Mark Salsbery13-Aug-08 17:02
Mark Salsbery13-Aug-08 17:02 
QuestionHow can I hide/Show Group Box Pin
sabdalla8013-Aug-08 11:02
sabdalla8013-Aug-08 11:02 
AnswerRe: How can I hide/Show Group Box Pin
Joe Woodbury13-Aug-08 11:53
professionalJoe Woodbury13-Aug-08 11:53 
GeneralRe: How can I hide/Show Group Box Pin
Le@rner13-Aug-08 18:30
Le@rner13-Aug-08 18:30 
GeneralRe: How can I hide/Show Group Box Pin
toxcct13-Aug-08 22:28
toxcct13-Aug-08 22:28 
GeneralRe: How can I hide/Show Group Box Pin
David Crow14-Aug-08 3:58
David Crow14-Aug-08 3:58 
AnswerRe: How can I hide/Show Group Box [modified] Pin
toxcct13-Aug-08 22:34
toxcct13-Aug-08 22:34 
there are several ways for that.

the most robust one is an overload of the GroupBox class which handles the hide/show event and which iterate through every controls of the window and tests if it is within the group box area.
this way, you have nothing more to do than just use an instance of such a class in your window, and call ShowWindow(SW_HIDE) on it for instance.

for performance reasons, I found myself to write my own Group box, which doesn't performs such tests. at the window construction, my version of the GroupBox is waiting for the HWND (or the CWnd) of the controls that are supposed to be within in.
that way, it iterated over that reduced array to send them the hide/show message...

here is my code :
<font color="green">/* GroupBoxEx.h
 *
 * Copyright (c) 2006 by toxcct. All rights reserved.
 * Consult your license regarding permissions and restrictions.
 */</font>
 
<font color="blue">#pragma once
 
#include</font> <MAP>
 
<font color="blue">class</font> CGroupBoxEx : <font color="blue">public</font> CStatic {
    DECLARE_DYNAMIC(CGroupBoxEx)
 
<font color="blue">protected</font>:
    std::map<UINT, BOOL> m_mapChildrenControls;    <font color="green">//Maps a CWnd ID to its original state</font>
    afx_msg <font color="blue">void</font> OnShowWindow(BOOL bShow, UINT nStatus);    <font color="green">//WM_SHOWWINDOW message handler.</font>
    DECLARE_MESSAGE_MAP()
 
<font color="blue">public</font>:
    CGroupBoxEx();
    <font color="blue">virtual</font> ~CGroupBoxEx();
    BOOL InsertNewChild(CWnd* pwndChild);    <font color="green">//Inserts a new CWnd child to the GroupBox</font>
    BOOL RemoveChild(CWnd* pwndChild);       <font color="green">//Removes a Cwnd child of the GroupBox</font>
};

<font color="green">/* GroupBoxEx.cpp
 *
 * Copyright (c) 2006 by toxcct. All rights reserved.
 * Consult your license regarding permissions and restrictions.
 */</font>
 
<font color="blue">#include</font> "stdafx.h"
<font color="blue">#include</font> "GroupBoxEx.h"
 
IMPLEMENT_DYNAMIC(CGroupBoxEx, CStatic)
 
 
CGroupBoxEx::CGroupBoxEx() : CStatic() {
    m_mapChildrenControls.clear();
}
 
CGroupBoxEx::~CGroupBoxEx() {
    m_mapChildrenControls.clear();
}
 
 
BEGIN_MESSAGE_MAP(CGroupBoxEx, CStatic)
    ON_WM_SHOWWINDOW()
END_MESSAGE_MAP()
 
 
<font color="green">/**
 * Inserts a new MFC control into the GroupBox.
 *  When a control is a child of a CGroupBoxEx object, it behaves with the grouping
 *  strategy of the GroupBox.
 */</font>
BOOL CGroupBoxEx::InsertNewChild(CWnd* pwndChild) {
    ASSERT(pwndChild != NULL);
    <font color="blue">if</font> (m_mapChildrenControls.find(pwndChild->GetDlgCtrlID()) != m_mapChildrenControls.end()) {
        <font color="blue">return</font> FALSE;
    }
    BOOL bVisible = pwndChild->IsWindowVisible();
    m_mapChildrenControls[pwndChild->GetDlgCtrlID()] = bVisible
    <font color="blue">if</font> (!this->IsWindowVisible()) {
        pwndChild->ShowWindow(SW_HIDE);
    }
    <font color="blue">return</font> TRUE;
}
 
<font color="green">/**
 * Removes a MFC control from the GroupBox.
 */</font>
BOOL CGroupBoxEx::RemoveChild(CWnd* pwndChild) {
    ASSERT(pwndChild != NULL);
    std::map<UINT, BOOL>::iterator iterChild = m_mapChildrenControls.find(pwndChild->GetDlgCtrlID());
    <font color="blue">if</font> (iterChild == m_mapChildrenControls.end()) {
        <font color="blue">return</font> FALSE;
    }
    <font color="blue">if</font> ((!this->IsWindowVisible()) && (iterChild->second)) {
        pwndChild->ShowWindow(SW_NORMAL);
    }
    m_mapChildrenControls.erase(iterChild);
    <font color="blue">return</font> TRUE;
}
 
/<font color="green">**
 * Event handler of th WM_SHOWWINDOW Windows Message.<BR>
 * When the GroupBox is hidden, any child control previously added is hidden.<BR>
 * When the GroupBox is unhidden, the children controls are restored to the original
 *  state they were in before the group were hidden.
 */</font>
<font color="blue">void</font> CGroupBoxEx::OnShowWindow(BOOL bShow, UINT nStatus) {
    CStatic::OnShowWindow(bShow, nStatus);

    std::map<UINT, BOOL>::iterator iterControls;
    CWnd* pwnd = NULL;
    <font color="blue">if</font> (!bEnable) {
        <font color="blue">for</font> (iterControls = m_mapChildrenControls.begin();
             iterControls != m_mapChildrenControls.end();
             iterControls++) {
            pwnd = this->GetParent()->GetDlgItem(iterControls->first);
            ASSERT(pwnd != NULL);
            iterControls->second = pwnd->IsWindowVisible();
            pwnd->ShowWindow(SW_HIDE);
        }
    }
    <font color="blue">else</font> {
        <font color="blue">for</font> (iterControls = m_mapChildrenControls.begin();
             iterControls != m_mapChildrenControls.end();
             iterControls++) {
            <font color="blue">if</font> (iterControls->second.bEnabled) {
                pwnd = this->GetParent()->GetDlgItem(iterControls->first);
                ASSERT(pwnd != NULL);
                pwnd->ShowWindow(SW_NORMAL);
            }
        }
    }
}



modified on Thursday, August 14, 2008 4:53 AM

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.