|
Well, you may consider the BSTR as a wide char string, hence you may use the corrensponding functions like, for instance, wcstok [^].
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hi,
i m reading data of csv file in a char buffer like this
CFile shopCart(strFileName,CFile::modeRead);
char buff[5000]={0};
shopCart.Read(buff,sizeof(buff));
and then saving changes before closing application in this way.
CFile::Remove(strFileName);
CFile csvFile(strFileName,CFile::modeWrite |CFile::modeCreate );
strCSV = L"|" + strCSV+ char(13) + char(10);
csvFile.Write(strCSV,strCSV.GetLength()*sizeof(TCHAR));
problem is that at first exec buffer holds data of all the file but after closing and re exec buffer contains only one character of file even though file contains same data after updation.wat can be the problem may b?
|
|
|
|
|
Please compare the return values of UINT uiReadBytes = chopChart.Read(..);
at the first an secon running and post them here
virtual void BeHappy() = 0;
|
|
|
|
|
in both cases uireadbytes contains 0.
|
|
|
|
|
Try it :
{
...
CFile cFile;
if (cFile.Open(strFileName, CFile::modeRead)) {
BYTE byBuffer[1024] = {0};
UINT uiReadBytes = cFile.Read(byBuffer, sizeof(byBuffer));
CString cszMessage;
cszMessage.Format(_T("File: %s:\r\nCount of read bytes = %u"),
strFileName, uiReadBytes);
AfxMessageBox(cszMessage);
cFile.Close();
}
...
}
virtual void BeHappy() = 0;
|
|
|
|
|
actually on saving file at close of application it is inserting end of file after every character.this is actually the problem.
|
|
|
|
|
Please answer,
what have you seen at the message boxes ?
virtual void BeHappy() = 0;
|
|
|
|
|
in both cases it is showing count 1024 in messageboxes..my qus is that where is my code inserting EOF after every character?
|
|
|
|
|
|
why my code is inserting EOF after evry character on saving file.where my code is wrong?
|
|
|
|
|
When your project is configured as UNICODE project
the output will be performed by two bytes per character...
Would you like to see your output in ANSI ?
virtual void BeHappy() = 0;
|
|
|
|
|
yes?but i want to keep the project as unicode
|
|
|
|
|
چرا که نه؟
Just convert your string to ANSI sequence:
#include <AtlConv.h>
...
{
...
USES_CONVERSION;
LPSTR lpszANSI = T2A(cszOut);
cOutFile.Write(lpszANSI, strlen(lpszANSI));
...
}
virtual void BeHappy() = 0;
|
|
|
|
|
thanx a lot Eugen Podsypalnikov that was what the problem was actually it was inserting extra byte.thanx nw it is working fine after converting to ansi.
Regards
|
|
|
|
|
You are welcome !
(sometimes I do read and write UNICODE csv-files,
you could it too, when it will be needed once )
virtual void BeHappy() = 0;
|
|
|
|
|
yeah thanx
|
|
|
|
|
Hi i want to crate a rectangle based on the font size, font style,and number of charactes.So How can i decide width and height of different font size,font style & number of characters.
|
|
|
|
|
You can get the font information from CWnd member GetFont(http://msdn.microsoft.com/en-us/library/cb4schcy(VS.80).aspx)
And GetLogFont of the CFont will help get the information about the font.
http://msdn.microsoft.com/en-us/library/zhcs623h(v=VS.71).aspx
Величие не Бога может быть недооценена.
|
|
|
|
|
This function could calculate the text dimensions :
void GetTextSize(CSize& cResultSize,
CDC* pcDC,
CFont* pcFont,
const CString& cszText)
{
if (pcDC && pcFont) {
CGdiObject* pcOldFont = pcDC->SelectObject(pcFont);
cResultSize = pcDC->GetTextExtent(cszText);
pcDC->SelectObject(pcOldFont);
}
}
virtual void BeHappy() = 0;
modified on Friday, April 2, 2010 2:12 AM
|
|
|
|
|
Please can you me an example.
|
|
|
|
|
It could be something like this :
void CYourView::OnDraw(CDC* pDC)
{
if (pDC) {
CString cszText(_T("Hello World !"));
CRect cTextRect(CPoint(100, 100),
pDC->GetTextExtent(cszText));
pDC->FillSolidRect(cTextRect, RGB(0, 200, 0));
pDC->DrawText(cszText, cTextRect, DT_LEFT | DT_TOP);
}
}
virtual void BeHappy() = 0;
|
|
|
|
|
actually i want create a Button based on fontsize fontstyle ,no of characters and font type.I dont know what actul text or characters. only i have a options like.
No of characters : 50
Font Size : 16
Font Style : Regular/Bold/Italic
Font Type : Times New Roman or Arial or Courier
How width and height can be decided for the above ? so i can create a Button by assigning width and height easily .
|
|
|
|
|
Try it :
#define GAP 20
CSize GetButtonDimensions(int iCharCount,
int iFontSize,
const CString& cszFontName)
{
CSize cResultSize(0, 0);
CFont cFont;
if (cFont.CreatePointFont(iFontSize * 10, cszFontname)) {
CDC cDC;
if (cDC.CreateCompatibleDC(NULL)) {
CGdiObject* pcOldFont = cDC.SelectObject(cFont);
TEXTMETRIC tm = {0};
cDC.GetTextMetrics(&tm);
cResultSize.cy = tm.tmHeight + 2 * GAP;
cResultSize.cx = tm.tmMaxCharWidth * iCharCount + 2 * GAP;
cDC.SelectObject(pcOldFont);
}
cFont.DeleteObject();
}
return cResultSize;
}
virtual void BeHappy() = 0;
|
|
|
|
|
i am getting error :
[CGdiObject* pcOldFont = cDC.SelectObject(cFont);]
'initializing' : cannot convert from 'HGDIOBJ' to 'CGdiObject *'
|
|
|
|
|
Sorry, ..cDC.SelectObject(&cFont);
virtual void BeHappy() = 0;
|
|
|
|