Creating & Adding Custom control to the in-built gallery of controls

Many a times we create a control and need to reuse it in number of other applications. Instead of creating the class having the same functionality or copying the already created classes we can add the created control to the in-built gallery of controls. We can then add this control to the project as and when necessary. Following steps show how to achieve this.

  • Create a dialog-based application ‘mycontrol’ and insert a class ‘charedit’ in it derived from CEdit.
  • Override OnChar( ) handler and add following code in it to accept only the characters.

void charedit::OnChar ( UINT nChar, UINT nRepCnt, UINT nFlags )

{

if ( nChar >= 48 && nChar <= 57 )

;

else

CEdit::OnChar ( nChar, nRepCnt, nFlags ) ;

}

  • Right click on charedit in the class view tab and select ‘Add to Gallery’ menu item.
  • ‘Add to Gallery’ creates and places a user-defined component (.OGX file) in the new folder. The .OGX file allows other applications to share the class you added to the Gallery.
  • The ‘charedit.ogx’ would get created in the Gallery located in:

C:\Program Files\Microsoft Visual Studio\Common\MSDEV98\Gallery\mycontrol.

  • Now to use the charedit control create another dialog-based application.
  • Add the control by selecting ‘Project | Add to Project | Component and Control | mycontrol’. Select ‘charedit.ogx’ from there.

The ‘charedit.h’ and ‘charedit.cpp’ would get added to your project. Create the edit control by calling charedit::Create( ) function.

Subscribe / Share

It's very calm over here, why not leave a comment?

Leave a Reply




Categories

Powered by Yahoo! Answers