|
Hi All ,
I have a code :
int CExWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if(CWnd::OnCreate(lpCreateStruct)==-1) return -1;
CClientDC dc(this);
pDC.CreateCompatibleDC(&dc);
bitmap.CreateCompatibleBitmap(&dc,Width,Height);
pDC.SelectObject(&bitmap);
return 0;
}
void CExWnd::OnPaint()
{
CClientDC dc(this);
Draw ( pDC ) ;
dc.BitBlt(0,0,Width,Height,&pDC,0,0,SRCCOPY);
}
This is a example . I have a question . Why WM_PAINT auto update when compatible with pDC . ( the same CClientDC ) .
I'm not good at English . Sorry !!
Thanks .
|
|
|
|
|
The underlying DC in your CClientDC is where the drawing gets visible. You can use temporary DC's to do painting, but then you will have to transfer it to the 'visual' DC. That's what the BitBlt call is doing.
|
|
|
|
|
Can you share for me documentary about it ?
Thanks .
|
|
|
|
|
You can start by reading about device contexts here[^]
|
|
|
|
|
I read but i don't understand what you say . .
I will try .
Thanks .
|
|
|
|
|
It is indeed really weird.
It looks like CClientDC directly or indirectly causes window to redraw in turn causing constant flow of WM_PAINT messages.
Even wierder, you can remove BitBlt from OnPaint and window will still redraw, providing your code is equivalent to mine.
This is a toughest question I have ever encountered on many discussion forums.
I have quickly tested your code on Vista and so far I did not find any answers.
I am looking into it and when (if) I find and answer it will be a real satisfaction.
Later, I am also going to test it on XP and Windows 7.
JohnCz
MS C++ MVP
|
|
|
|
|
Hi all.
How can i get a count of the characters present in a CString.
i.e For ex: CString str = Sample("10,20,30,40,50");
I want to get the "," character count i.e 5
Any idea
Thanks
Raj
|
|
|
|
|
You can use function strtok .
Have fun .
|
|
|
|
|
What's about this:
int GetCommaCount(const CString &str)
{
int count = 0;
for(int pos = 0; pos < str.GetLength(); pos++)
{
if (str[pos] == _T(','))
count++;
}
return count;
}
|
|
|
|
|
If you use the CStringT class you can do it via the SpanIncluding()[^] method.
It's time for a new signature.
|
|
|
|
|
It's not so true because, as the MSDN documentation says, SpanIncluding returns an empty substring if the first character in the string is not in the specified set.
|
|
|
|
|
Oops!
It's time for a new signature.
|
|
|
|
|
std::count_if is another method.
Something like
bool is_comma(char c)
{
return c == ',';
}
std::string s = "1,2,3,4";
int count = std::count_if(s.begin(), s.end(), is_comma);
Edit for clarification: This algorithm can of course be applied to a CString as well using the GetBuffer() member.
home
modified on Thursday, August 26, 2010 5:31 AM
|
|
|
|
|
Of course you don't need GetBuffer :
#include <algorithm>
using namespace std;
bool is_comma(TCHAR c)
{
return c==_T(',');
}
LPCTSTR beg = (LPCTSTR) str;
LPCTSTR end = beg + str.GetLength();
int result = count_if(beg, end, is_comma);
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]
|
|
|
|
|
|
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.
|
|
|
|