|
Handle OnCancel() (IDCANCEL) in the dialog box.
comment the base class call CDialog::OnCancel().
Regards,
Sandip.
|
|
|
|
|
|
|
I have a CListCtrl, each row has a specified color.
CListCtrl myList;
myList.SetRowColor(j, crRows.GetAt(j));
Then I need to insert some new rows, the latest is at top. Here is source code
CArray<colorref> crRows;
CArray<cstring> newData;
int nNew = newData.GetCount();
for (int i=0; i<nnew; i++="" )="" {<br="" mode="hold" />
CString txt = newData.GetAt(i);
myList.InsertItem(0, txt);
COLORREF aColor = GetRowColor(txt);
crRows.InsertAt(0, aColor)
int nCnt = myList.GetItemCount();
for (int j = 0; j<ncnt; j++="" )="" {<br="" mode="hold" /> myList.SetRowColor(j, crRows.GetAt(j));
}
}
</cstring></colorref>
I works, but because of 2 loop for, the performance speed is very slow, so I have to improve it
Does anyone know what should I do in this case??
Thanks in advance
|
|
|
|
|
Instead of for loop you can just maintain a stack so no movements required.
Does it makes sense.
Regards,
Sandip.
|
|
|
|
|
thank for your reply
but actually, i'm afraid that I don't understand how to maintain a stack??
|
|
|
|
|
why you want to maintain STL is there you just have to use it
Regards,
Sandip.
|
|
|
|
|
STL? is that Standard Template Library?
sorry SandipG, I really don't understand what you mean. Can you explain more detail,
|
|
|
|
|
Yes tataxin i mean Standard template library.
instead of using CArray you can use stack which is LIFO so you dont need to move elements down after every element added.
Regards,
Sandip.
|
|
|
|
|
Nice SandigG, that's what I want,
but I dont know how to implement this.
Can you show me more details.
|
|
|
|
|
can anyone give me more details or give me some document to read about this?
thanks in advance !!
|
|
|
|
|
Look here [^]
Few more.. [^]
[^]
Regards,
Sandip.
|
|
|
|
|
tataxin wrote: but because of 2 loop for, the performance speed is very slow, so I have to improve it
You can call SetRedraw( FALSE ) before the for loop and SetRedraw( TRUE ) in the end or use a virtual list control (http://www.codeproject.com/KB/list/virtuallist.aspx[^]).
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
do you mean that:
SetRedraw(false);
....
SetRedraw(true);
myList.RedrawWindow();
I applied it, it looks better but the actual time is the same with previous.
And I'll try virtual list control now, thks,
|
|
|
|
|
tataxin wrote: do you mean that:
Hope you are adding this above and after the "for" loop. Is it necessary to call RedrawWindow ?
tataxin wrote: I applied it, it looks better but the actual time is the same with previous.
And I'll try virtual list control now, thks, [Smile]
It's better to use virtual list if volume of data is high!
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
yes, for loops are inside, like this
SetRedraw(false);
for()
{
......
for()
{
......
}
}
SetRedraw(true);
myList.RedrawWindow();
it takes same time with the previous, in my project.
And, without RedrawWindow(), nothing is showed, myList is empty.
Ahh, the idea of virtual list is very nice. I'm reading now,
|
|
|
|
|
tataxin wrote: // get color, depends on the real data
COLORREF aColor = GetRowColor(txt);
crRows.InsertAt(0, aColor)
containers like CArray, vector are not suitable for insertion. Because those containers keep the data in contagious memory block and if you want to insert one item to middle, they've do a lot of memory moving to keep the items contagious.
Go for other insertion friendly containers such as std::list . Check there about how to use it - http://www.cplusplus.com/reference/stl/list/[^]
tataxin wrote: // get color, depends on the real data
COLORREF aColor = GetRowColor(txt);
crRows.InsertAt(0, aColor)
If you've lot of items to be added to your listctrl, better lock the control by LockWindowUpdate() then after insertion of all items, unlock by UnlockWindowUpdate() . It will avoid the flicker. Check this - http://weseetips.com/2008/04/19/how-to-update-bulk-amount-of-data-to-gui-controls-without-flicker/[^]
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
ah, thank you Jijo, I will check it now
|
|
|
|
|
hi all,
I found a solution, just use the custom draw, do not use a SetRowColor() method. So I just insert new row at top, like this
CArray crRows;
CArray newData;
int nNew = newData.GetCount();
for (int i=0; i<nnew;>
CString txt = newData.GetAt(i);
myList.InsertItem(0, txt);
COLORREF aColor = GetRowColor(txt);
crRows.InsertAt(0, aColor)
}
and then, in custom draw of the list control, I implement like this:
void CExample1Dlg::OnNMCustomdrawList2(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<nmlvcustomdraw*>( pNMHDR );
int nItem = static_cast<int> (pLVCD->nmcd.dwItemSpec);
pLVCD->clrTextBk = RGB(0, 0, 0);
*pResult = CDRF_DODEFAULT;
if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
{
COLORREF aColor = crText.GetAt(nItem);
pLVCD->clrText = aColor;
*pResult = CDRF_DODEFAULT;
}
}
</int>
that's all, and it doesn't take any time to change the color (time is almost 0)
Thank you everyone
|
|
|
|
|
Hi,
I want to create a modal dialog box instead of a messagebox in a worker thread.But when I closed the dialog box the program is gone (shutting down). What can cause to this problem? Is there a way to create a modal dialog box in a thread?
I think I shoud say that I am writing the program for Windows CE, but I think that the problem may be a general problem.
Thanks
|
|
|
|
|
Can you Paste your code ??
Regards,
Sandip.
|
|
|
|
|
Don't create UI in your worker thread, send a message to your main UI thread and create a dialog there.
use synchronisation event to wait for the dialog in your thread.
This signature was proudly tested on animals.
|
|
|
|
|
My code is like that;
UINT ComThreadEvent1(LPVOID lParam)
{
CNotepad *dlg = (CNotepad *)lParam;
while(HD != NULL)
{
::Sleep(500);
int index = dlg->events.Find(_T("\r\n"),0);
if(index == 0 )
{
dlg->thread2->ResumeThread();
dlg->GetEvent(dlg->events.Left(index));
}
}
return 0;
}
void CNotepad::GetEvent(CString event)
{
CString str;
if(event.Mid(9,2) == "C0")
{
str = "Hello";
CMessageBox mBox;
mBox.DoModal();
}
}
Here GetEvent() method is creating Modal Dialog box.How can I send a message to my main UI thread and create a dialog there?
Thanks
|
|
|
|
|
Hello. I'm trying to find something about the WebBrowser control, but have only managed to get information for MFC or C#, which doesn't help much as I'm writing a native C++ application. If you know any resources for Web Browser controls on pure WinAPI and native C++ environment, please let me know of them. Thanks.
|
|
|
|
|