|
These look like reinclusion guards. It stops the same .H file from being processed multiple times in the same compilation unit as this can cause problems. i.e.
------------------------------------
// File "a.h"
//
class CMyClass
{
public:
CMyClass() {}
};
// File "b.h"
//
#include "a.h"
// File "Main.cpp"
//
#include "a.h"
#include "b.h"
------------------------------------
This will casue problems as the class "CMyClass" is defined twice in the compilation unit "Main.cpp": once via "a.h" and once via "b.h" which includes "a.h". Reinclusion guards stop this kind of thing.
Steve
|
|
|
|
|
Ok. In that case when we use
#ifndef SOMEFILE_H<br />
#define SOMEFILE_H<br />
<br />
<br />
#endif
what is SOMEFILE_H ? is it another SIGNATURE to indicated something exists or not? Is it visible to the compiler or only to the preprocessor?
Abhishek
|
|
|
|
|
It's just something you make up that is unique for each header file in your project. You could also use the symbol to detect if a header has been included or not.
Steve
|
|
|
|
|
AbhishekBK wrote: what is SOMEFILE_H ?
It's simply a word that you make up. You could do the same with:
#ifndef AbhishekBK
#define AbhishekBK
...
#endif
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
the preprocessor directives are compiled first before the actual source code of your program. For example the #include statement is a preprocessor command that tells the compiler to include first the file specified before actually compiling the program you made.
for example #include <stdio.h> the compiler will include all the functions and definitions written on the stdio.h file before actually compiling your program.
for short preprocessor derectives are compiled before your actual codes...
-----------------------Life is simple, you just complicate things---------------------
|
|
|
|
|
moodsey211 wrote: For example the #include statement is a preprocessor command that tells the compiler to include first the file...
Actually, the compiler never sees the preprocessor directives. The preprocessor is what does the inclusions. The compiler simply sees the net result.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
#ifndef tells the preprocessor to test if the macro is not defined .
if if is not, then we instructo the preprocessor to #define s it and executes the body of the #if /#endif bloc.
if it's already defined, it is because the preprocessor already entered this file at least once for that compilation unit, and then, does nothing.
the main problem such conditionnal compilation resolves is the multiple uncludes of the same code, which will result in a "symbol redefinition" compiler error.
consider the following code :
Parent.h :
<font color=blue>class</font> CParent {
<font color=green>
};
Child.h :
<font color=blue>#include</font> <font color=gray>"Parent.h"</font> <font color=green>
<font color=blue>class</font> CChild : <font color=blue>public</font> CParent {
<font color=green>
};
main .cpp :
<font color=blue>#include</font> <font color=gray>"Parent.h"</font>
<font color=blue>#include</font> <font color=gray>"Child.h"</font>
<font color=blue>void main</font> (<font color=blue>void</font>) {
}
by doing this, what does the #include s actually do ? they copy the content of the file they reference in the compilation unit. then, the main.cpp should become this when entering the compiler :
<font color=green>
<font color=blue>class</font> CParent {
<font color=green>
};
<font color=green>
<font color=green>
<font color=blue>class</font> CParent {
<font color=green>
};
<font color=blue>class</font> CChild : <font color=blue>public</font> CParent {
<font color=green>
};
<font color=blue>void main</font> (<font color=blue>void</font>) {
}
by doing this, the compiler will complain because the class CParent is defined twice in the same compilation unit (main.cpp).
so, we use conditional compilation instructions to avoid this. when the preprocessor will enter the file Parent.h the first time, it will define its unique macro (like __PARENT_H_INCLUDED__ ), and when including the file the second time, as the macro already exists, the file content is not included twice...
do you get me then ?
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-- modified at 5:43 Friday 23rd June, 2006
|
|
|
|
|
clear and out!
Thanks a lot.
Abhishek
|
|
|
|
|
toxcct wrote: #ifndef tells the preprocessor to test if the macro is not defined.
if if is not, then the preprocessor #defines it and executes the body of the #if/#endif bloc.
This isn’t the case; if the macro isn’t defined the body is executed but the macro isn’t #define d automatically. In re-inclusion guards the first statement in the macro body is usually a #define . i.e.
#ifndef _MYFILE_H_
#define _MYFILE_H_
I'm sure you already know this but I point it out because the phrasing is a bit misleading.
Steve
|
|
|
|
|
Stephen Hewitt wrote: This isn’t the case, if the macro isn’t defined the body is executed but the macro isn’t #defined
i wasn't meaning that the #ifndef was defining the macro ; you misunderstood me.
this is the only purpose of the #define directive.
BTW, i modified a bit the paragraph, it was a bit confusing...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
hi
please help me
tell me
how i can change the color of a button control and text on it which are differ from dialog box. A button is on a dialog box
Ashish Dogra
MCA
Noida
|
|
|
|
|
I think you can change the button color in CWnd::OnCtlColor (WM_CTLCOLOR) of the parent window and change the text color by SetTextColor().
|
|
|
|
|
thanks form reply
but sir i use this one but it does not change the color
HBRUSH CButtoncolorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_BTN)
{
hbr=CreateSolidBrush(RGB(0,100,0));
pDC->SetTextColor(RGB(0,0,255));
pDC->SetBkColor(RGB(0,100,0));
}
return hbr;
}
Ashish Dogra
MCA
Noida
|
|
|
|
|
Did you set the BS_OWNERDRAW property of the button's to TRUE.
I guess not.Do it and then you will see the button color change.
To change the property of the button to owner draw right click on the button . Open the property window and just set the OWNER Draw property to true.
IS it OK?
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
THANKS
Ashish Dogra
MCA
Noida
|
|
|
|
|
hi again
i am sorry to disturb you again
but i make an application in which many dialog boxes are there
now when i make ownerdraw property true the application does not run and if i make ownerdraw property false the application runs
i dont understand the problem
so plz tell me what is the problem
thanks
Ashish Dogra
MCA
Noida
|
|
|
|
|
whats error you get one error when you set Ownerdraw,right?
whitesky
|
|
|
|
|
application does not run it simply show an message that application has encountreda problem and need to close
Ashish Dogra
MCA
Noida
|
|
|
|
|
see my example i hope you find why when you use ownerdraw you get error.
in MSDN you see:
"BS_OWNERDRAW
Creates an owner-drawn button. The owner window receives a WM_DRAWITEM message when a visual aspect of the button has changed. Do not combine the BS_OWNERDRAW style with any other button styles."
whitesky
|
|
|
|
|
HBRUSH CButtoncolorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_BTN)
{
if( pWnd == "Your specific button pointer" )
return CreateSolidBrush(RGB(0,100,0));
}
return hbr;
}
I wonder maybe you need to use new font ( by SelectObject() ) to change the font color.
|
|
|
|
|
You can use a class derived CButton and use WM_DRAWITEM of course you need to set OwnerDraw in
property button in property window
whitesky
|
|
|
|
|
I think you need to one code so see this you need to insert this code in your project for one start
m_Button.ModifyStyle(0,BS_OWNERDRAW);
m_Button is CMyButton1
class CMyButton1 : public CButton
{
DECLARE_DYNAMIC(CMyButton1)
public:
CMyButton1();
virtual ~CMyButton1();
protected:
DECLARE_MESSAGE_MAP()
public:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
};
IMPLEMENT_DYNAMIC(CMyButton1, CButton)
CMyButton1::CMyButton1()
{
}
CMyButton1::~CMyButton1()
{
}
BEGIN_MESSAGE_MAP(CMyButton1, CButton)
END_MESSAGE_MAP()
void CMyButton1::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
CRect rt;
rt = lpDrawItemStruct->rcItem;
dc.SetBkMode(0);
CString str;
GetWindowText(str);
if ( (lpDrawItemStruct->itemState & ODS_SELECTED) )
{
dc.FrameRect(&rt,&CBrush(RGB(110,170,210)));
dc.SetTextColor(RGB(0,0,0));
dc.FillRect(&rt,&CBrush(RGB(190,210,210)));
}
else
{
dc.FrameRect(&rt,&CBrush(RGB(0,0,0)));
dc.SetTextColor(RGB(255,255,255));
dc.FillRect(&rt,&CBrush(RGB(100,170,210)));
}
dc.DrawText(str,rt,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
dc.Detach();
}
</code>
whitesky
|
|
|
|
|
Hi I want to make an imap client using c++ can anyone guide me which way to follow.
Thanks,
answer_me
|
|
|
|
|
I don't kwon if it help you, but here's PJ Naughter's MAPI Implementation[^] Good luck and keep the good coding!
|
|
|
|
|
Hi!
I tried to build a sample and then I got this error:
LINK : fatal error LNK1104: cannot open file "atls.lib"
I linked all the libraries I need. I can't find this atls.lib anywhere, on my computer or the Internet. I tried to make visual c++ to ignore this lib too, but nothing works.
But through some sources i came to know that, it comes along with Microsoft Visual Studio.NET 2003 (VC7).So i installed Microsoft Visual Studio.NET 2003 (VC7)in my machine.
After that i built the application, but got the following errors:
atls.lib(atlbase.obj) : error LNK2001: unresolved external symbol ___security_cookie
atls.lib(atlbase.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
atls.lib(atlbase.obj) : error LNK2001: unresolved external symbol __SEH_epilog
atls.lib(atlbase.obj) : error LNK2001: unresolved external symbol __SEH_prolog
Can any one help me please ??
|
|
|
|