how to subclass a control on a dialog

  • Steven Weiss

    Steven Weiss - 2004-09-21

    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)

    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:



    • 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)


      • 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.

        // say your child window is an edit box
        // from now on, this child has been subclassed

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


    • Steven Weiss

      Steven Weiss - 2004-09-23

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


Log in to post a comment.