|
The buffer can have null values . It is a binary stream that is read as a BYTE buffer. vector is easier to manipulate.
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
You may want to use the vector member routine insert to put the data into the vector. This is at least as efficient as using std::copy, and can be more efficient.
To insert the elements into the vector (assuming that there are count elements):
vbuffer.insert( vbuffer.end(), buf, buf+count );
Using memcpy to do the copy after reserving the space will work, and may be faster, but I generally stay away from memcpy in C++ programs. It won't break anything when used with an unsigned char, but if you ever change what you are storing in the vector to a non-trivial data type, it could break.
Using insert also has the advantage of only needing a single call to do all the work.
You may want to get the book "Effective STL" by Scott Meyers. I have found this book to be very useful at learning better ways to use STL.
Best regards,
John
|
|
|
|
|
Efficiency - ooh, what a palaver. I did some timing tests on a 10 Mbyte sample and found (machine = 733MHz PIII, Windows 2000):
memcpy - 12nanoseconds/byte
std::copy with a vector output_iterator (see below) - 15nanoseconds/byte
explicit loop using vector operator[] - 18 nanoseconds/byte
std::copy with a vector insert_iterator (see below) - 27nanoseconds/byte
Given the closeness of the timings, I'd take the std::copy over memcpy anytime, as (IMHO) it's more correct when populating a vector...anyway, thats just my opinion, so hey, whatever.
(sample code for vector output_iterator:
unsigned char* buffer;
std::vector<unsigned chat> v;
v.resize(whatever the required size is);
std::copy(buffer, buffer + whatever the required size is, v);
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
How can I get the 8.3 format of a long filename ?
Thks in advance!
Appstmd
|
|
|
|
|
|
hi all,
could anybody give a hint on how to retrieve the cursor coordinate (CPoint) in a CListCtrl ? prog. running on Win CE 3.0
i want to display a pop-up menu where the user click somewhere in the List, to do so i need to get the cursor coord.
i've triied :
void C..::OnLButtonUp(UINT nFlags, CPoint point) // it only works in the View, not inside the control
void C..::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) //here there is no direct way to get the position..
any idea ?
thanx
Fred
|
|
|
|
|
Put this in your OnClickList or what ever its called.
CPoint point;
GetCursorPos( &point );
m_listCtrl.ScreenToClient( &point ); Then display your pop-up menu at point
-Raffi
|
|
|
|
|
Oops, just realize that you dont have to put the ScreenToClient part in there.
I should be:
CPoint point;
GetCursorPos( &point ); And display your pop-up menu at point .
-Raffi
|
|
|
|
|
Try:
NM_LISTVIEW *plv = ( NM_LISTVIEW * )pNMHDR;
UINT uflag ;
m_wndListCtrl.HitTest( plv->ptAction , &uflag );
if( uflag == LVHT_ONITEMICON )
....
Here plv->ptAction is the cursor coordinate and you don't need to use
ScreentToClient()
Cheers
|
|
|
|
|
thanx guys !
just a simple GetCursorPos() do it !
@+
Fred
|
|
|
|
|
I want to know how can i sense number pressed by caller using tapi 3.0 in VC.
|
|
|
|
|
Have a look at ITDigitDetectionEvent in MSDN or on the platform SDK.
Michael
Logic, my dear Zoe, merely enables one to be wrong with authority. - The Doctor
|
|
|
|
|
Hio.. I have 2 win98 machines that are having major toolbar problems.. I am using the following little function to switch out the toolbar:
void CMainFrame::SetToolbarDefault()
{
m_wndToolBar.SetButtons(NULL, 3);
m_wndToolBar.SetButtonInfo(0, ID_OPTIONS, TBBS_BUTTON|BTNS_SHOWTEXT, 0);
m_wndToolBar.SetButtonInfo(1, ID_APP_ABOUT, TBBS_BUTTON|BTNS_SHOWTEXT, 2);
m_wndToolBar.SetButtonInfo(2, ID_EXITBTN,TBBS_BUTTON|BTNS_SHOWTEXT, 3);
m_wndToolBar.SetButtonText(0,"Options");
m_wndToolBar.SetButtonText(1,"About");
m_wndToolBar.SetButtonText(2,"Exit");
m_wndToolBar.Invalidate(TRUE);
m_wndToolBar.UpdateWindow();
Invalidate(TRUE);
UpdateWindow();
} i have another function which is basicly the same which switches the toolbar to a different set of menus.. both have the following problem:
as soon as the SetToolbarDefault() gets called the menus become grey.. and they dont ever redraw.. if you move the window around, the area where the toolbar should be is all distorted, showing other things behind where the toolbar should be.. its like it never gets redrawn again, ever, until i exit the program and re-enter..
plz keep in mind that these buttons do have handlers, and they are not just greyed out as if they didnt have a message handler.. also these menus work fine under win 2000.. plz tell me someone has an idea on this one?
-dz
|
|
|
|
|
Hi, i want to let me richEdit control scroll to the very bottom whenever new text is added. Most examples here use LineScroll(1) to scroll down by 1 line whenever text is added but when your richedit has the style WS_HSCROLL turned off, then whenever the text is longer than the window width it'll need to scroll down more than one line...
I can't just do LineScroll(5) or anything like that either cause then it'll scroll down till the last line is at the top of the control, and thats not pretty either now is it..
Any ideas?
thanks.
P.S.: LineScroll doesn't even seem to work under WIN2000, i'd like to have something that works under WIN2000/WINXP as well
Kuniva
--------------------------------------------
|
|
|
|
|
I found this works:
// Give it focus
theApp.m_hwndPWOutputWindow->GetRichEditCtrl().StreamIn(SF_TEXT | SFF_SELECTION, es);
// Send some keys to cause it to move right to the bottom <-,->
theApp.m_hwndPWOutputWindow->SendMessage(WM_KEYDOWN,37,0);
theApp.m_hwndPWOutputWindow->SendMessage(WM_KEYDOWN,39,0);
if(!gbTalk)
{
theApp.m_hwndPWOutputWindow->SetFocus();
theApp.m_hwndPWOutputWindow->UpdateWindow();
}
theApp.m_hwndPWOutputWindow->UpdateWindow();
|
|
|
|
|
umm.. thanks for replying but i don't fully understand a few things here:
whats m_hwndPWOutputWindow?
whats es?
whats gbTalk for?
If you'd like to clear this up i'd be very thankful..
Kuniva
--------------------------------------------
|
|
|
|
|
i'm beginner
I search source code for display a jpeg in a dialog application with visual c++.
I have a list box with path file (c:\ttest.jpeg) and on click i search source code to show this image in a control 300*200 pixels.
Thanks a lot for your response.
please send me an email at noudard@wanadoo.Fr
nico
|
|
|
|
|
Your in luck a project of this type has receintly been submitted to code project. You can find it at http://www.codeproject.com/audio/cximagemng.asp. It is a bit much to go through but boy the things you can learn from this source.
|
|
|
|
|
if what I gave you in the first post is more than you were looking for try something a little simpler.
Like this
LVBKIMAGE lv;
ZeroMemory(&lv, sizeof(lv));
lv.ulFlags = LVBKIF_SOURCE_URL | LVBKIF_STYLE_NORMAL;
lv.pszImage = szFileName;
lv.cchImageMax = lstrlen(szFileName);
ListView_SetBkImage(hndLVCtrl, &lv);
|
|
|
|
|
2: Steven Szelei
You are right.
But what's wrong with my code, It seems be same as yours
It's me, code_cold
|
|
|
|
|
Could you told me what's wrong with my code ?
It's me, code_cold
|
|
|
|
|
I keep getting this message every time I double click an object to add code for it.
Any ideas on what may cause this or how I can fix it?
Thanks
|
|
|
|
|
are you trying to add a message handler, or a variable? (this is in the resource editor right?)
my guess is its caused by VS6 not being able to interpret your .cpp file..
Modified when adding variables:
void COptions1::DoDataExchange(CDataExchange* pDX)
{
CSAPrefsSubDlg::DoDataExchange(pDX);
DDX_Text(pDX, IDC_DATAPATH, m_strDataPath);
} Modified when adding message handlers:
BEGIN_MESSAGE_MAP(COptions1, CSAPrefsSubDlg)
ON_BN_CLICKED(IDC_BROWSEBTN, OnBrowsebtn)
END_MESSAGE_MAP()
if you took out or modified the AFX_MSG_MAP or AFX_DATA_MAP parts then VS6 wont be able to figure out where to put the code.. you can add it manually if you look at examples of how the class wizard has been doing it for you..
hope that is what you were looking for!
-dz
|
|
|
|
|
I want my MFC MDI CFormView based project to start up with the view (form)already populated with data (In my case I'll have pictures in a picture box)? Thank you,
ns
|
|
|
|
|
Sure can. Overload OnInitialUpdate().
|
|
|
|