|
Reinout Hillmann wrote:
I never understand this type of advise.[...]Not everything is better with std::string or CString. Old-style character arrays still work perfectly fine in a lot of cases.
But the original poster specifically stated that he wanted to learn C++. String classes (esp. std::string) are an integral part of working with C++ (as is using the STL and understanding templates).
You are right in stating that C-character arrays are fine, but they are definetly not C++, though seamlessly integrated.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
First, you should move the word arrays to be global. There's no need to repeat them.
Second, I don't see the point of using "sentence". Why not just output the words immediately? If you must store the sentence, use string .
Third, create a variable named "lastNoun" outside the loop. Assign it a random value (rand() %10 .) Use lastNoun as the index to both nouns. Just before the second usage, assign it a new random value.
You could add a small loop to ensure that you don't reuse the same noun.
(For consistancy, you should also retain the article using the same method.)
|
|
|
|
|
Hello,
I need to retrieve Date&Time from a remote UNIX server in the poche format to synchronize mi machine using a TCP/IP conection via sockets, how can I do that programming in VC++??
Edujule
|
|
|
|
|
If that server is listening on a particular port (some use 37, others 13), it can be done. Check out time_a.timefreq.bldrdoc.gov for more.
|
|
|
|
|
Hello,
The following code seems to work perfectly fine on Win 2k and above.. I think it may have some type of memory leak on 9x machines.. Can anyone find anything wrong with the following code?
It's used to paint my tree view..
void CMyTreeView::OnPaint()
{
if(IsWindowVisible())
{
CPaintDC dc(this);
CRect rcClip, rcClient;
dc.GetClipBox(&rcClip);
GetClientRect(&rcClient);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(&dc, rcClient.Width(), rcClient.Height());
CBitmap* pOldBitmap = memDC.SelectObject(&bitmap);
memDC.SelectObject(&bitmap);
CRgn rgn;
rgn.CreateRectRgnIndirect(&rcClip);
memDC.SelectClipRgn(&rgn);
rgn.DeleteObject();
CWnd::DefWindowProc(WM_PAINT, (WPARAM)memDC.m_hDC, 0);
if(m_bColor)
{
CRect border;
GetTreeCtrl().GetClientRect(&border);
memDC.FillSolidRect(0,0,1,border.bottom, RGB(255,0,0));
memDC.FillSolidRect(0,0,border.right,1, RGB(255,0,0));
memDC.FillSolidRect(border.right-2,0,2,border.bottom,RGB(200,0,0));
memDC.FillSolidRect(0,border.bottom-2,border.right,2,RGB(200,0,0));
}
HTREEITEM hItem = GetTreeCtrl().GetFirstVisibleItem();
while(hItem)
{
CRect rect;
UINT selflag = TVIS_DROPHILITED | TVIS_SELECTED;
Color_Font cf;
if (!(GetTreeCtrl().GetItemState(hItem, selflag) & selflag)
&& m_mapColorFont.Lookup(hItem, cf))
{
CFont *pFontDC;
CFont fontDC;
LOGFONT logfont;
CFont *pFont = GetFont();
pFont->GetLogFont(&logfont);
if(GetItemBold(hItem))
logfont.lfWeight = 700;
fontDC.CreateFontIndirect(&logfont);
pFontDC = memDC.SelectObject(&fontDC);
if(cf.color != (COLORREF)-1)
memDC.SetTextColor(cf.color);
CString sItem = GetTreeCtrl().GetItemText(hItem);
GetTreeCtrl().GetItemRect(hItem, &rect, TRUE);
memDC.SetBkColor(RGB(255,255,255));
memDC.TextOut(rect.left+2, rect.top+1, sItem);
memDC.SelectObject(pFontDC);
}
hItem = GetTreeCtrl().GetNextVisibleItem(hItem);
}
dc.BitBlt(rcClip.left, rcClip.top, rcClip.Width(), rcClip.Height(), &memDC,
rcClip.left, rcClip.top, SRCCOPY);
memDC.SelectObject(pOldBitmap);
pOldBitmap->DeleteObject();
memDC.DeleteDC();
}
}
BOOL CMyTreeView::OnEraseBkgnd(CDC* pDC)
{
pDC = NULL;
return TRUE;
}
Thanks,
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
Looks good to me. You don't need to (and shouldn't) call pOldBitmap->DeleteObject() because the bitmap is still selected into the device context. Shouldn't cause any problems because you're deleting the device context without doing anything else to it, but you should remove that line
A couple of other points though...
What is the reason for setting pDC to NULL in OnEraseBkgnd() ? It's not necessary and will have absolutely no effect at all
Why are you using IsWindowVisible() ? OnPaint() won't get called unless the window is visible...
And you don't need to set the clip region in your memory device context. Your BitBlt() call is only copying the parts in the clip box anyway. Speed may seem like a reason to do it, but the process of checking everything against the clip region can be slower than simply writing everything to a memory device context, particularly for lower-end graphics cards.
Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Ryan Binns wrote:
You don't need to (and shouldn't) call pOldBitmap->DeleteObject()
Thanks, I'll remove that...
Ryan Binns wrote:
What is the reason for setting pDC to NULL in OnEraseBkgnd()?
I set that to NULL to get rid of the level 4 warning..
Ryan Binns wrote:
Why are you using IsWindowVisible()? OnPaint() won't get called unless the window is visible...
I'll take that out..
I'll remove the clip region too..
Thanks for all your help!
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
RobJones wrote:
I set that to NULL to get rid of the level 4 warning
Try using the UNUSED() or UNUSED_ALWAYS() macros, or simply declaring the parameter without a name:
BOOL CMyTreeView::OnEraseBkgnd(CDC* ) If a parameter has no name, the compiler assumes it isn't used, and just ignores it. I usually leave it in a comment, so I can see what it actually is if I need it later
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I used the /*pDC*/ instead of pDC = NULL;
Thanks for all your help..
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
You're welcome
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi,
If we want to display a bmp onto a CView derived class's DC, why do we usually create a memory DC first and then select the bmp into that memory DC and then BitBlt the memory DC onto the CView DC?
Why not directly select the bmp into the CView DC?
Why do we go through a memory DC? Is it because it is faster to do it that way??
Regards,
Melwyn
|
|
|
|
|
Bitmaps cannot be selected into windows DCs, they can only be selected into memory DCs.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Hi Paul,
Thanks for the reply. It cleared a long-standing doubt of mine.
By the way, is it absolutely necessary to select atleast 1 bitmap into the memory DC before you can start drawing into the memory DC?
Thanks,
Melwyn
|
|
|
|
|
Hello
I am trying to allocate more than 1.3 Gb memory in my MFC based program.But it doesn't work with error No 8(not enough memory)
While I could do this on Non-MFC application.Anyone has a solution for this?
|
|
|
|
|
If the memory is not available, it's not available. Remember that your process only gets a 2GB address space (unless you have NT and started it with the /3GB option), and unless 1.3GB of that is contiguous, the allocation request will fail.
|
|
|
|
|
Because of the scattered loading of dlls inside the process address (2GB) space this is almost impossible...
DavidCrow wrote:
/3GB option
And the /3GB option is only available on the advanced server and data center server versions of windows.
John
|
|
|
|
|
try using memory mapped files?
|
|
|
|
|
amiru wrote:
I am trying to allocate more than 1.3 Gb memory in my MFC based program.
Just curious, but what (in broad terms if necessary) are you doing that requires a 1.3GB allocation? Is this just an experiment?
|
|
|
|
|
David Kentley wrote:
Just curious, but what (in broad terms if necessary) are you doing that requires a 1.3GB allocation? Is this just an experiment?
I am curious too, but there are certain applications that eat up your memory like crazy. I have never seen them being used in Windows (only in Unix), but they are Cadence Tools, Silicon Ensemble, etc. I have written programs by using some data structures called Binary Decision Diagrams (for research purposes), that would consume up to 1GB of memory in just a few minutes. Of course the machines would work so slowly afterwards because the swap space was being used afterwards. We would use all sorts of tricks not to let the programs use so much memory. I know of cases where these BDDs would reach 10GB and more, but our machines didn't have more than 1GB of memory.
// Afterall, I realized that even my comment lines have bugs
When one cannot invent, one must at least improve (in bed).-My latest fortune cookie
|
|
|
|
|
Video editing would easily use this much memory, as would high-resolution image processing, high-quality audio processing (studio work), just about any military algorithms (radar, sonar etc...).
They're pretty specialised applications, but they certainly exist
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Ryan Binns wrote:
Video editing would easily use this much memory, as would high-resolution image processing, high-quality audio processing (studio work), just about any military algorithms (radar, sonar etc...).
They're pretty specialised applications, but they certainly exist
I don't doubt it. It just seems to me that when talking about THAT much memory (at least on a standard PC), that you would generally get better performance by figuring out ways to not use so much memory at once.
I guess that could be tough to do in some cases. I wonder how much memory is alloc'd at one time for today's high end video games? It's gotta be getting pretty high.
|
|
|
|
|
David Kentley wrote:
I wonder how much memory is alloc'd at one time for today's high end video games?
I <marquee behavior="alternate" height="17" width="54" direction="up" scrollamount="1" scrolldelay="5" truespeed=""><marquee behavior="alternate" height="12" width="54" direction="left" scrollamount="1" scrolldelay="3" truespeed="">shudder to think...
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
hello ppl
what i am trying to do here is find out what functions are available for a particular DLL for example most of the API function are contained in USER32.DLL file we can write code for accessing functions like SendInput and SetLayeredWindowAttributes that is we can explicitly link the DLL file and get those functions to work now what i want to do it there is a third party DLL that i would like to explicitly link now the problem is with USER32.dll i am aware of the functions their return types and their parameters but such is not the case with a third party DLL how do i know what functions this DLL contains the parameters the return type and everything any help would be appreciated
Regards
Ahmed Ajmal
|
|
|
|
|
You can't get parameter and return value information from a DLL. You'll need third-party-supplied information to know that. You can get a list of the functions it exports by examining the export table, but you can't get any information about them, other than their name.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
yeah ryan actually i tried the DEPENDS tool that installs with the Visual Studio and yes i did find out the functions their names but not any other imformation and what do u mean by EXPORT TABLE how do i use that
Ahmed Ajmal
|
|
|
|
|