|
I need to copy an array, but I don't know the size until after the program has parsed a file.
I created a pointer to the new array like this:
<br />
double *data_ptr = new double[]; <br />
I then have a counter that counts as the file is parsed.
I call this counter int num_signals;
Once the file is parsed I nee dto resize the array with the size of num_signals.
<br />
double *data_ptr = new double[num_signals]; <br />
How can I do this?
thanks,
sj
|
|
|
|
|
Why not use an stl class like vector? vector will handle all the details of this for you.
John
|
|
|
|
|
Unless you are using data_ptr during the parsing of the file, don't initialize it until afterwards.
|
|
|
|
|
I have been trying for a week now to create a window region for a CButton. The region is created from a bitmap and is not rectangular. I know the region is created ok because when i click the part of the bitmap that is not transparent i get the button clicked event. I do not recieve the event when clicking outside of the non-transparent area. My problem is that no matter what i do the DrawItem function which paints the bitmap always fills a full rectangle. This displays the transparent, and non-transparent part of the button. I have tried using SetClipRgn but that has not worked. This same code creates a regioned dialog and paints that correctly. Does it matter that my button is created dynamically? Why does a bitblt using the buttons Client Rect fill the whole rectangle and not just the region i specified?????
Thanks
|
|
|
|
|
Would have to see your code to provide any comments.
onwards and upwards...
|
|
|
|
|
Here is the code
BOOL CSkinButton::CreateSkinButton(int nID, CWnd *pWnd)
{
if( pWnd == NULL )
return FALSE;
m_nID = nID;
m_pSkinDrawing = new CSkinDrawing;
if( m_bSkinned )
{
m_hBack = (HBITMAP)LoadImage(NULL,m_strBackImage,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE );
m_hMask = (HBITMAP)LoadImage(NULL,m_strMaskImage,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE );
m_hHover = (HBITMAP)LoadImage(NULL,m_strHoverImage,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE );
m_hDown = (HBITMAP)LoadImage(NULL,m_strDownImage,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE );
if( (m_hBack == NULL) || (m_hMask == NULL) || (m_hHover == NULL) || (m_hDown == NULL) )
return FALSE;
// Get the main window region using background bitmap
m_hRgn = m_pSkinDrawing->BitmapToRegion(m_hMask,m_clrMaskColor);
}
if( !Create(m_strCaption,BS_OWNERDRAW,CRect(0,0,0,0),pWnd,m_nID) )
return FALSE;
SetWindowPos(NULL,m_ptTopLeft.x,m_ptTopLeft.y,m_nWidth,m_nHeight,SWP_SHOWWINDOW);
return TRUE;
}
void CSkinButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
UINT uStyle = lpDrawItemStruct->itemState;
CDC *pDC = NULL;
CRect rcMain;
pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
if( !m_bSkinned )
{
rcMain.CopyRect(&lpDrawItemStruct->rcItem);
m_pSkinDrawing->DrawFilledRect(pDC,rcMain,m_clrBackColor);
m_pSkinDrawing->DrawFrame(pDC,rcMain,1);
// Draw the button and label using caption
m_pSkinDrawing->DrawButtonText(pDC,m_strCaption,rcMain,m_clrForeColor);
// Now, depending upon the state, redraw the button (down image) if it is selected,
// place a focus rectangle on it, or redisplay the caption if it is disabled
if( uStyle & ODS_FOCUS )
{
if( uStyle & ODS_SELECTED )
{
m_pSkinDrawing->DrawFilledRect(pDC,rcMain,m_clrBackColor);
m_pSkinDrawing->DrawFrame(pDC,rcMain,-2);
m_pSkinDrawing->DrawButtonText(pDC,m_strCaption,rcMain,m_clrForeColor);
}
}
else if(uStyle & ODS_DISABLED)
{
m_pSkinDrawing->DrawButtonText(pDC,m_strCaption,rcMain,m_clrForeColor);
}
}
else
{
CDC *pMemDC = NULL;
HRGN hRgn;
HBRUSH hBrush;
CBitmap *pBitmap = NULL;
hRgn = CreateRectRgn(0,0,0,0);
GetClientRect(&rcMain);
GetWindowRgn(hRgn);
pMemDC = new CDC;
pMemDC->CreateCompatibleDC(pDC);
if( uStyle & ODS_SELECTED )
pBitmap = (CBitmap *)pMemDC->SelectObject(m_hDown);
else
pBitmap = (CBitmap *)pMemDC->SelectObject(m_hBack);
hBrush = CreateSolidBrush(m_clrMaskColor);
FillSolidRect(pMemDC->GetSafeHdc(),rcMain,RGB(0,0,0));
FillRgn(pMemDC->GetSafeHdc(),hRgn,hBrush);
::SelectClipRgn(pMemDC->GetSafeHdc(),hRgn);
pDC->BitBlt(0,0,rcMain.Width(),rcMain.Height(),pMemDC,0,0,SRCCOPY);
::SelectClipRgn(pMemDC->GetSafeHdc(),NULL);
dcMain.SelectObject(pBitmap);
DeleteObject(hRgn);
DeleteObject(hBrush);
}
}
void CSkinButton::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
ModifyStyle(0,BS_OWNERDRAW|BS_PUSHBUTTON);
CButton::PreSubclassWindow();
}
int CSkinButton::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CButton::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
if( m_bSkinned )
SetWindowRgn(m_hRgn,TRUE);
return 0;
}
|
|
|
|
|
You don't seem to be setting a clipping region to the pDC that you are bitblt'ing the memdc to. Could that be an issue? Also, you are drawing on the memdc before setting a clipping region with your FillSolidRect function.
onwards and upwards...
|
|
|
|
|
Hi, I tried to read lines from rich edit control and display in the debug window with the following code. If I set i=1 in the for loop, this program won't crash and display every line other then the first line. However, when I set i=0 as below, it will crash and have memory leak problem. Can someone please tell me what's going on? Thank you.
int i, nLineLength, nLineCount;
CString strText;
nLineCount = m_redit.GetLineCount();
for (i=0;i < nLineCount ;i++)
{
nLineLength = m_redit.LineLength(i);
m_redit.GetLine(i, strText.GetBuffer(nLineLength));
TRACE (strText);
strText.ReleaseBuffer(nLineLength);
}
|
|
|
|
|
skinnyreptile wrote:
TRACE (strText);
strText.ReleaseBuffer(nLineLength);
Try switching these two statements.
|
|
|
|
|
Even without trace statment, it's still not working.
|
|
|
|
|
Read the documentation carefully. Note the requirement that the first word of the buffer must specify the maximum number of bytes that can be copied into the buffer. You need something like:
int i, nLineLength, nLineCount;
char szBuffer[64];
nLineCount = m_edit.GetLineCount();
for (i=0;i < nLineCount ;i++)
{
nLineLength = m_edit.LineLength(i);
m_edit.GetLine(i, szBuffer, nLineLength);
szBuffer[nLineLength] = '\0';
TRACE("%s\n", szBuffer);
}
or
int i, nLineLength, nLineCount;
char szBuffer[64];
nLineCount = m_edit.GetLineCount();
for (i=0;i < nLineCount ;i++)
{
nLineLength = m_edit.LineLength(i);
*((int *) szBuffer) = nLineLength;
m_edit.GetLine(i, szBuffer);
szBuffer[nLineLength] = '\0';
TRACE("%s\n", szBuffer);
}
|
|
|
|
|
Where does it crash? On what line?
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
On line 0. If the for loop is start at line 1, it won't crash.
|
|
|
|
|
I haven't tried, but...
nLineCount = m_redit.GetLineCount();
for (i=0; i < nLineCount - 1; i++)
{
nLineLength = m_redit.LineLength(i);
m_redit.GetLine(i, strText.GetBuffer(nLineLength));
TRACE (strText);
strText.ReleaseBuffer(nLineLength);
}
Do this works?
|
|
|
|
|
I tried the following code with display line 0 only when nLineCount > 1. THe code still crash.
if (nLineCount > 1)
{
nLineLength = m_redit.LineLength(0);
m_redit.GetLine(0, strText.GetBuffer(nLineLength));
TRACE (strText);
strText.ReleaseBuffer(nLineLength);
}
|
|
|
|
|
The function LineLength will return the ONLY the number of characters for the given line not including the carriage-return character. According MSDN the function LineLength actually calls the message EM_LINELENGTH and in the MSDN this message states that It does not include the carriage-return character at the end of the line. Also you should account for the NULL character at the end of the string when assigning the length of the buffer.
This code works for me:
<code>
int i, nLineLength, nLineCount;
CString strText;
nLineCount = m_redit.GetLineCount();
for (i=0;i < nLineCount ;i++)
{
nLineLength = m_redit.LineLength(i);
int nActualCharactersReturned = m_redit.GetLine(i, strText.GetBuffer(nLineLength + 2));
strText.ReleaseBuffer(nActualCharactersReturned);
TRACE (strText);
}
</code>
Kelly Herald
Software Developer
MPC
|
|
|
|
|
Thank you for all the help, guys!
|
|
|
|
|
How do you "auto-scale" data points on a graph?
the data will be received at a constant frequency.
I will be receiving data from a CAN/bluetooth gateway on a vehicle.
How do I go about graphing and receiving those data points and putting them on both a line and bar graph?
Thanks.
|
|
|
|
|
This is a very generic question, but I'll give it a try:
1. Separate the data from the viewing of the same data...
2. use dynamic memory assignment if you don't know the amount of data that you'll need.
3. think about how many history do you need to maintain.
4. create a control derived from a CStatic called CGraph.
5. Override the OnPaint function of that control in order to draw the axis, the captions and the labels.
6. Draw each point depending on a scale factor.
7. if the graph needs to be scrolled, think about a scrolling bar... (think about drawing the part needed ni order to avoid to collapse too much the CPU)
Hope this helps...
|
|
|
|
|
I think you need to enable the "toolwindow" style (i.e. its equivalent in C#).
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hi !
I have a very basic question about C++ :
I want to allocate on the heap a two-dimensionnal array. I tried to do this :
int* pArray=new int[x][y];
but of course it didn't work, so I did that :
int* pArray=new int[x*y];
and each time I need to acces my array, I calculate the x/y position. It works, but still, I'm curious : is it possible to allocate memory in such a way that I can then use the usual notation for a multidimensionnal array : Array[x][y]=z.
Thank you for your help !
Jerome
|
|
|
|
|
int **pArray = new int*[x];
for(int i=0; i<x; i++)
pArray[x] = new int[y]; This will let you use pArray[x][y] = z . To deallocate this array, do this:
for(int i=0; i<x; i++)
delete [] pArray[x];
delete [] pArray; Hope this helps,
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Great ! Thanks Ryan !
Jerome
|
|
|
|
|
You're welcome
BTW. That was one heck of a speedy reply
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Hi everyone!
I have to get the text from a ms word document (.doc) and save the text to a text file (.txt).
Have any of you guys done this? Or can you give me a hint where to start?
majo
|
|
|
|
|