|
did you handle the WM_ERASEBKGND - Message?
BOOL CMyView::OnEraseBkgnd(CDC* pDC)
{
return true;
}
(i had several problems doing this with ScrollViews.. but maybe you achieve this)
have a nice one
bernhard
Sometimes I think the surest sign for intelligent life elsewhere in
the universe is that none of them ever tried to contact us.
|
|
|
|
|
try double-buffering
www.klangwerker.de/developer/english/double_buf.htm
(Didn`t I see this post on www.codeguru.com )
CU Mario ///
---------------------------------
www.klangwerker.de
Look out for free Win32
Serial Communication Module
for VC++ or Borland C++ Builder
---------------------------------
|
|
|
|
|
Yep, take a look at a class called CMemDC, maybe this class can help you ( you can find that here or in CodeGuru).
HTH
Braulio
|
|
|
|
|
I've never used new and delete, but figured i'd give it a try cuz they seem easier to work with and are often recommended.
CHAR* m_pBuffer; //private member
SetSize(nSize) { m_pBuffer = new CHAR[nSize]; }
~CMyClass()
{ delete [] m_pBuffer; }
I call Set Size twice but if i call it more than once and run in debug mode i get memory leaks detected!!!
Can you not dynamically resize the m_pBuff more than once...?
Help please
TIA
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
For every new you must have a delete, because new allocates memory.
If you call SetSize() twice you will have two new, but only one delete in the destructor, hence the memory leak. If you have Stroustrups C++ programming language 3rd ed., I suggest you read chapter 6.2.6.
Cheers,
/Fredrik
Sonork ID: 100.11430:PhatBoy
|
|
|
|
|
I have Bruce Eckel Thinking in C++
I did read up a little on new and delete, turns out my misunderstanding was as simple as not knowing, realloc doesn't have an equivalent new/delete operator.
new and delete are used for dynamic creation and destruction of objects on the heap, but not reallocation.
I guess i have to resort to malloc/realloc and free.
Thanx again!
have a day!
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
Have you considered using std::vector instead of new char[...] ? It has a number of advantanges over your method:- Automatic cleanup (no memory leaks).
- Improved consistency: you get the number of elements by calling
size() on the vector, with new /delete it is up to the programmer to record the size elsewhere and get this information in sync with the buffer. -
realloc -like functionality (vector::resize ). - You can still have a pointer to raw memory if needed for compatibility with other functions (just pass
&v[0] ). Once you get accostumed to std::vector s and other STL containers, you'll never want to get back to raw memory management!
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
So i've heard and yes I certainly have, but for the time being i'm keeping with what i have and i'll see what comes of it.
I'm actually doing something quite similar with templates, designed from the ground up.
Call me stupid, but i enjoy playing with things that aren't broke;P
p.s-I've heard and read little of these vectors, so correct me if i'm wrong, but basically there templates with automatic reallocation as needed. Magically index any location and whola it's available..?
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
So i've heard and yes I certainly have, but for the time being i'm keeping with what i have and i'll see what comes of it.
Believe me, the learning curve for STL is not that steep, and the payoff is worth the effort. Consider this: As soon as you start using objects with nontrivial constructors and want to have arrays of them, then you will no longer be able to use malloc and have to resort to either new /delete or STL containers (that's where you are now). What's the point of mastering the intricacies of manual memory management when STL does the job for you? After all it's just about learning one of two methodologies, and the second is by far the most profitable.
I'm actually doing something quite similar with templates, designed from the ground up.
Call me stupid, but i enjoy playing with things that aren't broke;P
I think playing with these things is an excellent way to learn the language. When it comes to writing production code, though, it is better to rely on standard libraries.
p.s-I've heard and read little of these vectors, so correct me if i'm wrong, but basically there templates with automatic reallocation as needed. Magically index any location and whola it's available..?
No, for vectors you have to indicate resizing explicitly. Other STL containers called maps work sort of like you say. Hey, type "STL tutorial" on your web searcher and enter STL paradise! You will not regret having done it
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I'll certainly consider looking into using STL.
Thinking in C++ by Bruce Eckel introduced me to templates using the vector as an example. His vector basically has magical indexing. You specify the index location and it there.
I've noticed the STL version of vectors requires explicit resizing. Honestly, i think i prefer Bruce's idea of magic indexing...sounds easier, just set and delete...It's like VB
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
You can still use new and delete. In your SetSize function you need to delete the memory first beofre allocating the new one, or if you need the old values still, copy it across:
MyClass::MyClass()
{
m_pData = NULL ;
}
MyClass::~MyClass()
{
delete []m_pData ;
}
void MyClass::SetSize(int new_size)
{
ASSERT(new_size >= 1) ;
delete []m_pdata ;
m_pData = NULL ;
m_pData = new char[new_size] ;
}
Roger Allen
Sonork 100.10016
If I'm not breathing, I'm either dead or holding my breath.
|
|
|
|
|
Thanx Roger, i already settled for malloc, realloc and free, but this looks easier on the eyes, and quick enough to redo.
Thanx again!
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
I was wondering how to use the color palette used in microsoft paint so the user can define their own colors. I've seen other programs do it so it must be possible. Does it have something to do with the CPalette class?
Sorry if its confusing, its really late.
-Raffi
The truth about C++
|
|
|
|
|
How about CColorDialog?
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
|
Can anyone tell me how to put a CRichEditCtrl in a dialog app? It will run but it closes right away and never shows the dialog. Thanks if you can help.
- Matt Newman
-Sonork ID: 100.11179:BestSnowman
Frankly AOL should stick to what it does best: Fooling millions of americans into believing that it, AOL, is the web. -Paul Watson
|
|
|
|
|
Did you call AfxInitRichEdit in your CWinApp::InitInstance function?
Matt Gullett
|
|
|
|
|
It worked, Thanks.
- Matt Newman
-Sonork ID: 100.11179:BestSnowman
Frankly AOL should stick to what it does best: Fooling millions of americans into believing that it, AOL, is the web. -Paul Watson
|
|
|
|
|
You can also create it like this without AfxInitrichedit():
extern CWnd* pParentWnd;
// The pointer to my rich edit control.
extern CRichEditCtrl* pmyRichEditCtrl;
pmyRichEditCtrl->Create(
WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE,
CRect(10,10,100,200), pParentWnd, 1);
|
|
|
|
|
You can also create it like this without afxinitrichedit():
// pParentWnd is an external pointer to the parent window.
extern CWnd* pParentWnd;
// The pointer to my rich edit control.
extern CRichEditCtrl* pmyRichEditCtrl;
pmyRichEditCtrl->Create(
WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE,
CRect(10,10,100,200), pParentWnd, 1);
|
|
|
|
|
Mmmm...
Ok !, I remember I think you have to add this code in your InitInstance method from the APP:
AfxInitRichEdit();
Funny isn´t it ? ( I think I had one time that problem it´s a sh...), Bye !
Braulio
|
|
|
|
|
This is the point :at this case you don't need to add AfxInitRichEdit() anywhere
(you do not add richedit in resources tab)
1.Define controller in header of class--->CRichEditCtrl richedit;
2.In OnCreate or OnInitDialog you create richedit---->
richedit.create(.........);
|
|
|
|
|
Hi guys,
In my MFC application, I'm using an IRC layer to make remote machines connecting into a group and exchanging data.
I send some WHO commands in order to get the addresses of the remote machines.
Sometimes, the IRC server replies with an IP Address (123.123.123.123) and sometimes with a Domain Name (this.is.my.domain) but never both. I store the result into a string. I need to get both IP Address and Domain Name, or at least the IP Address if the Domain Name is not accessible.
How do I:
- detect if the format I get is an IP Address or a Domain Name,
- convert an IP Address to a Domain Name,
- convert a Domain Name to an IP Address.
Thanks a lot in advance for your help...
Jean-Louis
|
|
|
|
|
Here's a piece of code I used some time ago:
ULONG uRemAddr = inet_addr(lpszHostAddress);
if (uRemAddr == INADDR_NONE) {
hostent* pHE = gethostbyname(lpszHostAddress);
if (pHE == 0) {
m_lastError = WSAGetLastError();
return FALSE;
}
uRemAddr = *((ULONG*)pHE->h_addr_list[0]);
}
The address is in lpszHostAddress , at the end the IP address (as a 32bit unsigned number) is in uRemAddr . You can use the getnameinfo() function to get the host name from the IP address.
|
|
|
|
|
Thanks a lot man! That saved my day...
|
|
|
|