CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Posts
    3

    receive events from dynamically created controls

    my cformview-based application has dynamically created controls, depending on the user's settings. so, it could have 4 edit boxes for one user and 2 combo boxes for another. how can i receive events from these controls ? i can't use the classwizard. creating all the controls and hiding the appropriate ones is not an option, either.
    thanks


  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: receive events from dynamically created controls

    Try SubclassDlgItem().

    Regards,

    Paul McKenzie


  3. #3
    Join Date
    Apr 1999
    Posts
    3

    Re: receive events from dynamically created controls

    how about if some of these controls are activex controls ? must i use a dialog template for SubclassDlgItem to work ?

    thanks again


  4. #4
    Join Date
    May 1999
    Posts
    25

    Re: receive events from dynamically created controls

    Hi,

    Here is one way of doing it.
    If I want to create controls on a dialog box at runtime but want the convinience of MFC message mapping - I do the following:

    1. Edit resource.h file and add the ID of the control as it will be at runtime.

    2. Create a the control on the dialogbox resource and give it the ID we defined in step 1 above.

    This way MFC Class wizard will see it at design time and we can map messages as normal.


    3. Once we have mapped all the messages we want
    then we remove the control from the dialogbox template.
    The #define for the control ID should stay in the resource.h file (at least in VC++ version 6).


    When we create the control at runtime - no problem.


    You must remember to include resource.h in the appropriate cpp file.

    This basic principle can be extended to menu items for runtime dynamic menus, etc..

    If you want to create the control on for example the mainFrame window. Create a dialogbox in the resource (we will not display this box at all at runtime). Go throught the procedure outlined above. Instead of giving this dialogbox its own class- tell class wizard we want to associate it
    with an existing class - for example the mainframe window class.
    We can then get class wizard to map the message for the various controls to the mainframe.
    When all is done we simply delete the dialogbox from the resource.

    This is the way I do all my dynamic creation stuff.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured