About Custom controls

I am searching for some basic samples wich use custom controls in MFC.
(I am using Microsoft Visual C++ 5.0)
I have found some samples by Microsoft but these are written for windows 3.0 & 3.1.

Can some one tell me were to found some samples.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What do you mean by "custom controls"?  What do you want to do?

Personally, if I were you I would be inclined to write and use ActiveX controls. However, I'll trust that you have your reasons for wanting "custom controls".

Having said that, Coriolis Group Books has a book called Windows Programming Power with Custom Controls by Paul Cilwa and Jeff Duntemann. It's a couple of years old, however, the code is still perfectly valid.

With everyone moving to ActiveX, I don't think you'll find much more in terms of books on writing custom controls.


BTW, if you are interested in learning ActiveX, Wrox has a great beginner level book calld "Visual C++ Components with MFC Extensions & ActiveX Controls" by Matt Telles. This book will get you up and running very quickly on your first ActiveX controls.

OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.


If you want us to help you I would suggest that...

1. You state specifically what it is you need
2. When you reject an proposed answer, you explain why the answer didn't fit your needs


mike_marquetAuthor Commented:

What I really want is a sample application (an example) which use a 'custom control' (insert with the resource workshop). I want to know how I must instanced this control ?
What kind of parameter I must set in the properties of the control in the resource ?
 (Caption,CLASS,Style & ExStyle)
How to proceed with the class that will by used for this new control.
For example, I want that all message for this custom control goes to this class (my class) :

class CIO_LED : public CWnd


This is the InitDialog function off the dialog that has the custom control :
(where m_MyControl is declared in the header like CIO_LED m_MyControl)

void CMyDialog::InitDialog()

(Assuming you're using Developer's Studio:)

Here's a quick, possibly incomplete answer:  It will get you started.

Basically, you add an ActiveX control to your project by bringing up a dialog (template) and selecting Project|Add To Project|Components and Controls|Registered ActiveX Controls from menu.  Select a control from the list.  

Dev Studio will create a "wrapper class" for the control, which provides stubs for all the property gets/sets, and methods.  While still viewing your dialog, bring up Class Wizard.  Under Member Variables, be sure your dialog's class is selected under Class Name and select the Control ID of the control you just added.  Click on Add Variable and type in a name for the variable.  Dev Studio will add the member variable to your dialog class's header file (*.h).  All you need to do is use the variable to call the control's member functions.

Also, make sure the call to AfxEnableControlContainer(); is in the InitInstance handler of CTheApp (the main app program).

Basically, you call the get/set properties of the control.  Each control will be different.  You can also bring up custom property sheets for controls during design mode.  Bring up your dialog, right click on a control and select Properties.  Look under the All tab.  You can set properties here as well.

Try this and if you have specific questions (and I'm sure you will) ask them after you experiment a little.

mike_marquetAuthor Commented:
There was propably a mistack.
I doesn't want to use ActiveX control but Custom control. This is a control
avalaible in the resource workshop of Microsoft Visual C++ 5.0.
You can find this control in the 'controls' list of the resource workshop.
The button for this control is a 'HEAD'.

For ActiveX control, I have already created some one.

You lost me.  I thought VC++ Version 5.0 ran under Developer Studio, which integrates resource workshop.  I can't find a 'controls' list, other than as I described in previous comment.  Maybe there's a difference between VC++ 5.0 pro version and standard version?  Anyway, good luck.
Ok, Now I'm totally lost. Do you want to write a custom control or simply use one??? If you want to simply use a control, which one? I have no idea what you are asking!!!
I'm lost too, I'm afraid. I got the impression that you want to just make a plain beginning "backdrop" so to speak in the resource workshop (Like a button or window) and the alter it program-wise at run time with special message handling, look and feel, etc. Is this what you want?
mike_marquetAuthor Commented:
My English is not so perfect !
When you go to the resource workshop, you can drag for example a Edit Control to
your Dialog (or a Static control, ...).Whis this floating toolbar, you can insert in your dialog :
- Group box
- Static control
- Edit control
- List control
- button control
- radio button
- combo box
- list box
- slider control
- ...
AND custom control

When you insert some control in the dialog it appers like a grayed rectangle and when
you look in the properties of this control you can see this :

Custom Control Properties
ID .....................                 Caption
Visible         Group              Class
Disabled      Tab Stop           Style
Help ID                               ExStyle

How must I proceed to use this control ????

Thanks for answer
try www.codeguru.com and look in the controls area and then look for datetimepicker.  one of these uses the custom control to create the datetime picker.
good luck,

The custom control option is for when you have created your
own windows classes and registered them.

You would register your own window class in the initinstance
giving it a name.  From then on whenever a window is created
which contains a custom control with that class name, your
window class will be used.

Each window class has a number of styles and a windows procedure.

You could just create custom controls from the window classes
already in existance such as EDIT, LISTBOX etc.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.