Board index » Visual Studio » How to Add OnClick Message for a dynamic control

How to Add OnClick Message for a dynamic control

Visual Studio78
Hi Group



If i had included a static control via resource , i would need to add the

OnClick message handler via Class Wizard. So when the user clicks that

control the OnClick function would be called.



But if i had created the control dynamically during runtime, how can i add

such message handler.



Regards


-
 

Re:How to Add OnClick Message for a dynamic control

Quote
If i had included a static control via resource , i would need to add the

OnClick message handler via Class Wizard. So when the user clicks that

control the OnClick function would be called.



But if i had created the control dynamically during runtime, how can i add

such message handler.



When you create the control, you'll usually know the command ID you

give it. In such circumstances you can usually add the message handler

directly as if the Wizard did it (see what the Wizard does and

duplicate it), or you may have a range of command ID values to handle,

in which case you can use ON_COMMAND_RANGE.



Dave

-

Re:How to Add OnClick Message for a dynamic control

Actually i am creating an array of CStatic controls.



And after i arrange them on the dialog i want call a click function each

time the user clicks on that control.

Quote
When you create the control, you'll usually know the command ID you

give it. In such circumstances you can usually add the message handler

But i am not creating it from resorce so how can i assign command ID to it ?



in the header file

CStatic ctl_gridBox[9][9];





In the cpp file



//creating the control

for(int col=0;col<9;col++)

for(int row=0;row<9;row++)

ctl_gridBox[col][row].Create(_T("

"),WS_VISIBLE,GridBox,this);//|SS_CENTER|WS_CHILD



//Positioning the control

for(int col=0;col<9;col++)

for(int row=0;row<9;row++)

{

.....





ctl_gridBox[col][row].SetWindowPos(this,GridBox.left,GridBox.right,GridBox.Width(),GridBox.Height(),SWP_FRAMECHANGED

);

ctl_gridBox[col][row].SetBitmap(mGridBmp);

ctl_gridBox[col][row].GetDC()->DrawEdge(GridBox,EDGE_BUMP,BF_RECT);

ctl_gridBox[col][row].ShowWindow(SW_SHOW);



..

}



Now the control appears on the dialog

Now i want to call a function for each control when the uses clicks on them

.









-

Re:How to Add OnClick Message for a dynamic control

As mentioned by Dave, you need to specify ID for each of the CStatics

that you are creating. Your code is not doing it. Its the last

parameter in Create method(after parent). You are currently using the

default value.



---

Ajay





beauwlf wrote:

Quote
Actually i am creating an array of CStatic controls.



And after i arrange them on the dialog i want call a click function each

time the user clicks on that control.

>When you create the control, you'll usually know the command ID you

>give it. In such circumstances you can usually add the message handler

But i am not creating it from resorce so how can i assign command ID to it ?



in the header file

CStatic ctl_gridBox[9][9];





In the cpp file



//creating the control

for(int col=0;col<9;col++)

for(int row=0;row<9;row++)

ctl_gridBox[col][row].Create(_T("

"),WS_VISIBLE,GridBox,this);//|SS_CENTER|WS_CHILD



//Positioning the control

for(int col=0;col<9;col++)

for(int row=0;row<9;row++)

{

.....





ctl_gridBox[col][row].SetWindowPos(this,GridBox.left,GridBox.right,GridBox.Width(),GridBox.Height(),SWP_FRAMECHANGED

);

ctl_gridBox[col][row].SetBitmap(mGridBmp);

ctl_gridBox[col][row].GetDC()->DrawEdge(GridBox,EDGE_BUMP,BF_RECT);

ctl_gridBox[col][row].ShowWindow(SW_SHOW);



..

}



Now the control appears on the dialog

Now i want to call a function for each control when the uses clicks on them

.



-

Re:How to Add OnClick Message for a dynamic control

Could you use this sort of thing?



www.codeproject.com/staticctrl/cmyhyperlink.asp">www.codeproject.com/staticctrl/cmyhyperlink.asp



Tom



"beauwlf" <beauwlf@fruggle.com>wrote in message

Quote
Actually i am creating an array of CStatic controls.



And after i arrange them on the dialog i want call a click function each

time the user clicks on that control.

>When you create the control, you'll usually know the command ID you

>give it. In such circumstances you can usually add the message handler

But i am not creating it from resorce so how can i assign command ID to it

?



in the header file

CStatic ctl_gridBox[9][9];





In the cpp file



//creating the control

for(int col=0;col<9;col++)

for(int row=0;row<9;row++)

ctl_gridBox[col][row].Create(_T("

"),WS_VISIBLE,GridBox,this);//|SS_CENTER|WS_CHILD



//Positioning the control

for(int col=0;col<9;col++)

for(int row=0;row<9;row++)

{

.....







ctl_gridBox[col][row].SetWindowPos(this,GridBox.left,GridBox.right,GridBox.Width(),GridBox.Height(),SWP_FRAMECHANGED

);

ctl_gridBox[col][row].SetBitmap(mGridBmp);

ctl_gridBox[col][row].GetDC()->DrawEdge(GridBox,EDGE_BUMP,BF_RECT);

ctl_gridBox[col][row].ShowWindow(SW_SHOW);



..

}



Now the control appears on the dialog

Now i want to call a function for each control when the uses clicks on

them .













-