|
Dear all
in C language we can create dynamic multi dimentional arrays by using malloc operator.
But how we can create multidimentional arrays by using new operator in C++.
Please note that length of each dimention is dynamic and is not apparant in compile time.
Regards
Mahdi
|
|
|
|
|
You can do that in C++.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
A code example for a two dimensional array:
int** pArray;
pArray = new int*[10];
for (int i=0; i<10; i++)
pArray[i] = new int[10];
This will create a 10 X 10 array.
|
|
|
|
|
For instance:
int ** p;
int n=3;
int m=4;
p = new int *[n];
p[0]= new int [5];
p[1] = new int [m];
p[2] = new int [10];
p[0][1]=13;
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
what about std::vector<std::vector<YourType> >
|
|
|
|
|
|
I am trying to develop an application which will be able to convert several
European currencies to Euros and back, using visual C++
I need to convert 3 currencies to euros and theother way.
I also need to connecting it to a database where currency data
from at least 10 European countries will be stored.
The user must be able to choose to convert any of the
currencies included in the database, or add more currencies of his
choice, using application’s database link.
Can you help me out ?
|
|
|
|
|
cmvr wrote: I am trying to develop an application which will be able to convert several
European currencies to Euros and back, using visual C++
Not a daunting task.
Please make, at least an attempt, then post specific questions whenever you find yoursef in troubles.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
|
Programm3r wrote: But as far as I can see there is no semicolon missing !!
There is. To complete class defintion, semicolon must be there.
So class CMyClass {} is not valid statement, its valid when you give semicolon.
Prasad
MS MVP - VC++
|
|
|
|
|
prasad_som wrote: So class CMyClass {} is not valid statement, its valid when you give semicolon
I am well aware of that fact, I was trying to say that I did put a semicolon after the class definition.
But I include this file shlobj.h and then I receive the error, when I comment this file out the project builds successfully.
Why is this ???
Many Thanks.
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
Oh !
Can you tell me include sequnce of headers. I tried to reproduce the problem, but no success.
Prasad
MS MVP - VC++
|
|
|
|
|
Hi,
I have property sheet wizard application and I am repaining its title bar and creating new minimize and close button on title bar. The following codes are doing things ok. but when i try to right click on task bar button( applications task bar button - close/minimize application from system menu) minimize and close button is not repinted as expected. The codes are
void CSamplePaintSheet::OnNcPaint()
{
CWindowDC dc( this );
ModifyStyle(NULL,WS_SYSMENU|WS_MINIMIZEBOX);
Default();
ReDrawCaptionBar( &dc );
ReleaseDC( &dc );
}
BOOL CSamplePaintSheet::OnNcActivate( BOOL bActivate )
{
OnNcPaint();
return TRUE;
}
void CSamplePaintSheet::ReDrawCaptionBar(CDC *pDC )
{
CRect rc;
this->GetWindowRect( rc );
ScreenToClient( rc );
rcCap = rc;
rcCap.bottom = ::GetSystemMetrics( SM_CYCAPTION ) +
::GetSystemMetrics( SM_CYFIXEDFRAME );
rcCap.right += ::GetSystemMetrics( SM_CXFIXEDFRAME );
CString szTitle(_T("Sample Paint Application"));
SetWindowTextW( szTitle );
CBrush brSolid( CLR_GRAY );
pDC->FillRect( &rcCap, &brSolid );
CRect rcLeft( rc );
rcLeft.top = rcCap.bottom;
rcLeft.right = ::GetSystemMetrics( SM_CXFIXEDFRAME );
rcLeft.bottom = rc.Height();
pDC->FillRect( &rcLeft, &brSolid );
CRect rcRight( rc );
rcRight.left = rcCap.right - ::GetSystemMetrics( SM_CXFIXEDFRAME );
rcRight.top = rcLeft.top;
rcRight.right = rcCap.right;
rcRight.bottom = rcLeft.bottom;
pDC->FillRect( &rcRight, &brSolid );
CRect rcBottom( rc );
rcBottom.left = rcLeft.left;
rcBottom.top = rcRight.bottom - ::GetSystemMetrics(SM_CYFIXEDFRAME) -
nBottomBorderHeight;
rcBottom.right = rc.Width();
rcBottom.bottom = rcRight.bottom;
pDC->FillRect( &rcBottom, &brSolid );
CSize sizeText = pDC->GetTextExtent( szTitle );
int nCy = HIWORD( ::GetDialogBaseUnits() );
rcText = rcCap;
rcText.left = ::GetSystemMetrics( SM_CYFIXEDFRAME );
rcText.right = rcText.left + ( sizeText.cx );
rcText.top = (rcCap.bottom - (nCy + 1))/2;
rcText.bottom = rcText.top + nCy + 1;
pDC->SetBkMode( TRANSPARENT );
pDC->DrawText( szTitle, rcText, DT_LEFT | DT_SINGLELINE );
rcBtClose = rc;
rcBtClose.top = ::GetSystemMetrics( SM_CYFIXEDFRAME )+ 3;
rcBtClose.right = rcBottom.right - ::GetSystemMetrics( SM_CXFIXEDFRAME );
rcBtClose.left = rcBtClose.right - ::GetSystemMetrics( SM_CXSIZE ) + 8;
rcBtClose.bottom = ::GetSystemMetrics( SM_CYSIZE )- 3;
if( bBtClose )
{
pDC->DrawFrameControl
(rcBtClose,DFC_CAPTION,DFCS_CAPTIONCLOSE|DFCS_HOT );
}
else
{
pDC->DrawFrameControl
(rcBtClose,DFC_CAPTION,DFCS_CAPTIONCLOSE|DFCS_INACTIVE );
}
rcBtMin = rcBtClose;
rcBtMin.left = rcBtClose.left - rcBtClose.Width() -
::GetSystemMetrics( SM_CXFIXEDFRAME );
rcBtMin.right = rcBtMin.left + rcBtClose.Width();
pDC->DrawFrameControl(rcBtMin,DFC_CAPTION,DFCS_CAPTIONMIN|DFCS_HOT );
}
void CSamplePaintSheet::OnSysCommand( UINT nID, LPARAM lParam )
{
CDC *pDC = GetWindowDC();
ReDrawCaptionBar( pDC );
ReleaseDC( pDC );
CDialog::OnSysCommand( nID, lParam );
}
|
|
|
|
|
Re draw it in WM_ACTIVATE
|
|
|
|
|
i have a problem with two images.suppose,3 circles comes one inside the other.like that,2 images are there.(image1 has 3 circles,and image2 has 3 circles one inside the other.)i want to compare the two images and to find whether the first image is same as that of second??
|
|
|
|
|
Refer this[^] article by PJ Arends .
Prasad
MS MVP - VC++
|
|
|
|
|
if you want to compare two images a way is that isnt very good you can use of CImage class you make two loops for height and width and use of GetPixel for check color of pixel on each images but this way is a problem and its slow but I think on the codeproject is other ways.
|
|
|
|
|
Hi,
Can you help me how to "synchronize" .NET DateTime.Tick and C++ time (CTime, LPSYSTEMTIME, t_time doesn't matter which one) . I need to write certain time to file (using .NET C# -> write Ticks value) and than read it in C++ == create time structure (constructor with !same! ticks or something...) . I'm using old VS 6 C++ !!!
thanx
|
|
|
|
|
Please help me. I'm looking for DFP and Newton optimization methods. They may be written in C, Java or C++. And I don't want Newton Raphson method.
|
|
|
|
|
Hi
I am trying the change the default font of the menu.
I have used code from http://www.codeproject.com/menu/menuch.asp.
In the App file,there are AppendMenu(),DrawItem() overriden functions.
Under drawItem(),I have written the code to change the default
font of the Menu.I have declared objects like m_FileMenu, m_EditMenu
of type App class in the Mainframe header file and through these variables
I have called AppendMenu() from within the constructor of Mainframe class.
Like m_FileMenu.CreatePopupMenu();
m_FileMenu.AppendMenu(MF_ENABLED,ID_MYFILE_NEW,"&New\tCtrl+N");
m_FileMenu.AppendMenu(MF_ENABLED,ID_FILE_OPEN,"&Open\tCtrl+O");
Similarly, I have called AppendMenu()for m_EditMenu object also.
Next,Under CreateMenu()which has been called from OnCreate handler,I have
taken the pointer of CMenu through GetMenu(), and all the default items of
menu have been removed through RemoveMenu().
Like pMenu->RemoveMenu(0,MF_BYPOSITION);
Then,through that CMenu pointer,I have called InsertMenu() through which all
the appended items are getting inserted in the menu.
Like
pMenu->InsertMenu(0,MF_BYPOSITION|MF_POPUP,
(UINT)m_FileMenu.m_hMenu,"&File");
pMenu->InsertMenu(1,MF_BYPOSITION|MF_POPUP,
(UINT)m_EditMenu.m_hMenu,"&Edit");
Now,the problem is that although the font of all the submenu items are getting changed as per my given font in the drawitem(), but the font of menu items like "File" and "Edit" are not getting changed.
If possible Can you please tell me what could be the reason behind it and what should I do to solve it?
-- modified at 5:23 Monday 23rd April, 2007
With Regards
Neeraj Sinha
Netstudio
Pune
|
|
|
|
|
Menu will be drawn as per the system font settings.
You can try with Owner-Drawn menu
Search CP to find more articles on it.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Thanks for your reply
I have tried with Owner-Drawn menu.The menu items font didn't change.Only the submenu items font got changed.I have used code from the CP itself:
http://www.codeproject.com/menu/menuch.asp.
With Regards
Neeraj Sinha
Netstudio
Pune
|
|
|
|
|
I made one dialog box in VS2005(mfc) it is not running in Vist(OS) system, is there any way to run mfc application in vista?
|
|
|
|
|
Please refer this[^].
Regards,
Paresh.
|
|
|
|
|
Dear sir
Thank you for your replay
But i am getting earror is "application has filed to start because its side-by-side configaration is incorrect................."
I am checking my (MFC)application in "Vist home basic"
|
|
|
|