CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Guest

    Removing a dynamic control

    Hello,

    I'm dynamically create an ActiveX control by using the CreateControl call but I can't find a way to delete the control once I no longer want it. Is there anything in MFC that allows you to remove a Active X control?


  2. #2
    Guest

    Re: Removing a dynamic control

    CreateControl() can return a CWnd object ( i think ), check the class library for the required function, i think it is CWnd::CloseWindow() or CWnd:estroyWindow(), sorry don't Dev studio on this machine


  3. #3
    Join Date
    Apr 1999
    Posts
    306

    Re: Removing a dynamic control

    Destoying controls by yourself can be very risky causing in the best case memory leaks. If you use CWnd:estroyWindow(), as suggested, this will call only the base class destructor and guess what will happen.

    My suggestion:

    Make it a stack based object and it will be destructed either when the function exits or when your program enters the CWinApp::OnIdle() function.


  4. #4
    Join Date
    Nov 1999
    Posts
    2

    More dynamic control questions

    I'm _so_ hoping that you're still following this thread. I've been trying to find someone who has, successfully, dynamically created ActiveX controls, for the past few days.

    I'd like to dynamically create an ActiveX masked edit control within a VC++
    application.

    I've generated the source for CMSMask, and added it to the project.

    The dialog in which this all happens is created by a DLL. The DLLs CWinApp
    derived class has an InitInstance() method which calls
    AfxEnableControlContainer().

    I've made a call to the CMSMask constructor and called Create() upon it. [ I've tried CreateControl with the first argument (the class name) as "MaskEdBox" and as "MSMaskWndClass" but both caused CreateControl to return false. ]

    I set the font (successfully) and then call SetMaxLength(). This results in
    an exception being thrown which causes the message box "Invalid Property
    Value" to be displayed. I get the same effect if I call ModifyStyleEx().

    The call to Create also causes exceptions to be thrown. The exceptions are
    caught before Create returns. They are all DISP_E_MEMBERNOTFOUND.


    I suspect that I have failed to call some OLE initialisation method.

    Care to set me on the right track?




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