|
- Can you help?
- Regards,
Maer
|
|
|
|
|
if you are asking about #ifndef then the main difference is the #if form permits complex expressions such as :
#if( !define(THIS) && !define(THAT) && !(THE_OTHER_THING) )
I don't believe that #ifndef supports this type of expression. It may but I have never seen any.
|
|
|
|
|
- Thanks pal!
- I think the statement "#if( !define(THIS) && !define(THAT) && !(THE_OTHER_THING) )" should be
#if( !define(THIS) && !define(THAT) && !define(THE_OTHER_THING) )
- Am I right?
- Regards,
BigMouth
|
|
|
|
|
Yep, I missed that last define.
I was just testing you.
Actually, they should all say defined but your compiler would tell you that soon enough.
Good Luck.
|
|
|
|
|
- Thanks pal!
- I think you are smart and warm-hearted.
- Regards,
BigMouth
|
|
|
|
|
- Can you help?
- Regards,
Maer
|
|
|
|
|
_DEBUG is the standard definition that VC++ uses when performing a debug build. I don't know about DEBUG. I couldn't find it in the docs.
|
|
|
|
|
|
- Can you help?
- Regards,
Maer
|
|
|
|
|
It is used to prevent a header file from being included more than one time.
|
|
|
|
|
|
- I still have a question. I think we can use the statement "#if !defined ... #define" to do the same task. I think the use of "#pragma once" is a redundance. Am I right? (For example, in MainFrm.h of a MDI app)
- Can you help?
- Regards,
BigMouth
|
|
|
|
|
In most cases that I have seen it used it is redundant.
There are two ways to go about the issue of multiple include prevention. You can benignly allow it and protect against it in the header (like the AppWiz does) or you can require the includers to insure that they haven't seen it yet which is what I usually do.
I use this kind of thing :
#ifndef _THISHEADER_H
#define _THISHEADER_H
#else
#error repeated include of this file
#endif
Then in the source files I do this :
#ifndef _THISHEADER_H
#include "ThisHeader.h"
#endif
This insures that the header is included once and only once.
FWIW, I learned this from checking out the SDK headers. I added the error check so that I would find the cases where I missed the ifndefs.
|
|
|
|
|
- Thanks pal!
- I still have a question. I think the statement "#error repeated include of this file" should be #error _THISHEADER_H has already defined". I think in the header file we can only see whether the variable "_THISHEADER_H" has been defined. We can not see whether the header file has been include twice. Am I right?
- Can you help me out?
- Regards,
BigMouth
|
|
|
|
|
The reason I did it that way is that when the error message is displayed it tells you the line number and file name where it occurred.
Of course, you can make the error message say whatever you like.
|
|
|
|
|
- Thanks pal!
- I stll have a question. What means "allow it and protect against it in the header (like the AppWiz does)" in your reply? Can you give me an example?
- Regards,
BigMouth
|
|
|
|
|
What the AppWiz does is make headers like this :
#ifndef AFX_THISHEADER_H_a_whole_bunch_of_random_numbers_here
#define AFX_THISHEADER_H_a_whole_bunch_of_random_numbers_here
// contents of header go here
#endif // AFX_THISHEADER_H_a_whole_bunch_of_random_numbers_here
This style will let you repeatedly include the file because it is protected but it will not warn you about it. I like to know about and prevent against repeated inclusion.
As I said previously, this is mostly a personal preference but M$ does it also in several of the windoze headers and, in my opinion, they should because they have lots of 100K+ headers.
Many people take a bit more relaxed approach than me (including M$) and only do the #ifndef thing inside other headers when they are being nested (includes inside headers.) That's fine but I am just a bit more obssessive about it.
|
|
|
|
|
I have an intersting problem to solve that has been causing much caffeine intake over the past few hours...
Say I have a CWnd derivied class, which we'll call CBaseWnd. Now, CBaseWnd can have multiple children, which in turn can have multiple children, though only one of the first level children can be visible at a time, with any number of second...third... level children optionaly visible as you work down all branches of the family tree.
CBaseWnd has an attribute and appropriate accessor that stores whether or not the base window (itself) or any of the child windows has the focus.
Now to my question: How can I determine from within CBaseWnd if it or any of it's children, grandchildren, great grandchildren, etc, currently has the focus? I've tried all the [to me] obvious approaches, but they all cause problems when the focus is given to one of the windows in the tree from one outside it (e.g. the desktop). Why is beyond me.
There must be a way to walk through a window's children and then repeat the process for each child, etc, surely?
Any help would be greatly appreciated as I have now run out of coffee and will have to start taking coke intravenously...
P.S. Sorry about the title, but I am more used to posting the the lounge!
________________
David Wulff
http://www.davidwulff.co.uk
"I loathe people who keep dogs. They are cowards who haven't got the guts to bite people themselves" - August Strindberg
|
|
|
|
|
Hi David,
This reminds me of when I learned to recursivly traverse tree data structures
I have not tried this, but could you not use EnumChildWindows().
When the child is accessed, check if it has the focus,
If it does, send it's HWND to it's parent (say "It's me"),
If it does not, Enumerate it's own children.
If it does not get an "It's me" message from one child, go to the next,
If it does get the "It's me" message, forward it to it's immediate parent.
Do this for all levels of children until all windows are exhausted (no focus) or the "It's me" message is recieved by the top window.
Here is basic view of what I mean. (The numbers are the order windows are checked)
1Parent
+-------------------+--------------------+
2Wnd 7Wnd 10Wnd
+-----+-----+----+ +-----+ +------+------+
3Wnd 4Wnd 5Wnd 6Wnd 8Wnd 9Wnd 11Wnd Wnd Wnd
\
Focus
The focus is held by the 11th window checked, so the rest of the windows are not checked.
HTH
---
It may be that your sole purpose in life is simply to serve as a warning to others.
|
|
|
|
|
|
The problem with that is that it doesn't work for any more than the windows children (i.e. no grandchildren, etc). This is because I can not parse the child windows looking for one with focus, but rather determine the window with focus from GetFocus().
I cannot do...
if (IsChild(GetFocus()))
{
bFocus = true;
}
...but rather would need to do...
if (GetFocus() == CBaseWnd)
{
bFocus = true;
}
else if (GetFocus()->GetParent() == CBaseWnd)
{
bFocus = true;
}
.
.
.
else
{
bFocus = false;
}
... (working back down the tree from the child).
The problem is that obviously the window with the current focus may not be a child of CBaseWnd, and so navigating up it's family tree will either do no good, or crash because I reach the top too soon.
________________
David Wulff
http://www.davidwulff.co.uk
"I loathe people who keep dogs. They are cowards who haven't got the guts to bite people themselves" - August Strindberg
|
|
|
|
|
David Wulff wrote:
if (GetFocus() == CBaseWnd)
Always compare hWnd's, not CWnd pointers.
If (GetFocus()->GetSafeHwnd() == pBaseWnd->GetSafeHwnd())
cheers,
Chris Maunder
|
|
|
|
|
Thanks for that bit of wisdom!
Luckily I can't remember ever having done this before, so you nipped it in the bud!
________________
David Wulff
http://www.davidwulff.co.uk
"I loathe people who keep dogs. They are cowards who haven't got the guts to bite people themselves" - August Strindberg
|
|
|
|
|
David Wulff wrote:
The problem with that is that it doesn't work for any more than the windows children (i.e. no grandchildren, etc).
Huh... I was going by MSDN, which says:Indicates whether the window specified by pWnd is a child window or other direct descendant of CWnd. A child window is the direct descendant of CWnd if the CWnd object is in the chain of parent windows that leads from the original pop-up window to the child window.
[edit]
Oh wait, I think I mixed up owner windows with child windows. NM
--Mike--
http://home.inreach.com/mdunn/
Help! Help! I'm being repressed!!
your with and
Sonork - 100.10414 AcidHelm
|
|
|
|
|
In my head that was approaching it from the wrong angle - of course, my head isn't always right.
I read the documentation as meaning that I needed to supply the child window, but thinking about what you wrote again, of course it should work because GetFocus() would be a child (if not another window).
I believe the phrase goes something like "D'oh"...
________________
David Wulff
http://www.davidwulff.co.uk
"I loathe people who keep dogs. They are cowards who haven't got the guts to bite people themselves" - August Strindberg
|
|
|
|