how to subclass a control on a dialog

2004-09-21
2013-04-15
  • Steven Weiss
    Steven Weiss
    2004-09-21

    hi,
    i know how to create a subclass (wnd_extend) but i don't know how to apply this subclass to a control on a dialog. i tried this:

    wnd<> mainframe = create_wnd<MainFrame>( "Renamer 4", null_wnd, create_info().menu(IDR_MAINWND) );   

    create_dlg<MainDlg> (mainframe)
        .add_child<FolderTree>(create_info().id(IDC_TREE_FOLDER));

    here i try to subclass the tree with the id IDC_TREE_FOLDER with the class FolderTree. but all it does is creating another tree.

    thx to your answers!
    mfg steven

     
    • John Torjo
      John Torjo
      2004-09-22

      He he ;) That's the beauty of auto-mapping. It happens by default. So in other words, if your dialog has some child controls, at runtime, when the dialog is created, all its children (C++ classes) are automatically created.

      For instance, say you put a list control with ID_list on your dialog - at design time. At runtime you can reference it like this:

      child<list_ctrl>(ID_list)->whatever(...);

      Best,
      John

       
    • Steven Weiss
      Steven Weiss
      2004-09-22

      well ok, nice system but:
      how do i respond to the messages of the controls in the subclass directly? i mean: if the binding to the subclass happens at runtime and dynamically then i can't get the messages in the class handler but only in the dialog (or parent window).

      but what if i want a special tree subclass which has a special behaviour when clicking on the tree. it would be necessary to have a static connection between the subclass and the actual control because the treehandler must get the message.

      that's my theory, perhaps you will correct me or show an easy way i overlooked...

       
      • John Torjo
        John Torjo
        2004-09-22

        You create an event handler for your dialog.

        There are plenty of examples to get you started.

        For your tree, you can check out examples\Splitter\simple_viewer. The dialog receives and handles events from a tree-view and a list-view.

        or... (check the next message)

        Best,
        John

         
      • John Torjo
        John Torjo
        2004-09-22

        In case you want to extend a control - like, for instance my_edit (which extends the edit control, but implements extra features)

        In this case you subclass it at run-time.
        Use the (advanced) remap<> function.

        Example:
        // say your child window is an edit box
        child(IDC_text)->remap<my_edit>();
        // from now on, this child has been subclassed

        It is best to do this in your dialog' constructor.

        Best,
        John

         
    • Steven Weiss
      Steven Weiss
      2004-09-23

      ok, i'll give the remap-mechanism a try.
      thank you!