|
CString has more to offer
void CMyClass::MyFunc()
{
CFile myFile(L"C:\\MyFile.txt", CFile::modeRead);
CString myString;
myFile.Read(myString.GetBuffer(myFile.GetLength()+1), myFile.GetLength());
myString.ReleaseBuffer();
myFile.Close();//not needed ?
}
and some error checking for the File I/O is missing Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
My attempt goes wrong here:
myString.ReleaseBuffer();
Something about lengths not matching. I've tried taking off the +1 but no luck.
I get a debug assertion:
Expression: nLength <=GetData()->nAllocLength
Almost, but not quite, entirely unlike... me...
|
|
|
|
|
i guess your are mixing Multibyte and Unicode. Compile the project in Unicode. Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
KarstenK wrote: i guess your are mixing Multibyte and Unicode. Compile the project in Unicode.
Yes, I have been compiling my project(s) in Unicode.Almost, but not quite, entirely unlike... me...
|
|
|
|
|
|
CFile myFile(_T("C:\\u_MyFile.txt"), CFile::modeRead);
TCHAR* pchContents = new TCHAR[myFile.GetLength()];
myFile.Read(pchContents, myFile.GetLength());
CString myString = (TCHAR *)pchContents;
myFile.Close();
delete[] pchContents;
|
|
|
|
|
CFile myFile(_T("C:\\u_MyFile.txt"), CFile::modeRead);
int len = myFile.GetLength();
TCHAR* pchContents = new TCHAR[len + 1];
memset(pchContents, 0, (len + 1) * sizeof(TCHAR));
int n = myFile.Read(pchContents, len);
CString myString = (TCHAR *)pchContents;
myFile.Close();
delete[] pchContents;
|
|
|
|
|
Thanks for the suggestions, but neither worked... Almost, but not quite, entirely unlike... me...
|
|
|
|
|
The below works if u_MyFile.txt is UNICODE and the project configuration is also UNICODE.
When switching project configuration it is better to use the portable type TCHAR.
CFile myFile(_T("C:\\u_MyFile.txt"), CFile::modeRead);
int len = myFile.GetLength();
const int MB_BUFFER_SIZE = 1024;
TCHAR* pchContents = new TCHAR[len + 1];
memset(pchContents, 0, (len + 1) * sizeof(TCHAR));
int n = myFile.Read(pchContents, len);
char mbString[MB_BUFFER_SIZE];
size_t countConverted;
mbstate_t mbstate;
#ifdef _UNICODE
pchContents++;
::memset((void*)&mbstate, 0, sizeof(mbstate));
countConverted = wcsrtombs(mbString, (const wchar_t **)&pchContents, MB_BUFFER_SIZE, &mbstate);
CStringA myString = mbString;
if (errno == EILSEQ)
{
printf( "An encoding error was detected in the string.\n" );
}
else
{
printf( "%s\n", myString.GetBuffer());
}
#else /* assuming txt file read is not UNICODE */
CString myString = pchContents;
printf( "%s.\n", myString.GetBuffer());
#endif
|
|
|
|
|
I am trying for a transpaerent radio button with colored text,
i tried so many options by overwriting WM_CTRL_CLR or WM_ERASE_BKGND etcc.. its working for static and buttons but radio buttons not working... can any throw a light on this.. how we can do it
|
|
|
|
|
From comctrl6,if theme enabled you cannot change the text color of the raido button usign the WM_CTLCOLOR color. AFAIK, one thing we can do is, disable theme only for radio button. After this your code in the CTL color will work.
eg:
SetWindowTheme( GetDlgItem( IDC_RAIOD_BTN_ID)->m_hWnd, L"", L"" );
where IDC_RAIOD_BTN_ID is the id of the radio button
|
|
|
|
|
Hope this may help
1.Create a CBrush member variable in Dialog class
CBrush m_brush;
2.In OnInitDialog, Create the brush with background color of the dialog
m_brush.CreateSolidBrush(RGB(200,100,0));
3.Handle the WM_CTLCOLOR message of the dialog and change the OnCtlColor function
HBRUSH CTestRadioDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if(pWnd->GetDlgCtrlID()==IDC_RADIO1)
{
pDC->SetBkColor(RGB(200,100,0));
pDC->SetTextColor(RGB(0,100,200));
return m_brush;
}
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
|
|
|
|
|
Have you tried
CDC::SetBkMode(TRANSPARENT) .
Regards,
Paresh.
|
|
|
|
|
What is the background of your dialog or window? A Image, or just filled with a color?
|
|
|
|
|
you can also use the radio button without text and paint the text yourself or in another static. Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Hi all,
i working on SMS sending application,
i able to send sms in Text mode by AT command,but some mobile not supported the Text mode format to sending sms,
so i want to send sms in PDU format.
please tell me how can i send sms in PDU mode by AT commands,
if possible please provide me any sample or example.
please tell me also how can create PDU code.
thanks in advance.
|
|
|
|
|
Hi
I am having listcontrol with different many columns in report view.
I need to setup a different color for a single columns depending upon the status such as started,finished etc.,
Kindly help me..
Regards
Ganesh.P
|
|
|
|
|
|
|
How can i add drag drop target line when drag an item from one tree and drop it in to the another tree?
|
|
|
|
|
You want CTreeCtrl::SetInsertMark or TVM_SETINSERTMARK.
To find out which item you should display the mark at, look at: CTreeCtrl::HitTest / TVM_HITTEST message, and the TVHITTESTINFO Structure.
For an application that does these things brilliantly, have a look at Dan.G.'s todo list article here on codeproject. If you look at one of the earlier versions so it's smaller, that may help you.
Good luck,
Iain.I have now moved to Sweden for love (awwww).
|
|
|
|
|
Forgive me if this has already been answered recently. I have a solution that I am ready to distribute. I want to package it with a licensing/registration utility to disperes as shareware. Your typical use for period then force registration. It doesnt need to be real hardcore protection as my application is not that big of a deal. But does need to be simple to implement. And appear to the user to be a decent product. I have been searching for some time and most of these are big bucks! I dont mind paying for this product, but not what most are charging. Also, I want to know that the program works well. I dont want people not being able to register my product. Any help in this matter is greatly appreciated. What programs would you recommend? What are you using?
Thank you very much for your time.
|
|
|
|
|
bump......nobody?
|
|
|
|
|
I have a program that maintains a log file. The file is created at the start of the program and appended to as needed. In normal operation this works fine, but I added the program to my "Run at windows startup" list, and while the program runs fine, the log file doesn't exist where I placed it. According to fstream::is_open, the file opened correctly and I have no error messages anytime I use the stream, but the file is just not there.
I know the simple solution is to keep the data in memory until it needs to be written to file (sometime far after windows startup), but I was more interested in why it won't create the file and why I don't get any errors. Is there anyway to account for this other than rewriting the where and when the file is opened?
|
|
|
|
|
Are you sure you're not getting errors? Are you checking? I'd suggest making the file stream throw exceptions on errors (it makes them harder to ignore):
fs.exceptions(ios::eofbit | ios::failbit | ios::badbit); Steve
|
|
|
|