CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 1999
    Location
    Salisburyl UK
    Posts
    324

    Decleration of 2d array of CStatic*

    Hi All..

    Im trying to re-develop my C++ skills and have a little project in which I want to declare, fill and create a 2d array of CStatic pointers then draw them on a dialog box in a grid pattern.

    Can anyone help me with the correct syntax please.
    Thank you for your time !

    Phill

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Decleration of 2d array of CStatic*

    What's the problem? Why pointers; why not CStatic itself? Is the grid fixed, or does it vary with the size of the dialog, etc.? Why not use a control more amenable to grids such as a CListCtrl?

  3. #3
    Join Date
    Sep 1999
    Location
    Salisburyl UK
    Posts
    324

    Re: Decleration of 2d array of CStatic*

    Hi...
    Well the grid (or table) will vary in size depending on the user. It doesnt have to be a 2d array, but I would like to access it using co ordinates i.e GetAt(3,4) etc. Having created it I just want to change the text in it and perhaps the background colour.
    Thanks anyway !
    Phill

  4. #4
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Decleration of 2d array of CStatic*

    I still don't understand. This is just simple algebra. Do you just want someone to do all the work for you, or is there some concept you don't understand?

  5. #5
    Join Date
    Sep 1999
    Location
    Salisburyl UK
    Posts
    324

    Re: Decleration of 2d array of CStatic*

    OK..
    So I have a single dimension array of 144 CStatics created like this

    SlabRect.left = 50;
    SlabRect.top = 50;
    SlabRect.right = 100;
    SlabRect.bottom = 100;

    for(i=0; i<m_NumberGrid.GetSize(); i++)
    {
    delete m_NumberGrid.ElementAt(i);
    }

    m_NumberGrid.SetSize(0);

    for(i=0; i<(m_GridXSize * m_GridYSize); i++)
    {
    m_NumberGrid.Add(new CStatic());
    ((CStatic*)m_NumberGrid.ElementAt(i))->Create(" ",WS_CHILD |WS_BORDER|WS_VISIBLE, SlabRect, this);

    }

    What I dont understand is how I can draw them in a table of 12 x12, and having done that, access each of the windows pointers using co-ordinates such as GetAt(4,5).
    Im sure it is a simple matter of algebra, but Im afraid its not as simple as it used to be for me.

  6. #6
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Decleration of 2d array of CStatic*

    for a zero based x by y array of width columns

    Code:
    element = x * width + y

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured