Click here to Skip to main content
15,888,401 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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

GeneralRe: How can I hide/Show Group Box Pin
sabdalla8014-Aug-08 6:25
sabdalla8014-Aug-08 6:25 
QuestionHandle Event from a Class Pin
Sianspheric13-Aug-08 10:05
Sianspheric13-Aug-08 10:05 
QuestionCreating a global mouse hook Pin
JRuthe13-Aug-08 8:34
JRuthe13-Aug-08 8:34 
QuestionThread: Suspending best practice Pin
StevenS_Dev13-Aug-08 7:41
StevenS_Dev13-Aug-08 7:41 
AnswerRe: Thread: Suspending best practice Pin
Cedric Moonen13-Aug-08 7:52
Cedric Moonen13-Aug-08 7:52 
AnswerRe: Thread: Suspending best practice Pin
Randor 13-Aug-08 7:53
professional Randor 13-Aug-08 7:53 
AnswerRe: Thread: Suspending best practice Pin
StevenS_Dev13-Aug-08 8:27
StevenS_Dev13-Aug-08 8:27 
AnswerRe: Thread: Suspending best practice Pin
Stephen Hewitt13-Aug-08 16:39
Stephen Hewitt13-Aug-08 16:39 
QuestionIndexing Service Administration API Pin
kasi1413-Aug-08 6:12
kasi1413-Aug-08 6:12 
QuestionWindows XP and Modeless Dialogs Pin
Snaggles13-Aug-08 3:58
Snaggles13-Aug-08 3:58 
AnswerRe: Windows XP and Modeless Dialogs Pin
Randor 13-Aug-08 4:27
professional Randor 13-Aug-08 4:27 
AnswerRe: Windows XP and Modeless Dialogs Pin
vikas amin13-Aug-08 5:04
vikas amin13-Aug-08 5:04 
QuestionApplication and webpage/webservice interaction Pin
Monty213-Aug-08 3:56
Monty213-Aug-08 3:56 
AnswerRe: Application and webpage/webservice interaction Pin
vikas amin13-Aug-08 4:20
vikas amin13-Aug-08 4:20 
QuestionProblems when configuring Visual Studio ... Pin
SNArruda13-Aug-08 3:21
SNArruda13-Aug-08 3:21 
AnswerRe: Problems when configuring Visual Studio ... Pin
Cedric Moonen13-Aug-08 3:25
Cedric Moonen13-Aug-08 3:25 
AnswerRe: Problems when configuring Visual Studio ... Pin
David Crow13-Aug-08 3:27
David Crow13-Aug-08 3:27 

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.