|
bob16972 wrote: would it be more efficient to make the methods non-static and simply require the parameters in a constructor
I would say yes, slightly.
In the static A calls static B calls static C scenario, the 10 params are pushed on and copied off the stack 3 times.
In a constructor the 10 params would only need to be pushed/copied once (plus there's an additional call/return to
the constructor added on). The 3 method calls only have the implicit "this" pointer pushed on the stack.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Good deal.
I use some utility classes to convert MFC types to GDI+ types for drawing text and passing all those parameters around seems clunky and now I need to add more functionality and wasn't sure if cleaning it up and making it a nice solid class would waste any more clock ticks.
If anything, I just need to make sure I don't weigh it down any more since GDI+ is pretty darn slow as it is.
Thanks for the input.
|
|
|
|
|
Hi Guys
I am a new comer to programming and this forum.
I have been looking at some code I found on the internet and in the header files they have what i believe are called header wrappers. Which I understand are to stop the header file from being defined more than once.
The code looks like this:
#if !defined(AFX_MYDERIVATIVE_H__AC73BB0F_CC43_4B4B_850A_4DC13A664B8C__INCLUDED_)
#define AFX_MYDERIVATIVE_H__AC73BB0F_CC43_4B4B_850A_4DC13A664B8C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "myFunction.h"
namespace Ovalkey {
//class definitions
};
#endif
My question is why the strange symbol AFX_MYDERIVATIVE_H__AC73BB0F_CC43_4B4B_850A_4DC13A664B8C__INCLUDED_
Is this something generated by Visual Studio? or just some strange thing the programmer decided to call the variable?
Many thanks
|
|
|
|
|
This strange constant was generated by your friendly MFC Wizzard, when you used it to generate the Class Files. It is based on a GUID (Globally Unique Identifier). It's purpose is to ensure that this constant is unique in the world for your header. I.e. Someone else anywhere anytime who decides to generate a Class CMyDerivative, will have a different constant.
Bram van Kampen
|
|
|
|
|
To add to the other reply,
It seems Visual C++ class wizard stopped putting these in class files after VC++ 6.0 so if your using a newer Visual C++ IDE, you probably won't see these in classes created with those newer IDE's.
For what it's worth.
|
|
|
|
|
i have downloaded autumnframework which is IOC for C++
but when i compile the autumnframework workspace using VC++ 6.0 but
iam getting the following errors.......
class 'Autumn::IBeanWrapper'
error C2440: 'specialization' : cannot convert from '' to ' (__cdecl *)(const char *)'
None of the functions with this name in scope match the target type
error C2975: 'BasicType' : invalid template argument for 'createfun', constant expression expected
error C2440: 'specialization' : cannot convert from '' to 'void (__cdecl *)()'
None of the functions with this name in scope match the target type
...........
..
The code is
the errors are at
.....................................
const string charAT("char");
const string ucharAT("unsignedchar");
char atoch(const char* s){return s[0];}
short atosh(const char* s){return (short)atoi(s);}
void freech(char p){}
void freesh(short p){}
TypeManager::TypeManager()
{
//I think that unsigned is same to singed to deal with except long
// The following is for basic type.
this->TypeList.push_back( new BasicType(charAT) );
this->TypeList.push_back( new BasicType(ucharAT) );
this->TypeList.push_back( new BasicType(shortAT) );
this->TypeList.push_back( new BasicType(ushortAT) );
.
.
}
The template def is
..................
template<class t,="" t="" createfun(const="" char*),="" void="" freefun(t)="">class BasicType:public IAutumnType{
private:
string typeFormat;
public:
BasicType(const string& name): typeFormat(name){}
.
.
}
please any can figure out the error
thanks in advance
naresh
-- modified at 9:55 Saturday 1st December, 2007
|
|
|
|
|
nareshtummanapalli wrote: error C2440: 'specialization' : cannot convert from '' to ' (__cdecl *)(const char *)'
please any can figure out the error
See here.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I'm c# programmer and I'm familiar with declaring methods inside a class body. Now c++ says that I should put in the body just prototypes and declare methods somewhere else using :: scope operator.
My question is: what happen if I declare a method inside a class anyway? I read somewhere that it would make it 'inline', I mean the compiler would copy it everywhere it is called instead of putting actual 'call' command... What you c++ guys say on this?
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
gajatko wrote: My question is: what happen if I declare a method inside a class anyway? I read somewhere that it would make it 'inline',
True.
gajatko wrote: ...the compiler would copy it everywhere it is called instead of putting actual 'call' command... What you c++ guys say on this?
You should only request inline for small functions. Even so, the compiler is free to ignore your request.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi,
i wanna assign a bitmap for a button. like in VB.
Could Some One tell how could i do that?
Thank you
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
You load your image with CImage class and then use of SetBitmap.
CImage m;
m.Load("C:\\1.jpg");
m_Button.SetBitmap(m_.detach());
|
|
|
|
|
should i change the CButon to CBitmapButon or it works even with the CButon Class ??
thank you
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
another thing.
it tells me that the CImage is not defined. or sth like that .
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
No you dont need to use of CBitmapButton you must set bitmap to true for button on the property window and for CImage did you include AtlImage.h on your project?
|
|
|
|
|
hai friends.
how to capture the enter key event of an edit control?
for example, user will type some data in the edit control and hits enter key.
then i have to do some validations and auto correct it.
iam able to get the enter event in the pretranslate message.
but i want the nid here.
though comparing pMsg->hwnd will do, it is not applicable for my dialog because, there are as many as 200 controls with me.
any ideas please?
thank you.
|
|
|
|
|
Hello Chandu,
You can identify whether the handle is that of an edit control by getting the class name. Please go throught the code below.
TCHAR strClassName[255];<br />
CString csEditBoxClassName( _T("Edit")); <br />
<br />
::GetClassName( pMsg->hwnd, strClassName, 255 );<br />
<br />
if( 0 == csEditBoxClassName.CompareNoCase( strClassName ))<br />
{<br />
}
I can give you one more hint. Since you have 200 controls, i guess you have created those controls dynamically by providing a range of control ids. If thats the case, you can use the resource id to identify whether its an edit control. For getting the resource id from handle,
UINT nResourceId = GetWindowLong( pMsg->hwnd, GWL_ID );
If you still have problems or if this is not what you needs, let me know.
Regards,
Jijo.
________________________________
Yesterday is history,
Tomorrow is a mystery,
But today is a present.
|
|
|
|
|
Somehow I have managed to create a bug that is driving me crazy!
I have a list of items that i show in a grid in a MDI window. The grid is drawn with MoveTo() LineTo() functions. When the list is empty only the grid lines are supposed to be shown with no data. But when the list(a collection in the Document) is empty the grid lines are not drawn. When I put a breakpoit in OnDraw() the grid drawing functions are called, but nothing shows up. Once I add an item to the list the grid lines are drawn all right. It seems to be something wrong with CDC* pDC, but I can't find out what. And I can't see why a poulated list or empty list should make a difference.
Haakon S.
|
|
|
|
|
Post the relevant code.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
void CTomhaxView::OnDraw(CDC* pDC)<br />
{<br />
pDC->MoveTo(100, 100);<br />
pDC->LineTo(200, 200);<br />
<br />
return;<br />
.<br />
.<br />
}
What can I say? This line is not drawn. When I put breakpoints the functions are called, OnPaint() is called, OnPrepareDC() is called, etc. Obviously, somewhere along the chain of funtions I have managed to interupt the setup process. Once I have added an item to my list, the above test line is drawn.
How can I check the pen that is used by the pDC?
Damn it
|
|
|
|
|
Sorry, think I have found it. Seems I have missed a required call to CalcScroll(). Thanks anyway
Haakon S.
|
|
|
|
|
How to use TerminateThread() function in program.
iam used like this but the thread is not stopped.
<br />
CWinThread* m_pNuThread;<br />
void CThrdDlg::OnButton2() <br />
{<br />
CString string;<br />
m_NuStart.GetWindowText(string);<br />
<br />
<br />
<br />
if(string =="START")<br />
{ <br />
m_pNuThread = AfxBeginThread(NuThread, this);<br />
m_NuStart.SetWindowText("STOP");<br />
}<br />
else<br />
{ <br />
<br />
TerminateThread(m_pNuThread, 0);<br />
m_NuStart.SetWindowText("START");<br />
<br />
}<br />
<br />
<br />
}<br />
<br />
<br />
UINT NuThread(LPVOID lParam)<br />
{ <br />
CThrdDlg *dlg = (CThrdDlg*)lParam;<br />
CString str;<br />
for(int i=0;i<=100;i++)<br />
{<br />
str.Format("%d",i);<br />
dlg->m_NuEBox.SetWindowText(str);<br />
Sleep(200);<br />
if(i == 100)<br />
i=0;<br />
}<br />
return 0;<br />
}<br />
kp.Vuppala
|
|
|
|
|
krishna Vuppala wrote: How to use TerminateThread() function in program.
iam used like this but the thread is not stopped.
Thread is not stopped because you're doing a mistake on passing the first argument to TerminateThread function. It must be the thread HANDLE and not the pointer to che CWinThread class .
Hence you have to use:
TerminateThread(m_pNuThread->m_hThread, 0);
BTW: as stated by the documentation you should avoid to use TerminateThread (it must be only the last resort), there are other ways to stop smoothly a thread, for instance setting and (added) flag in your thread loop control condition, i.e.:
UINT NuThread(LPVOID lParam)
{
for(int i=0; i <= 100 && bKeepRunning;i++)
}
Hence you can simply set bKeepRunning=false outside the thread to gracefully stop it.
Hope that helps.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Mr.CPallini sir ,
iam very Thankful to you..iam using 2 buttons in a Dailog with two threads.it works well.
now iam willing two generate two buttons with Single thread.is there any idea pls share with me sir...
kp.Vuppala
|
|
|
|
|
Sorry I really cannot understand your requirements, please explain better.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
I think I could decode his question.
Mr.CPallini sir ,
He has two buttons on the dialog and when he clicks each button it makes a thread they work very well now he wants that either buttons makes a single thread is it possible and if yes do you have any idea?
(what do you think it was a good decode;))
|
|
|
|