|
toxcct wrote: that will hide the Group Box control only, not its content...
Which is what the OP requested.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
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"></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">
afx_msg <font color="blue">void</font> OnShowWindow(BOOL bShow, UINT nStatus); <font color="green">
DECLARE_MESSAGE_MAP()
<font color="blue">public</font>:
CGroupBoxEx();
<font color="blue">virtual</font> ~CGroupBoxEx();
BOOL InsertNewChild(CWnd* pwndChild); <font color="green">
BOOL RemoveChild(CWnd* pwndChild); <font color="green">
};
<font color="green"></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"></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"></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
|
|
|
|
|
Thanks for the replys... I had it coded the same way you guys suggested, but it was crashing originally, but when I recompiled, it seems to work fine.
Thanks again
|
|
|
|
|
Hi !
I have to create a small prototype for a future application that my company wish to develop. A couple of years ago i've learn C++ but for the last 5 years or so i've been programming only in .net (VB, C#) and Java so my knowledge of C++ seems a bit far away So this is why i need your help.
Right now one of the function of our prototype is to "create" a bridge between c++, .net and Java application. One of our supplier send us a Com Dll (C# code) which allow us to interact with their software. Using their myClass.tlb file i've imported the file in the C++ code. This file contain some class.
In one of their class (clCommunication) there is a method call "Get_Message()" and also an Event call "NewMessage". When the Get_Message method is called it trigger the NewMessage Event.
So what i what to know is how to handle the NewMessage event in the c++ code. When the NewMessage will be triggered i want to call a c++ function. I've already done this in .net and in Java but i cannot find the solution in C++.In VB i've done something like:
Function myFunction() Handle aCom.NewMessage. ( When NewMessage will be invoke myFunction will be called)
In C# i have done the same thing using the += operator but in C++ i cannot find out how do to it.
I don't know if this could help but i've noticed that when i create an instance of the class clcommunication there is 3 properties available "add_NewMessage","remove_NewMessage","raw_NewMessage". I guess that i should use them to make what i need but i have no idea where to start.
So let's says that i have a function called "Dothis()" in my c++ code. What did i need to do to automatically triggered this function when a instance of clCommunication will triggered "NewMessage".
Thanks !!!
|
|
|
|
|
I'm using Visual C++ 2008 Professional with a CLR project of Windows Form Application. This program is a stopwatch and I'd like to be able to set a global mouse hook so that when the user clicks anywhere on the screen after pressing a specific button, it will start the timer. How is this possible? I'm not sure what code would be needed to help me, but I will post anything that is needed.
Thanks for your time,
Jordan
|
|
|
|
|
I am just curious as to the best practice for suspending a thread. We have a thread that every once in awhile is required to do something. I am currently using SuspendThread on the CWinThread object. When the thread needs to do work, I Resume the thread. That seems to work well and does not eat up any CPU. But I am just wondering if a better way is to WaitForSingleObject and use an Event to resume the thread.
Using SuspendThread works and is certainly easy to implement, but am just curious which way may provide a better design.
Thanks for the insight.
Note: We were originally ending the thread when it was done with its job, but ran into some other problems. This thread calls into something else which uses OpenMP for multi-threading. When our C++ client thread ended, the OMP threads did not seem to get removed so we kept accumulating OMP threads until we eventually get an error saying too many OMP threads.
|
|
|
|
|
StevenS_Dev wrote: But I am just wondering if a better way is to WaitForSingleObject and use an Event to resume the thread.
Yes, that's probably a much better approach because you are in full control about what is happening. When you call SuspendThread, you have absolutely no idea where the thread will be stopped. Perhaps right in the middle of something important. With the other approach, you fully complete the task, then swith in a 'wait state' (waiting for the event to be signaled).
|
|
|
|
|
|
Thanks for the answers. That is what I figured, but wanted real data to support it.
|
|
|
|
|
Don't use SuspendThread[^]. You're been lucky so far but I wouldn't count on that continuing. See this article on why you should never suspend a thread[^]. The documentation for SuspendThread[^] also points out the dangers of using it as you are:
This function is primarily designed for use by debuggers. It is not intended to be used for thread synchronization. Calling SuspendThread on a thread that owns a synchronization object, such as a mutex or critical section, can lead to a deadlock if the calling thread tries to obtain a synchronization object owned by a suspended thread. To avoid this situation, a thread within an application that is not a debugger should signal the other thread to suspend itself. The target thread must be designed to watch for this signal and respond appropriately.
|
|
|
|
|
Hi,
I am working on a desktop search engine.
As a part of this project i need to create catalog in indexing service. To cteate this i need to have the Indexing Service Administration API.
Where can i get them. Should i need to buy them?
or I can get them for free? if so where can i get them?
I had the dll "ciodm.dll" on my machine but with out the .tld i can't use it in my project.
Some one, please help me in finding out what i can do/ where i can get the API's so that i can complete my project.
Thanks
krish99
|
|
|
|
|
We have an application written in VC 6, that works well on Windows 2000, but when running on XP the modeless status diaglog that displays the progrees of the operation doesn't seem to refresh or return to top after the operator returns from a screen saver.
The status bars continue to updte as far as we can tell, but the application appears to lose focus of the modeless dialog until the operation is complete. When the operation finishes, THEN the status screen displays with all status bars compete at 100%, and a the Afxmessege Box appears.
How can I get the application to return focus to the status screen when returning from the screen saver?
Anyone have any suggestions?
Snaggles
|
|
|
|
|
|
Try to set the modeless as top window with SetForegroundWindow()
you can also WM_NEXTDLGCTL message it is sent to a dialog box procedure to set the keyboard focus to a different control in the dialog box.
Vikas Amin
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
Hi,
I have an application(MFC), it needs to send some data (XML 20/25kb) to some online entity(some online script or service) and that online entity will parse the XML query some Database and return results to the MFC application.
i just need to know what is the idea scenario under these circumstances should i use some script or service or query the database directly
please suggest
Thanks
C++ where friends have access to your private members !
|
|
|
|
|
|
Hello there, some one help me ?
How can i configure my Visual Studio 8 to solve the problem indicated by the above message ?
C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlbase.h(4575) : error C3861: '_beginthreadex': identifier not found
tanks for help ...
Ps: Sorry by my english, i´m Brasilian
|
|
|
|
|
You don't need to configure anything, just include the appropriate header file: procces.h (as described in the documentation[^] ).
|
|
|
|
|
See here. You are not including the process.h file.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
|
I am using a thread for which I am sending the below mentioned structure as parameter. pls advice
error C2440: '=' : cannot convert from 'const class abcDomain::Scope *const ' to 'class abcDomain::Scope *'
.h
declaration
virtual bool searchABCByAttributes()const;
typedef struct THREADSTRUCT_SCOPE
{
Scope *_this;
}THREADSTRUCT_SCOPE;
.CPP
bool Scope::searchABCByAttributes()
{
THREADSTRUCT_SCOPE *_param= new THREADSTRUCT_SCOPE;
_param->_this = this;
....
|
|
|
|
|
Your function is declared as constant, so it means that the this pointer is const too. And you are trying to assign it to a non-const variable, which is illegal. So, remove the constness of the function and it should be fine.
|
|
|
|
|
Missed a const in the definition of Scope::searchABCByAttributes() ?
.h
declaration
virtual bool searchABCByAttributes()const;
.CPP
bool Scope::searchABCByAttributes()
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Sorry it is my mistake, pls find below the correct one. I want keep the const, is there any work around...
.hdeclaration
virtual bool searchABCByAttributes()const;
.CPP
bool Scope::searchABCByAttributes()const
|
|
|
|
|
There's a solution but it is really ugly: you can remove the constness of the this pointer by using a const_cast. But it doesn't make any sense because you declared your function as const. Why would you do that if you remove the constness inside it ?
Another point: why are you putting the this pointer inside a structure if you only pass that pointer ? Why don't you pass it directly to your thread function ?
|
|
|
|