|
every literal string gets a NULL appended automatically by the compiler.
However there are 8-bit and 16-bit characters and strings, and you can't just mix them.
If you use wcscat_s, you want wide char strings, the example in MSDN is:
wchar_t wszStr[] = L"1a1g";
|
|
|
|
|
Hello. I created a new icon in the resource view called "IDI_OBJECT_GLOBAL_VAR". In my "View" cpp, I added the icon to my HICON ( along with a bunch of other icons that work) using the following:
hIcon[ICON_INDEX_OBJ_GLOBAL_VAR] = AfxGetApp()->LoadIcon(IDI_OBJECT_GLOBAL_VAR);
This is then added to a tree list :
for( GUShort index = 0;
index < ICON_INDEX_MAXIMUM;
index++ )
{
m_TreeImageList.Add( hIcon[ index ] );
}
GetTreeCtrl().SetImageList( &m_TreeImageList, TVSIL_NORMAL );
When I go to insert an item with the icon, I use the following:
hNewItem = GetTreeCtrl().InsertItem( label,
ICON_INDEX_OBJ_GLOBAL_VAR,
ICON_INDEX_OBJ_GLOBAL_VAR,
parentTreeItem,
hInsertAfter );
The item itself is placed in the tree, but the icon NEVER displays. It's just blank. Any help on this would be appreciated. Thanks!
|
|
|
|
|
Have you checked the return values of LoadIcon and Add? Since you want to use your indexes as above, I suggest you put in an index check.
for( GUShort index = 0;
index < ICON_INDEX_MAXIMUM;
index++ )
{
VERIFY(m_TreeImageList.Add( hIcon[ index ] ) == index);
}
Who knows? You might be surprised!
(The point is, if any of your icons fail to be added, the indexes are screwed up)
|
|
|
|
|
Hi I have strings like
GROUP23
TREND12
GRAPH120
GRAPH01
From this i have to extract the numbers only like 23,12,120,01...
I tried atoi(),but it returns 0.
I tried Right(),
int iPanNo;
CString sNo;
CString sName = "GROUP23";
sNo = sName.Right(2);
iPanNo = atoi(sNo);
The above code works fine and it returns '23'.
But it fails for GRAPH120.For this it returns 20 not 120.
How can i do that?
Anu
|
|
|
|
|
You need to parse your string into alpha and numeric portions and then apply the conversion on the numeric portion. Take a look at the methods of CString() to see if there is a builtin that will do it for you, or use something like isdigit()[^]. The rest should be easy.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Thank you.I coded like
for (int i = 0; i < sNo.GetLength(); i++)
{
Number = sNo.GetAt(i);
if(isdigit(Number))
res += Number;
}
And it works.
Thanks.
Anu
|
|
|
|
|
compare each element of this string to the numeric range '0' to '9', if it's in the range, record it.
|
|
|
|
|
Which is exactly what I already said.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Here is something you can try.
You want only the numerals in the string and they appear after the alphabets.
First you could use CStringT::SpanExcluding to extract only the alphabets in the string.
CString sToken = sName.SpanExcluding(L"0123456789");
Next extract the characters after the length of the alphabets using CStringT::Mid .
sNo = sName.Mid(sToken.GetLength());
|
|
|
|
|
I can see a couple of approaches here. The first way would be to pile your characters in a std::string, use find_first_of to locate where the digits and then use std::stringstream to convert from the digits to a number. That's a bit clunky though.
You could go straight to using a std::stringstream, pile the characters in there and then peak at each character extracting non-digits. Once you hit a digit you could just extract the number.
Cheers,
Ash
PS: If you're stuck using CString then use Superman's idea above
|
|
|
|
|
Anu_Bala wrote: Hi I have strings like
GROUP23
TREND12
GRAPH120
GRAPH01
From this i have to extract the numbers only like 23,12,120,01...
I tried atoi(),but it returns 0.
I tried Right(),
int iPanNo;
CString sNo;
CString sName = "GROUP23";
sNo = sName.Right(2);
iPanNo = atoi(sNo);
The above code works fine and it returns '23'.
But it fails for GRAPH120.For this it returns 20 not 120.
How can i do that?
Didn't it occur to you that you would have to write some kind of crude loop to do that, at the least? Don't post such lazy assed efforts just to avoid scathing comments. These kinds of posts are far worse.
|
|
|
|
|
I think your comments are a tad harsh, particularly your choice of language.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
int begin = sName.FindOneOf("0123456789");
if (begin == -1)
{
}
iPanNo = atoi((LPCSTR)s + begin);
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]
|
|
|
|
|
Read from right - to - left.
Check if digit and set position for the left most digit.
Deduct position from length and then you can get the length of your string.
|
|
|
|
|
If you're reading from right to left, you could as well perform the conversion yourself as you pass over each digit.
|
|
|
|
|
Hi All,
I am having a tabbed dialog and all the pages contains several controls. After clicking to any control (say a radio button) if I press escape button on my keyboard the entire page became blank.
Please any one put some light on this. Thanks in advance.
Regrads,
Sandip
|
|
|
|
|
Override CDialog::OnCancel() for your all child dialogs, and do nothing there.
|
|
|
|
|
To read asynchronously there is an way-> overlapped I/O.
Open file with FILE_FLAG_OVERLAPPED flag, pass OVERLAPPED structure to ReadFile, and wait for overlapped event for some limited time.
I did not find any sample for this. There are many samples to read from COM device.
But i need a sample to read data from disk/drive/file
|
|
|
|
|
|
Thanks for your reply. It's good article and helped me. To define time i need to create an event and calcel read operation there if it takes long time. But the problem is i am calling ReadFile in a thread (GUI thread). Will it be good to create an event in thread and call another thread from this thread. Please suggest.
|
|
|
|
|
Usually (slow) I/O operation are done on a separate thread (to make the GUI responsive). Why do you need an event when you have timeouts on ReadFile (maybe I didn't got you)?
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]
|
|
|
|
|
Without using overlapped, Sometime ReadFile takes very long time(say 5 minutes) to read some data. And this create a big issue for me because after that ReadFile does not read any data from any offset. So i decided to use IO overlapped. Passed FILE_FLAG_OVERLAPPED in CreateFile and OVERLAPPED structure in ReadFile.
But here also when i call GetOverlappedResult after ReadFile program hangs because GetOverlappedResult takes 5 minutes. So i decided to create event for OVERLAPPED STRUCTURE. After creating event i call a thread where i check the elapse time. And if time pass more than 1 minutes then i call CancelIO operation to cancel the GetOverlappedResult but still it did not help me. Please check my below code and suggest
in header file, define 2 variables
OVERLAPPED osReadOperation;
HANDLE hFile;
in cpp file
void myfunc()
{
TCHAR szFileName[255];
memset(szFileName,0,sizeof(szFileName));
sprintf(szFileName,"\\\\.\\PHYSICALDRIVE0");
hFile = CreateFile(szFileName,
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
return;
BOOL fOverlapped = FALSE;
char* pDataBuf = new char[83886081];
memset(pDataBuf,0,sizeof(pDataBuf));
DWORD NumberOfBytesRead = 0;
DWORD NumberOfBytesTransferred = 0;
memset(&osReadOperation,0,sizeof(osReadOperation));
osReadOperation.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
SetEvent(osReadOperation.hEvent);
AfxBeginThread(myThread, this);
int result = 0;
if (!ReadFile(hFile,pDataBuf,83886080,&NumberOfBytesRead,&osReadOperation ))
{
if (GetLastError() != ERROR_IO_PENDING)
return;
else
fOverlapped = TRUE;
}
else
fOverlapped = FALSE;
if (fOverlapped)
{
if (GetOverlappedResult( hFile,&osReadOperation,&NumberOfBytesTransferred,TRUE))
result = 1;
else
return;
}
else
result = 1;
CloseHandle(osReadOperation.hEvent);
osReadOperation.hEvent = NULL;
}
void CAlldrivesDlg::canceltheoperation()
{
CancelIo(hFile);
}
UINT myThread(LPVOID me)
{
CAlldrivesDlg *th = (CAlldrivesDlg*)me;
OVERLAPPED * self = &th->osReadOperation;
DWORD ww = WaitForSingleObject(self->hEvent, 1000);
int bm=2;
switch(ww)
{ /* waitfor */
case 0:
th->canceltheoperation();
break;
default:
break;
} /* waitfor */
ResetEvent(self->hEvent);
return 0;
}
|
|
|
|
|
Probably, in your case, setting TRUE the bWait parameter of the GetOverlappedResult function is not a good idea, see the "Testing for the End of a File" MSDN sample.
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]
|
|
|
|
|
Thanks for the link. I noticed that it does not use time. So with this code am i able to handle the case when diskio takes long time to read any data (say 4-5 minutes).
For my case my program reads any data in few seconds but at one offset it takes some minutes to read some data (sometimes hour). Will this code solve that problem? If not then what is the solution? Should i attach the sample source code here which use overllaped io.
|
|
|
|
|
Hi,
I need to customize a CMFCPropertyGrid such that be able to display a simple button inside.
when user selects given grid, user can press button inside and then a dialog box will be displayed!
exactly like Folder dialog box.
how can i do this?
best regards
|
|
|
|