CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2004
    Location
    Bangalore,karnataka,India
    Posts
    13

    Question array of buttons in VC++

    i tried making an array of buttons when programming using class vizard. i did it using image button and also using direct coding. in VB it is possible bu copying the buttons. i have written a common message handler for btton's On click operation. but i need to reffer it by common name. is it possible?

  2. #2
    Join Date
    Jun 2004
    Posts
    7

    Re: Array of buttons in VC++

    I don;t understand what you mean by common names but it is very easy if you keep a member integer vairable in your button class and in the OnClick handler put a check on that integer variable you can determine which button was clicked....

  3. #3
    cilu's Avatar
    cilu is offline Moderator/Reviewer/MS MVP Power Poster
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,349
    What exactly are you trying to do? You want to have several buttons having the same handler? You can use ON_COMMAND_RANGE macro to map a range of command IDs to the same handler.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Mar 2004
    Location
    Bangalore,karnataka,India
    Posts
    13

    Arrow I need to control set of buttons in aloop

    I have written a common handler for the set of buttons. But, i need to address them like

    m_Button[i][j].SetWindowText("XXXX");
    in a loop. i did it by changing the declaration of button as CButton m_Button[5][5];
    but after that i could not go to class-wizard.

  5. #5
    cilu's Avatar
    cilu is offline Moderator/Reviewer/MS MVP Power Poster
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,349
    Here an example for an array of 2 buttons.

    In the header declare:
    Code:
    typedef CButton CMyButton[2];
    and use it in AFX_DATA
    Code:
    //{{AFX_DATA(CGeneralTestDlgDlg)
    enum { IDD = IDD_GENERALTESTDLG_DIALOG };
    CMyButton  m_button;
    //}}AFX_DATA
    In the source file write the DoDataExchange like this:
    Code:
    void CGeneralTestDlgDlg::DoDataExchange(CDataExchange* pDX)
    {
      CButton &but1 = m_button[0];
      CButton &but2 = m_button[1];
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CGeneralTestDlgDlg)
      DDX_Control(pDX, IDC_BUTTON2, but1);
      DDX_Control(pDX, IDC_BUTTON1, but2);
      //}}AFX_DATA_MAP
    }
    Now you will be able to use the class wizzard and have buttons array.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  6. #6
    Join Date
    Mar 2004
    Location
    Bangalore,karnataka,India
    Posts
    13

    Lightbulb Re: array of buttons in VC++

    got the solution:
    result is there as a article here: Implementation of Array of Buttons: The Shuffle Game:

Bookmarks

Posting Permissions

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



HTML5 Development Center

Click Here to Expand Forum to Full Width