Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why do the wizards deny to help me?

Status
Not open for further replies.

josecarlo

Programmer
Aug 22, 2000
30
PE

Hi,

When my controls are created in run time, for example after clicking a button, their event handlers must be created before, in design time.

But they don`t appear in classwizard so I have to do everything by hand: I add their IDs to the resource.h file, I add the definitions and declarations of the event handlers by hand ... I do everything by hand.

The question is: Is there any other way to do this? with a little help of the wizards ... or God?

Thanks



JOSE CARLOS ARAMBURU
josecarloaa@hotmail.com
 
That is odd. When you right click the control, I assume you see the class wizard. In the class wizard you should see a list of your IDs and their associated functions/event handlers. Clicking on that and Adding the function should work. If that doesn't i would suggest a re-install.

Matt
 
You can try to delete the .clw file from your project directory. Then in your project, typed Ctrl-W and follow the dialog to recreate the .clw file.

BTW, Class Wizard cannot recognized controls that you create in run-time. You have to use the resource editor to create the controls at designed time.

HTH
Shyan
 
Well, thank you. But look at what I've done:

Creating a button:
In the .h file of my view:
CMyview: public CFormview
...
protected:
CButton m_myButton;
...

In resource.h
...
#define ID_BUTTON1 1005
...
#define _APS_NEXT_CONTROL_VALUE 1006

In the .cpp file of my view, I modified the OnCreate function
int CMyview::OnCreate(...)
...
m_myButton.Create ("Start",WS_CHILD|WS_VISIBLE,
CRect(300,150,350,175),this,ID_BUTTON1);
...

So, when I want to add event handlers for the button the ID_BUTTON1 doesn't appear in the wizards.
More help please!


JOSE CARLOS ARAMBURU
josecarloaa@hotmail.com
 
The Wizard find the control's object and the ID association in DoDataExchange() member function surrounded by the Wizard code:
//{{AFX_DATA_MAP(CMyView)
DDX_Control(pDX, IDC_BUTTON1, m_btnButton1);
//}}AFX_DATA_MAP

The easiest way is to add the button using the resource editor and use the ClassWizard to add a control variable.

Otherwise, you have to add the association in DoDataExchange yourself.

You don't need to create the button manually too. It is handled by the framework if you use DDX_???().


HTH
Shyan
 
Is there a way that you could make the button with the resource editor during design time but make it not visible. Then when you want to see it you could pass the WM_VISIBLE to it????
 
You can creat your own class:
class CMyButton : public CButton
and then you can use classwizard to add your event handlers.

Creating a button:
In the .h file of your view:
CMyview: public CFormview
...
protected:
CMyButton m_myButton;
...
 
But if you don't know how many controls you are gonna need or create, using WM_VISIBLE is not the best solution, I think. But to be honest, I'm using it.


JOSE CARLOS ARAMBURU
josecarloaa@hotmail.com
 
> Is there a way that you could make the button with
> the resource editor during design time but make it
> not visible. Then when you want to see it you could
> pass the WM_VISIBLE to it????

Yes. At design time, right click the controls, select "Properties". In the "General" tab, there is a check box called "Visible". Uncheck the box will make the control invisible when run.

To hide or unhide the control, call the ShowWindow member function:
m_myCtrl.ShowWindow(SW_HIDE); // hide the control
m_myCtrl.ShowWindow(SW_SHOW); // Show the control.

HTH
Shyan
 
> But if you don't know how many controls you are gonna
> need or create, using WM_VISIBLE is not the best
> solution, I think. But to be honest, I'm using it.

If you need to create the controls at run time, ClassWizard is not going to help. You have to add the handler manually.

What you can do is create a dummy control using ClassWizard, use that control to add the handlers, and see how the message map is being added and the function prototypes. Use that information as a template to add your own handlers manually.

Once you're done, you can remove the dummy control and all the handlers.

HTH
Shyan
 
i have a Clistctrl object in report view form
can i stop resizing the columns of the listBox?

how can i find a item so that there is no duplicate items.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top