|
I need to know when the text in a CEdit control is too long to display in the control. The control has the ES_AUTOHSCROLL style set and is read only. The problem is that EN_MAXTEXT is only sent when the text length exceeds the value returned by GetTextLimit() as the number of chars but as the control uses a proportional font the number of chars that will fit in the control will vary depending on the actual text.
So how can I do this?
The text is being added programmatically.
Thanks,
Parish
while (!asleep)
code();
|
|
|
|
|
You could monitor EN_CHANGE (or is it EN_CHANGED?)
Get the current text. Use one of the GetTextExtentPoint32 routines to get the length of that text.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Hmmm, I was beginning to think that I would have to do the size comparison myself. This is not good, IMHO, as this fuctionality must be built into the control so, when the WS_HSCROLL is used with a multi-line control, it can determine when to enable/disable the horizontal scrollbar.
Thanks for the quick reply, I'll take a look at GetTextExtentPoint32.
Regards,
Parish
while (!asleep)
code();
|
|
|
|
|
Sure, it is code already in the control, but not exposed to the developer. (Unless I missed it.)
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Hi Tim,
I followed your suggestion and used GetTextExtentPoint32() but something's not quite right. Can you help out please?
This is my code:
CString line;
// Code to populate ``line''
m_edit3.SetWindowText(line);
RECT rect;
m_edit3.SendMessage(EM_GETRECT, 0, (LPARAM)&rect);
CDC *cdc = m_edit3.GetWindowDC();
HDC hdc = cdc->GetSafeHdc();
SIZE Size;
GetTextExtentPoint32(hdc, (LPCTSTR)line, line.GetLength(), &Size);
but the following values are returned:
rect.left 4
rect.top 1
rect.right 394
rect.bottom 14
so the formatting rect of the edit control is 390 x 13, but Size contains the following:
Size.cx 552
Size.cy 16
The string (line) contains 72 chars and only the last 3 chars are outside the edit box.
Do these 2 values (rect & Size) use different units?
Any help would be greatly appreciated.
Regards,
Parish
while (!asleep)
code();
|
|
|
|
|
I'm trying to put strings in a richedit box I made with the Microsoft's Active X control in MFC, but it just won't work. Hope somebody can help me.
Thx. Lio.
|
|
|
|
|
Post your code.
--Mike--
http://home.inreach.com/mdunn/
"Listen you footwarriors, can you hold down a bit with the firing? I've just got three impromptu weddings breaking out behind me!" -- Arthur Dent
your with and
|
|
|
|
|
"Listen you footwarriors, can you hold down a bit with the firing? I've just got three impromptu weddings breaking out behind me!" -- Arthur Dent
When did he say that ?
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
That's from the last radio show, when the Lintillas and the anticlones get married so the anticlones can kill the Lintillas.
--Mike--
http://home.inreach.com/mdunn/
"Listen you footwarriors, can you hold down a bit with the firing? I've just got three impromptu weddings breaking out behind me!" -- Arthur Dent
your with and
|
|
|
|
|
??
I have an owner drawn control. It calls SetFont, then MeasureItem, then DrawItem for each item. Is there any way of calling MeasureItem each time DrawItem is called? Or is there a way to get a handle on
LPMEASUREITEMSTRUCT lpMeasureItemStruct
So that I can call MeasureItem again.
Please, please any response any one can give me will be greatly appreciated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
I was wondering if anyone could recommend an array class\template that would work with the following array classes within classes?
class Third
{
public:
int m_data;
double m_price;
};
typedef CArray< Third > ThirdArray;
class Second
{
public:
int m_data;
ThirdArray m_ThirdArr;
};
typedef CArray< Second > SecondArray;
class First
{
public:
SecondArray m_SecArr;
};
CArray does not like this because of the protected copy constructor. I need to be able to make copies easily of the class First.
Any ideas?
Giles
|
|
|
|
|
|
Hi Tomasz,
Yep, I guessed I would get the STL vector class as a reply. I have implemented it for the time beinf, but I find it such a horrible thing to debug with. The person who wrote it did not seem to know what tabs and carrige returns are.
I was kind of hoping that someone had written something a bit nicer. I had a go at writing my own. It workde okay until the but about an array inside an array part. I could not seem to get the copy constructor to be happy.
Thanks,
Giles
|
|
|
|
|
Yes, the STL implementation that ships with VC++ 6.0 is hard to debug. You can switch to free STLPort (www.stlport.org), it's source is orders of magnitude more readable and even has debug diagnostics.
Anyway, if you'd like to stick with MFC containers, you create new template derived from CArray and make its copy constructor public.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thanks for the tip. I think I will give STL a go. Have not touched it in about 5 years, but this gives me the excuse.
Giles
|
|
|
|
|
Following recomendations of some friends who says that standard C++ is more efficient and fast than non standard, I have a case that demonstrates it is not true....UNLESS I AM NOT CONSIDERING SOME OTHER C++ STANDARD FUNCTIONALITIES THAT ENCHANCE THE SPEED SUCH AS AN EFFICIENT BUFFERING.
The next program shows two ways of copying one file to another, the first one (CODE A) is very, very slow but the second (CODE B) is very fast. CODE A uses standard C++ (do not consider CTIME ), CODE B uses MFC.
Try this, copy/paste this program to your powerful computers and create a input text file of 40MB, run it and and you will see the amazing results.
By the way, I have necessity to read lines, that is why I show this case with this functionality.
Please comment me your points of view.
#include <afxwin.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main()
{
// CODE A
// This code................
CTime startTime = CTime::GetCurrentTime();
string sReg;
ifstream entrada; entrada.open("prov.txt");
ofstream salida("prov1.txt");
while(getline(entrada, sReg))
salida << sReg << endl;
salida.close();
entrada.close();
CTime endTime = CTime::GetCurrentTime();
CTimeSpan ts = endTime - startTime;
cout << (LPCTSTR)ts.Format("Time consumed: Mins: %M, secs: %S" ) << endl;
// is extremely lower than ...
// CODE B
// this code......
startTime = CTime::GetCurrentTime();
CString stReg;
CStdioFile ent;
CStdioFile sal;
ent.Open("prov.txt", CFile::modeRead);
sal.Open("prov2.txt", CFile::modeCreate | CFile::modeReadWrite);
while (ent.ReadString(stReg)) {
sal.WriteString(stReg);
sal.WriteString("\n");
}
endTime = CTime::GetCurrentTime();
ts = endTime - startTime;
cout << (LPCTSTR)ts.Format("Time consumed: Mins: %M, secs: %S" ) << endl;
sal.Close();
ent.Close();
}
|
|
|
|
|
I beg your pardon . The #included files are:
afxwin.h, iostream, fstream and string.
For some reason, the angular brakets have some problems.
|
|
|
|
|
> For some reason, the angular brakets have some problems
I had similar problem yesterday too while posting a message. It looks like HTML was probbaly confusing with its tagging mechanism.
Later I figured if you provide a space after and before the brackets, it works fine. Here is how I did..
#include < afxtempl.h >
Get RadVC today! Play RAD in VC++
http://www.capitolsoft.com
|
|
|
|
|
Maybe you should check out how CStdioFile class actually does the copying of the file. This is how it does it, and it seems to me like it's using what your friend calls "standard C++". (With the exception of CString)
BOOL CStdioFile::ReadString(CString& rString)
{
ASSERT_VALID(this);
rString = &afxChNil;
const int nMaxSize = 128;
LPTSTR lpsz = rString.GetBuffer(nMaxSize);
LPTSTR lpszResult;
int nLen = 0;
for (;; )
{
lpszResult = _fgetts(lpsz, nMaxSize+1, m_pStream);
rString.ReleaseBuffer();
if (lpszResult == NULL && !feof(m_pStream))
{
clearerr(m_pStream);
AfxThrowFileException(CFileException::generic, _doserrno,
m_strFileName);
}
if (lpszResult == NULL ||
(nLen = lstrlen(lpsz)) < nMaxSize ||
lpsz[nLen-1] == '\n')
break;
nLen = rString.GetLength();
lpsz = rString.GetBuffer(nMaxSize + nLen) + nLen;
}
lpsz = rString.GetBuffer(0);
nLen = rString.GetLength();
if (nLen != 0 && lpsz[nLen-1] == '\n')
rString.GetBufferSetLength(nLen-1);
return lpszResult != NULL;
}
void CStdioFile::WriteString(LPCTSTR lpsz)
{
ASSERT(lpsz != NULL);
ASSERT(m_pStream != NULL);
if (_fputts(lpsz, m_pStream) == _TEOF)
AfxThrowFileException(CFileException::diskFull, _doserrno, m_strFileName);
}
Sprudling
|
|
|
|
|
Anybody who would make a blanket statement like that should just get a pat on the head and the response, "Oh, isn't that sweet".
Standard anything based on the lowest common denominator is usually slower than something designed for the platform in question. The important phrase being "is usually".
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
OK, I accept the title is really a good way to receive the pat and response "Oh, isn't that sweet". Sorry, I was referring to the libraries.
I only intended to recieve an answer such as: If you want to speed the "code A" using C++ standard libraries (not C and not MFC) use option1, option2, ...etc.
Actually, I need a very fast reading/writing process because I manage big files and I do not only read files, I make other complex memory manipulations for every line I read.
According to your answer, it means that the only solution is to use MFC, because I could demonstrate it is faster than C++ standard libraries. I do not feel happy because my intention to use standard C++ libraries for manipulating files (GUI is not important) will be deferred. May be, in a LINUX or UNIX environment it works faster but, in my work, we use Windows platform.
Thank you for your comments.
|
|
|
|
|
How to convert char * to LPWSTR for func. NetWkstaUserEnum??
|
|
|
|
|
Try MultiByteToWideChar function
regards
|
|
|
|
|
If you have ATL installed, take a look at AtlA2WHelper.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
If you're using MFC, you can use CString to do it, just call AllocSysString.
Either way, you can cast to _bstr_t in order to do this conversion. Just #include <comdef.h>
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|