Click here to Skip to main content
16,004,686 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: create a dicom file Pin
Christian Graus15-Mar-05 14:59
protectorChristian Graus15-Mar-05 14:59 
QuestionHow to catch event for dynamic Controls Pin
i2c15-Mar-05 13:51
i2c15-Mar-05 13:51 
AnswerRe: How to catch event for dynamic Controls Pin
Max Santos15-Mar-05 14:17
Max Santos15-Mar-05 14:17 
GeneralRe: How to catch event for dynamic Controls Pin
i2c15-Mar-05 14:37
i2c15-Mar-05 14:37 
GeneralRe: How to catch event for dynamic Controls Pin
Maximilien15-Mar-05 15:02
Maximilien15-Mar-05 15:02 
GeneralRe: How to catch event for dynamic Controls Pin
Max Santos16-Mar-05 0:11
Max Santos16-Mar-05 0:11 
AnswerRe: How to catch event for dynamic Controls Pin
namaskaaram15-Mar-05 18:43
namaskaaram15-Mar-05 18:43 
AnswerRe: How to catch event for dynamic Controls Pin
Cedric Moonen15-Mar-05 20:23
Cedric Moonen15-Mar-05 20:23 
I think there is an easier solution instead of subclassing your own control.
If I understood well your question, you want to display X (which is only known at runtime) buttons on a dialog and create them dynamically on initialisation of your dialog. Then, when a specific button is pressed, you want to call a function.

The first thing you made is correct: this way you create dynamically the button and place it where you want. The only thing that is not really clean is that you give your own Id's. These Id's may already been used for other controls so it's not a good idea. What you need to do is reserve a range of id's in the resources.h file, something like:

#define IDC_BUTTON1     32000<br />
#define IDC_BUTTON100    32100


Then when creating your buttons:

for (int i=0;i<iNumButtons;i++)<br />
{<br />
pButton[i] = new CButton;<br />
pButton[i]->Create(_T("My button1"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(10,10,100,30), this, IDC_BUTTON1+i);<br />
pButton[i]->ShowWindow(SW_SHOW);<br />
}<br />


Of course, in the loop you'll need to change the rectangle of the button and the title...

Now, to associate a function with each of these buttons, you can make use of the ON_COMMAND_RANGE macro (in the message map):

ON_COMMAND_RANGE(IDC_BUTTON1,IDC_BUTTON100,OnButtonRange)

Take a look at the documentation to have a complete help on this macro and how to use it.

Hope this helps
GeneralRe: How to catch event for dynamic Controls Pin
i2c17-Mar-05 4:24
i2c17-Mar-05 4:24 
GeneralAuto-fill style listctrl question Pin
djtommye15-Mar-05 13:35
djtommye15-Mar-05 13:35 
GeneralAdding mfc variable .. Pin
vchedalla15-Mar-05 13:05
vchedalla15-Mar-05 13:05 
GeneralRe: Adding mfc variable .. Pin
Christian Graus15-Mar-05 13:30
protectorChristian Graus15-Mar-05 13:30 
GeneralRe: Adding mfc variable .. Pin
vchedalla15-Mar-05 13:54
vchedalla15-Mar-05 13:54 
GeneralRe: Adding mfc variable .. Pin
Christian Graus15-Mar-05 14:04
protectorChristian Graus15-Mar-05 14:04 
GeneralRe: Adding mfc variable .. Pin
vchedalla15-Mar-05 18:24
vchedalla15-Mar-05 18:24 
GeneralRe: Adding mfc variable .. Pin
Christian Graus16-Mar-05 12:20
protectorChristian Graus16-Mar-05 12:20 
QuestionWhy do my icons look like crap on NT? Pin
Ian Bowler15-Mar-05 13:02
Ian Bowler15-Mar-05 13:02 
AnswerRe: Why do my icons look like crap on NT? Pin
Steve Mayfield15-Mar-05 13:39
Steve Mayfield15-Mar-05 13:39 
GeneralRe: Why do my icons look like crap on NT? Pin
Ian Bowler15-Mar-05 13:44
Ian Bowler15-Mar-05 13:44 
GeneralRe: Why do my icons look like crap on NT? Pin
Ian Bowler15-Mar-05 13:57
Ian Bowler15-Mar-05 13:57 
GeneralRe: Why do my icons look like crap on NT? Pin
Steve Mayfield15-Mar-05 15:01
Steve Mayfield15-Mar-05 15:01 
GeneralText Font Pin
Larsson15-Mar-05 12:51
Larsson15-Mar-05 12:51 
GeneralRe: Text Font Pin
Blake Miller15-Mar-05 12:53
Blake Miller15-Mar-05 12:53 
GeneralRe: Text Font Pin
Larsson15-Mar-05 20:56
Larsson15-Mar-05 20:56 
GeneralRe: Text Font Pin
jan larsen16-Mar-05 2:28
jan larsen16-Mar-05 2:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.