|
|
Assuming your string is
CString str = _T("Sample(10,20,30,40,50)");
Then
int start = -1;
int count = 0;
while ( (start = str.Find(_T(','), start + 1)) != -1)
count++;
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]
|
|
|
|
|
raju_shiva wrote: i.e For ex: CString str = Sample("10,20,30,40,50");
I want to get the "," character count i.e 5
Shouldn't that be 4?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
You can use the CString::Tokenize[^] method by specifying "," as the token delimiter.
You can get the count by incrementing a variable in the while loop in the example in the above link.
|
|
|
|
|
Hi all,
dialog box in my application having so many controls.i want to print it.
i want to print dialog box screen.
please tell me how can i do this.
thank in advance.
|
|
|
|
|
I've answered a similar question in the QA section some time ago.
Check out my answer[^] which contains a working example.
|
|
|
|
|
its working fine thanks.
but dialog size display smaller than its real size.
|
|
|
|
|
Set your printer resolution same as your screen resolution and the problem should gone.
Another approach is to create the bitmap of the dialog based on the printer resolution, but in some cases
(on high resolution printers) this can generate huge bitmaps, so setting the printer resolution is easier and safer.
|
|
|
|
|
Nice piece of code and certainly worth a 5.
It's time for a new signature.
|
|
|
|
|
Thank you very much Richard!
|
|
|
|
|
its not display the OnPaint graphics in image.
|
|
|
|
|
Le@rner wrote: its not display the OnPaint graphics in image.
I'm not sure what you mean.
There is not OnPaint method in my code.
There is only OnPrint and it is working as expected, prints the dialog.
|
|
|
|
|
i draw a header on dialog box in OnPaint function.
|
|
|
|
|
In that case you should draw it again in on the bitmap of the dialog.
This can be done in OnPrint method.
Here is a snippet from the method with comments to show you where you can draw:
void CDlgTestDlg::OnPrint(CDC *pDC, CPrintInfo* pInfo)
{
HBITMAP hWndBmp = GetWndBmp(GetSafeHwnd());
RECT rect;
GetWindowRect(&rect);
int nWidth = rect.right - rect.left;
int nHeight = rect.bottom - rect.top;
CDC dcSrc;
dcSrc.CreateCompatibleDC(NULL);
const int nRestorePoint = dcSrc.SaveDC();
dcSrc.SelectObject(hWndBmp);
pDC->BitBlt(0, 0, nWidth, nHeight, &dcSrc, 0, 0, SRCCOPY);
dcSrc.RestoreDC(nRestorePoint);
dcSrc.DeleteDC();
DeleteObject(hWndBmp);
}
|
|
|
|
|
|
You are welcome!
|
|
|
|
|
One more query,
OnPaint graphics overlap with image and not display exactly same as dialog display,
if i draw graphics on OnPrint again.
there is any other option to print dialog with Paint graphics.
thanks.
|
|
|
|
|
This happens because the viewport of the bitmap dc is not synchronized with the client rect of the dialog.
Try something like that:
void CDlgTestDlg::OnPrint(CDC *pDC, CPrintInfo* pInfo)
{
HBITMAP hWndBmp = GetWndBmp(GetSafeHwnd());
RECT rect;
GetWindowRect(&rect);
int nWidth = rect.right - rect.left;
int nHeight = rect.bottom - rect.top;
CDC dcSrc;
dcSrc.CreateCompatibleDC(NULL);
const int nRestorePoint = dcSrc.SaveDC();
dcSrc.SelectObject(hWndBmp);
CRect rcClient, rcWindow;
GetWindowRect(rcWindow);
GetClientRect(rcClient);
CRect rcClientMoved(rcClient);
rcClientMoved.MoveToXY((rcWindow.Width() - rcClient.Width()) / 2,
(rcWindow.Height() - rcClient.Height() - GetSystemMetrics(SM_CYBORDER)));
CPoint ptViewPortOrg = dcSrc.GetViewportOrg();
dcSrc.SetViewportOrg(rcClientMoved.TopLeft());
dcSrc.SetViewportOrg(ptViewPortOrg);
pDC->BitBlt(0, 0, nWidth, nHeight, &dcSrc, 0, 0, SRCCOPY);
dcSrc.RestoreDC(nRestorePoint);
dcSrc.DeleteDC();
DeleteObject(hWndBmp);
}
This should do the job!
|
|
|
|
|
Hi, how to use iterators in file stream can any one explain me with sample code, that read and write files using iterator
|
|
|
|
|
Please explain what you are trying to achieve. Files and iterators are two completely different concepts.
|
|
|
|
|
Really? I was under the impression that istream_iterator and ostream_iterator were for exactly that purpose.
|
|
|
|
|
Looking at the other replies, I realized that I misunderstood his question. I thought that he wanted to serialize a container and use the iterators to save the data. that's why I asked him more information.
|
|
|
|
|
something like that (snatch from a google search):
std::ifstream ifs("filename.txt");
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
?
Watched code never compiles.
|
|
|
|
|
Maximilien wrote: std::ifstream ifs("filename.txt");std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
Something like this is much faster,
std::ifstream stream("c:\\test.txt");
if (stream.good())
{
std::stringbuf buf;
stream>>&buf;
std::string str(buf.str());
stream.close();
}
|
|
|
|
|