-
August 12th, 2004, 12:07 PM
#1
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?
-
August 13th, 2004, 01:48 AM
#2
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....
-
August 13th, 2004, 02:58 AM
#3
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.
-
August 14th, 2004, 05:47 AM
#4
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.
-
August 14th, 2004, 07:10 AM
#5
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.
-
August 24th, 2004, 01:32 PM
#6
Re: array of buttons in VC++
got the solution:
result is there as a article here: Implementation of Array of Buttons: The Shuffle Game:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|