|
|
Sometimes, you need to see each item before deleting it (like to delete data associated with the item data pointer). The reason the original code didn't work was that deleting item 0 then moves all the other items up one. Then you delete item 1 and the same thing happens to items 2-n. You probably ended up with opnly about half the items deleted. The solution is to either go through the list backwards, or to make the loop like this:
<br />
while(lbx.GetCount())<br />
{<br />
Data* p = (Data*)lbx.GetItemDataPtr(0);<br />
<br />
<br />
lbx.DeleteString(0); <br />
}<br />
|
|
|
|
|
This is buggy - you want to do DeleteString(0) not DeleteString(i) since GetCount() will return you smaller values each time you call DeleteString() .
Or as has already been pointed out, you can just use ResetContent() .
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
for(int i=0;i<pmylistbox->GetCount()-1;i++)
msn:Flashcutreg@hotmail.com
|
|
|
|
|
I've created a custom control from drawing, deriving it from a generic CWnd, and i'm drawing on it in the OnPaint function.
I've registered it with
windowclass.hbrBackground = ::GetSysColorBrush(COLOR_WINDOW); so it's 'white'
I want to clear it, paint it white again, when i click a button.
i've read about the CWnd::OnEraseBkgnd, but i don't know if it's alright to call it.
any ideas on how might i clear the control??
thanks!!!
|
|
|
|
|
void CMyDlg::OnBtnClked ()
{
m_MyCtrl.Invalidate ();
}
This will mark the whole window area as needing repainting. Part of that process is erasing the back
ground with the window class brush.
For further reading, See:
::InvalidateRect (...),
WM_PAINT ,
::BeginPaint (...) ,
WM_ERASEBKGND ,
::EndPaint (...)
for the raw information.
Iain.
|
|
|
|
|
when i press a botton from the dialog, i call
this->m_AreaPizarra.Invalidate();
then, i've overloaded the OnEraseBkgnd function, but it doesn't seem to work
BOOL CAreaPizarra::OnEraseBkgnd(CDC* pDC)
{
CPen pen(PS_SOLID, 1, RGB(0,0,0));
CPen * pen_vieja = pDC->SelectObject(&pen);
CRect rect;
GetClientRect(rect);
pDC->Rectangle(rect.left,rect.top,rect.right,rect.bottom);
return CWnd::OnEraseBkgnd(pDC);
}
is there anything wrong in that code?
|
|
|
|
|
You are painting in the window and then calling the base class OnEraseBkgnd() which will of course ERASE everything you just painted... Yes?
This i am guessing is what is making you sad
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
hi i am using MSWinSock Activex in my project to Create a Simple TCP connection through a server.
for this purpose i have to Send an Message to that Server. My message should Contain Some NULL char char(0) in it.
for example my message should be something like this : HI***This is Ehsan******Accept my request (here * means char(0) or NULL char )
MSWinSock Uses this Syntax to send a Message : void CMSWinsockControl::SendData(const VARIANT& data)
this means that i have to Save my message in a VARIANT type variable and then Send it with this function.
in VARIANT i can use BSTR to store my message in VARIANT but as u know Char(0) means the end of a String So i need to Store my message in a Different way in VARIANT variable.
one way is to store a Char[] (an array of char) in a Variant !! is it Possible ??
Thankx a lot
|
|
|
|
|
As a BSTR includes the size of the string (rather than relying on null termination), it
should exactly suit your needs.
Just a quick look at CComBSTR:
CComBSTR( );
CComBSTR( int nSize );
CComBSTR( int nSize, LPCOLESTR sz );
CComBSTR( int nSize, LPCSTR sz );
nSize
[in] The number of characters to copy from sz.
sz
[in] A string to copy. The Unicode version specifies an LPCOLESTR; the ANSI version specifies an LPCSTR. Only nSize characters will be copied. The default value is NULL.
So that *should* sort out your problem.
Iain.
|
|
|
|
|
why don't yopu try the void
*memset( void *dest, int c, size_t count );
function which inits the memory of a string with a given char on a certain length; or
char *_strset( char *string, int c );
char *_strnset( char *string, int c, size_t count );
#include <string.h>
#include <stdio.h>
void main( void )
{
char string[15] = "This is a test";
/* Set not more than 4 characters of string to be *'s */
printf( "Before: %s\n", string );
_strnset( string, '*', 4 );
printf( "After: %s\n", string );
}
Output
Before: This is a test
After: **** is a test
I hope this helped.
gabby
|
|
|
|
|
I found a lot of ebook on the web. I was very intrested. I want to make a ebook like this by myself.But what should I do and How can I do this? I want to use C++,Visual C++ 6.0. Any ideas or examples?
Thank you all.
Alick
|
|
|
|
|
Alick Xiong wrote:
I want to make a ebook like this by myself.But what should I do and How can I do this?
http://www.ebookswriter.com/
http://www.tomdownload.com/home_education/e_books_literature/ebookswriter.htm
http://www.axeman.co.nz/eBook_generator.html
http://www.webpronews.com/ebusiness/smallbusiness/wpn-2-20000514MakeYourOwnEbook.html
I do not know how to do it programmatically.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I need a CCamera class which indicate the camera in Directx.
Thanks~~
buaa_chenx@hotmail.com
|
|
|
|
|
Hi
I would like to know how to log the date and time and retrieve them at later stage.
Someone books to attend a conference i want to log the exact time and date the booking whas made.
Do i use the time class and just somehow write these to a file or how do i do that.
many thanks
Education begins a gentleman,
conversation completes him
|
|
|
|
|
CTime class.
You can get the lot.
I usely get the year, month ... in integer and set them via the Format function of CString in a CString (like: yyyy/mm/dd hh/mimi/ss)
Have Fun,
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
<font style="color:blue;">#include</font> <ofstream>
<font style="color:blue;">void </font>LogMessage (LPCTSTR strMessage) {
std::ostream OutputFile(<font style="color:purple;">"C:\\MyFolder\\My_log_file.txt"</font>);
CTime CurrentTime = CTime::GetCurrentTime();
CString TimeMrk = <font style="color:purple;">"["</font> + CurrentTime.Format(<font style="color:purple;">"%H:%M:%S"</font>) + <font style="color:purple;">"] "</font>;
OutputFile << TimeMrk << strMessage; <font style="color:green;">
}
TOXCCT >>> GEII power
|
|
|
|
|
Ok, this isn't a programming question but...
Has anybody else out there had the problem of VS.NET hanging when you exit. The UI vanishes but devnet.exe remains in the background running. Practically everyone on this project has this problem.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hi Dear...
I'm trying to bind DB-Grid & ADO..please help Me..
I'm using MS-DB Grid Control & MS ADO Control ActiveX.using vc+6.0. I want to bind ADO & Grid
Thanks for help Advance..
what I'm Doing is:
int CDBGridTestDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
m_Ado.Create (NULL,WS_VISIBLE|WS_CHILD,CRect(0,0,100,20),this,IDC_ADODC1);
m_Ado.SetConnectionString("Provider=MSDASQL.1;Persist Security Info=False;Data Source=FileCheck");
//m_Ado.SetCommandType(2);
m_Ado.SetRecordSource("Select * From TBL_ITEM_TYPE");
m_Ado.Refresh();
m_Grid.Create(NULL,WS_VISIBLE|WS_CHILD,CRect(20,20,300,200),this,IDC_DBGRID1);
LPUNKNOWN pCursor=m_Ado.GetDSCCursor();
m_Grid.SetDataSource(pCursor);
m_Grid.BindProperty(0x9, &m_Ado);
m_Grid.Refresh();
return 0;
}
bye
---Sumit Kapoor---
|
|
|
|
|
Hi
As usual i recd. following message on my build output window
How to find the point of the memory leak and how to overcome it.
Thanks a lot for any suggestion.
Sandeep
Detected memory leaks! <br />
Dumping objects -><br />
strcore.cpp(118) : {1639} normal block at 0x0063B6B0, 181 bytes long.<br />
Data: < ODBC> 01 00 00 00 A8 00 00 00 A8 00 00 00 4F 44 42 43 <br />
D:\Documents and Settings\erc\Desktop\Pattern\DBManager.cpp(32) : {1633} client block at 0x0063B900, subtype 0, 100 bytes long.<br />
a CDatabase object at $0063B900, 100 bytes long<br />
D:\Documents and Settings\erc\Desktop\Pattern\PatternDoc.cpp(508) : {1535} client block at 0x0063A180, subtype 0, 88 bytes long.<br />
a CObject object at $0063A180, 88 bytes long
Leave your mark wherever you go
|
|
|
|
|
You usually find the memory leak by simply clicking on the line reported say
strcore.cpp(118)
But, if that file resides out side your project, as strcore.cpp does (its part of MFC) it wont work.
The second leak should "D:\Documents and Settings\erc\Desktop\Pattern\DBManager.cpp(32) "
Double click it and it will take you to where it was allocated.
As for the first, you have a leak via a CString somewhere.
|
|
|
|
|
ah you beat me to it... gotta type a little faster next time
|
|
|
|
|
Well they gets two answers to their Q not just one - effeciant this CP message board eh.
|
|
|
|
|
one way is dubble clicking on the line
the other reading it..
first line says:
strcore.cpp(118) etc etc etc
says that the mem was allocated on line 118 of the strcore.cpp file...(but never deallocated)
in your DBManager.cpp file line 32 you allocate memory that wasn^t deallocated
same for PatternDoc.cpp line 508.
as for in which situations that occurs... Debug!! put breakpoints and read carefull your new and delete statements!
Regards,
Davy
|
|
|
|
|
Thanks i will check it and will come up back
Leave your mark wherever you go
|
|
|
|