|
I found out why some chars was stripped from my message and how to send it correctly. So, here it is, again:
It is invalid C++. Your idea written correctly looks like this:
template
class TType
{
public:
CString GetAsString()
{
CString sValue;
sValue.Format(GetFormat(), m_tValue);
return sValue;
}
protected:
T m_tValue;
};
template <class T> CString GetFormat();
template <> CString GetFormat<int>() { return "%d"; }
template <> CString GetFormat<float>() { return "%.4f"; }
Unfortunately, this doesn't work on VC++ 6.0 (GetFormat<int> is called even for float's).
Try this:
template <class T>
class TType
{
public:
TType(const T& value)
: m_tValue(value)
{
}
CString GetAsString()
{
CString sValue;
sValue.Format(TypeHelper::GetFormat(), m_tValue);
return sValue;
}
protected:
T m_tValue;
};
template <class T> class TypeHelper;
template <> class TypeHelper<int>
{
public:
static CString GetFormat() { return "%d"; }
};
template <> class TypeHelper<float>
{
public:
static CString GetFormat() { return "%.4f"; }
};
--
Martin
|
|
|
|
|
You need to create a GetFormat function template and specializations for different types. VC++ seems to have problems with some forms of specializations. I was able to make the following code work:
CString GetAsString()
{
CString sValue;
sValue.Format( GetFormat(m_tValue), m_tValue );
return sValue;
}
template < class T >
CString GetFormat(const T& unused)
{
return CString();
}
template < >
CString GetFormat(const float & unused)
{
return "%.4e";
}
template < >
CString GetFormat(const int & unused)
{
return "%d";
}
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Does anybody know a possibility to display graphical primitives as Rectangles,
that are saved in the RichTextFormat File through th CRichEdit Control or any
other control
eiselekd
|
|
|
|
|
when i try to use CRecordSet functions such as SetAbsolutePosition and MoveNext etc, i get an error. When i debug, it complaints about the IsOpen function, that if m_hstmt is NULL, it returns FALSE. I can use the CRecordSet functions to a certain point, after that this error message keeps coming up.
Seems like my CRecordSet pointer looses it's position or something.
I'm using Visual Studio 6.0, and i'm trying to get information from an access database.
Kristian
|
|
|
|
|
Hmmm. sounds tricky;P
...::: knowledge is king :::...
|
|
|
|
|
I have a CEdit derived class. I wanted to override the OnChar messages and PreTranslateMessage. However, when I add these I get "member function not declared in CDerivedEdit" errors. I have checked that the correct entry is in the header file and the mapping macro in the implementation file. Am I doing something else wrong or is something weird somewhere?!
thanks in advance
|
|
|
|
|
I've been trying to close another application from within my application I've used EnumWindows to obtain the handle of the other application. The problem is If The Other Application Remains Active WM_CLOSE message works fine but if it is not active there goes the problem I'm unable to activate it and the Other Application remains without closing . Does anyone knows how to come over this?
Thanks in advance
P Vijaya Rama Raju
|
|
|
|
|
Try sending WM_QUIT to the UI Thread.
--------------------------------------------------
If my messages appear curt, I apologize.
I try to be brief to save your time as well as mine.
--------------------------------------------------
|
|
|
|
|
Can you write code ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Have you tried TerminateProcess() ?
Here is a sample:
int KillPid(DWORD pid) {
HANDLE hPid = OpenProcess(0, FALSE, pid);
if (hPid != NULL) {
if (TerminateProcess(hPid, 0) == TRUE) {
CloseHandle(hPid);
return 0;
} else {
CloseHandle(hPid);
return GetLastError();
}
CloseHandle(hPid);
}
return 1;
}<pre>
|
|
|
|
|
Thanks, it is useful example ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Some people say I can, most say I can't
Try:
http://www.codeproject.com/threads/interprocesssync.asp
--------------------------------------------------
If my messages appear curt, I apologize.
I try to be brief to save your time as well as mine.
--------------------------------------------------
|
|
|
|
|
can you point me the difference beetween:
Option m_Option;
m_Option.DoModal();
and:
m_Option = new Option(this);
m_Option->DoModal();
Both work but what is the difference "new" create a new instance ?
but if I "new" something I assume I should delete it somewhere ?
I'm a bit lost here while MFC do so much things automaticly
I don't want to miss something and to get memory leak.
Thanks
|
|
|
|
|
The difference is that m_Option is obviously a member variable to a pointer, Option is just an istance of the dialog. You never call delete on a CWnd, you call DestroyWindow, which ( I believe ) will be called for you in the case of a modal dialog. You should definately set m_Option to NULL after the DoModal though, and also in your constructor, for safety.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
In your option 's ::PostNcDestroy()
add :
delete this;
no memory leak;
|
|
|
|
|
Thanks
|
|
|
|
|
I hope somebody can help me with this (before I tear all my hair out and/or reformat my disk and reinstall everything)
For the last week or so, every now and then, as I am working in Visual Studio, I get a dialog labelled "MSDEV.EXE - No Disk", with the message "There is no disk in the drive. Please insert a disk into drive \Device\Harddisk1\DR2.". Three buttons, labelled "Ok", "Cancel" and "Try Again" each seem to do nothing, I need to terminate Visual Studio via the Task Manager to clear the message. Sometimes there is a considerable time (Hours) between stating Visual Studio and when this happens, other times it may only be a few minutes. I have uninstalled and reinstalled Visual Studio to no avail. I would suspect the hardware, except that no other application is failing in any way! BTW, I am running Windows 2000 Professional, on a new computer. I never had a problem like this on my previous machine.
Regards,
Gunter
Gunter F. Maywald
CSIRO Entomology
Long Pocket Labs, Brisbane
Australia
|
|
|
|
|
In Tools -> Options, you can go to the Directories tab and see where it's looking for things. If there are duplicate paths that don't exist anymore then you can just delete them from there and you'll have no problem anymore.
|
|
|
|
|
Hi,
I have two variables with types CString and int.
int nWidth;
CString strWidth;
strWidth = "110";
How do I convert strWidth("110") to int type(110) so I can store it in nWidth?
Please show me how to do this, thank you very much.
|
|
|
|
|
use the atoi or atol functions.
iWidth = atoi(strWidth);
|
|
|
|
|
Or you could use strtod() and strtol().
strtol() is useful if you want to read a number that is not in base 10. For example
to read hex numbers use strtol("0x12345678", NULL, 16)
_tcstol() and _tcstod() are the macros for UNICODE/MBCS portability
Stephen Kellett
--
C++/Java/Win NT/Unix variants
Memory leaks/corruptions/performance/system problems. UK based.
Problems with RSI/WRULD? Contact me for advice.
|
|
|
|
|
int nWidth = 110; <br />
CString strWidth; <br />
strWidth.Format ( "%d", nWidth );
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Use function StrToInt this way
int nWidth=StrToInt(strWidth);
just one line of code and u got inr value.;)
Gonna be 18 till I die
|
|
|
|
|
Two problems. First, why use a non standard function when atoi works perfectly well, and second ( from MSDN)
Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with Internet Explorer 4.0 or later).
Windows 95/98: Requires Windows 98 (or Windows 95 with Internet Explorer 4.0 or later).
Sounds like a bad idea to me, unless you specifically do not target the platforms not supported, and even then I would personally prefer not to get into the habit of using something I may find unavailable to me down the track, for no good reason I can see.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
I need to color 3D graphic object, the graphic object is described by multiple triangles in variable size. I need to color this 3D object. Color will be variable based on the different
heighth (Z coordinate) of the 3D dimension, but the parts which are in the same height must be in the same color. How to color this graphic object? Please help me.
|
|
|
|