| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions. |
![]() |
|
|
Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
#1
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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 BancilaHome Page | Blog My CodeGuru articles My latest articles: Visual Studio 2010 series: VC++, C++ compiler, MFC Try my VSBuildStatus add-in for Visual Studio 2005, 2008 & 2010 (v1.2.0). I do not offer technical support via PM or e-mail. Please use vbBulletin codes. Please answer my multi-core and concurrency questionnaire. |
|
#4
|
||||
|
||||
|
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
|
||||
|
||||
|
Here an example for an array of 2 buttons.
In the header declare: Code:
typedef CButton CMyButton[2]; Code:
//{{AFX_DATA(CGeneralTestDlgDlg)
enum { IDD = IDD_GENERALTESTDLG_DIALOG };
CMyButton m_button;
//}}AFX_DATA
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
}
__________________
Marius BancilaHome Page | Blog My CodeGuru articles My latest articles: Visual Studio 2010 series: VC++, C++ compiler, MFC Try my VSBuildStatus add-in for Visual Studio 2005, 2008 & 2010 (v1.2.0). I do not offer technical support via PM or e-mail. Please use vbBulletin codes. Please answer my multi-core and concurrency questionnaire. |
|
#6
|
||||
|
||||
|
got the solution:
result is there as a article here: Implementation of Array of Buttons: The Shuffle Game: |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|