|
Yes, you are right. I found the answer. I just was confused by a small sample using MFC - it was looking that they are the same. But they are not.
Thanx !
Andrew
|
|
|
|
|
I guess Andrew mean to use maalloc(...) then realloc(...) no "new" shoud be used in this case.
|
|
|
|
|
you could use list<> or vector<> .
otherwise, the only way is to create a new array (using new operator, the length you like), then copy the datas you want to preserve during the "resize operation", then delete the old array...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
If possible, use stack memory instead of allocating. Then you don't have to care about size.
Don't try it, just do it!
|
|
|
|
|
Why do you want to decrease the size of the buffer? You know that there are no easy ways to manipulate the size of an array! The only way to change the size of an array is to create a complete new one with the size you want and copy all the items you can from the old array..
As other users pointed out, you can use a std::vector or some other collection class.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Something like:
LPBYTE lpBuffer2 = new BYTE[1000];
memcpy(lpBuffer2, lpBuffer, 2 * sizeof(BYTE));
delete [] lpBuffer2; The other way is to not make it too big in the first place. Lastly, even if you ended up just using 2 of the 5000 bytes, that's not a big deal in the overall scheme of things.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Strange.
Declare and array of 1000 bytes, then copy 2 bytes from the old array to the new array.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
John R. Shaw wrote:
Strange.
Indeed, but since the OP did not specify what size he wanted the array "shrunk" to, I just pulled a smaller number from the sky.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
:-DYeh; I thought about that after the fact.
Normaly I just substitute the numbers with something like new_array_size. Because it is closer to how we would actually write it.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
John R. Shaw wrote:
Normaly I just substitute the numbers with something like new_array_size. Because it is closer to how we would actually write it.
Yes, I've done that too, only to be asked shortly afterwards, "What is this new_array_size thing and how do I use it?"
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Ya first of all just like to thank everyone for helping out
cant use Cbytes for the application
and ya the buffer doesnt get filled by only 2... its filled by user specified items. So ill probably use the memcpy function that DavidCrow suggested, the buffer will be reduced by checking the amount the user filled.
Was hoping i didnt need to create another buffer array but seems like best solution is to cpy it so far.
Thanks,
Mepho
|
|
|
|
|
When using a timer SetTimer(Bla,1000,0) the count start inside the timer or it waits until it get out of the ontimer function to start the time
/\|-||\/|/\|)
|
|
|
|
|
|
hi
i want to know how to attach bmp file as attachment in email in vc. i m not using the MAPI and using the smtp server to send email.
ddd
|
|
|
|
|
Read the SMTP RFC!
Don't try it, just do it!
|
|
|
|
|
See these examples.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hello all, I decide to have a list control, where it will print out the error message in red and the information message in green.
I try to take a look on http://www.codeproject.com/listctrl/lvcustomdraw.asp
The item is colered, based on their position. However, I need a way to store, to indicate whether this item represents error or information message.
Hence, I use the following approach:
In my method which inserting the control list item:
LVITEM lvi
lvi.lParam = ERROR_MESSAGE
In my custom draw method:
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<nmlvcustomdraw*>( pNMHDR );
if ( (pLVCD->nmcd.lItemlParam) == ERROR_MESSAGE)
However, I always get something else in pLVCD->nmcd.lItemlParam
How I can pass the "error message" information to the custom draw message handler? Can anyone please advice on my implementation?
Thank you.
cheok
|
|
|
|
|
When you added the items, did you remember to set LVIF_PARAM in the mask field?
LVITEM lvi
lvi.mask = LVIF_PARAM;
lvi.lParam = ERROR_MESSAGE;
If you don't do that, it will not store your lParam for you.
|
|
|
|
|
I write a class by C++, in this class use string. For exsample:
#include "string"
using namespace std;
int exsample{}
{
string strTest;
......
}
I compile by Visual C++.NET. I get a lot of errors:
(Compile by Visual C++ 6, no Errors)
Compiling...
wmutility.cpp
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(862) : error C2143: syntax error : missing ';' before '<'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(935) : see reference to class template instantiation 'std::istreambuf_iterator<_Elem,_Traits>' being compiled
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(862) : error C2238: unexpected token(s) preceding ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(863) : error C2143: syntax error : missing ';' before '<'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(863) : error C2238: unexpected token(s) preceding ';'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2143: syntax error : missing ')' before '*'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2143: syntax error : missing ';' before '*'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2864: '_Sb' : only const static integral data members can be initialized inside a class or struct
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2501: 'std::istreambuf_iterator<_Elem,_Traits>::_Sb' : missing storage-class or type specifiers
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2143: syntax error : missing ';' before 'throw'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(866) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(871) : error C2143: syntax error : missing ')' before '&'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(871) : error C2143: syntax error : missing ';' before '&'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(871) : error C2059: syntax error : ')'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\XUTILITY(871) : error C2143: syntax error : missing ';' before 'throw'
Please help me this problemp.
Thank you very much!
|
|
|
|
|
how to enable CListctrl which is disabled at design time...
ditty grail
|
|
|
|
|
m_listControlVariable.EnableWindow(TRUE);
Jetli
Constant Thing In World Is Change.
|
|
|
|
|
Hi,
The situation:
* Using a Window with the Scroll bar capabilities.
* The mapping mode is MM_HIMETRIC.
* Just drawn a Circle in the View using OnDraw()
* Handled MouseLeft button click to perform the hit test.
I know that:
* Mouse Co-ordinates are device co-ordinate system (in pixel)
* The circle drawn is in the Logical Co ordinate
My Doubt:
The following code does't work . Why? What is wrong with me. I have tested it after converting the point into Logical point.
Code:
void CEX04CView::OnLButtonDown(UINT nFlags, CPoint point) <br />
{<br />
CClientDC dc(this);<br />
OnPrepareDC(&dc);<br />
CRect rectDevice = m_rectEllipse;<br />
dc.DPtoLP(& point);<br />
if (rectDevice.PtInRect(point)) <br />
{<br />
if (m_nColor == GRAY_BRUSH)<br />
m_nColor = WHITE_BRUSH;<br />
else<br />
m_nColor = GRAY_BRUSH;<br />
InvalidateRect(rectDevice);<br />
}<br />
CScrollView::OnLButtonDown(nFlags, point);<br />
}
Thanks in advance for the Valuable help!
|
|
|
|
|
SivaramanDhamodharan wrote:
The following code does't work
"Doesn't work" is a little vague. What or where is failing exactly?
SivaramanDhamodharan wrote:
CRect rectDevice = m_rectEllipse;
Despite its name, rectDevice is in logical coordinates, right? Since you are converting the point to logical coordinates too, the test in rectDevice.PtInRect(point) should work as expected.
However, when calling InvalidateRect , you should pass a rect in device coordinates, so I'd try doing dc.LPtoDP(rectDevice) before the call to InvalidateRect .
On another point, you are calling CScrollView::OnLButtonDown with the modified value of point ... It probably doesn't matter (I don't think the default implementation actually uses this value), but I'd fix that too.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Do not convert the point coordinates to logical coordinates.
1) If the rectDevice is in device coordinates, then no conversion is needed.
2) If the rectDevice is in logical coordinates then convert it to device coordinates instead.
InvalidateRect() does not take a rectangle in logical coordinates and niether does CScrollView::OnLButtonDown(nFlags, point).
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Hi John,
Thanks it works.
"If the rectDevice is in logical coordinates then convert it to device coordinates instead." - This helped me with the Quote "InvalidateRect() does not take a rectangle in logical coordinates"
Thanks a Lot.
The Working Code is :
CClientDC dc(this);<br />
OnPrepareDC(&dc);<br />
CRect rectDevice = m_rectEllipse;<br />
dc.LPtoDP(rectDevice);<br />
if (rectDevice.PtInRect(point)) <br />
{<br />
if (m_nColor == GRAY_BRUSH) <br />
{<br />
m_nColor = WHITE_BRUSH;<br />
}<br />
else <br />
{<br />
m_nColor = GRAY_BRUSH;<br />
}<br />
InvalidateRect(rectDevice);<br />
}
|
|
|
|