How To Insert Activex dynamically - Programmer

This is a discussion on How To Insert Activex dynamically - Programmer ; Hi to all. I need to insert "n" ActiveX on a CFormView or CMainFrame using a Menu Bar. I did the next: void CMainFrame::OnFileNew() { // TODO: Add your command handler code here CImagXpress mm; DWORD style = WS_VISIBLE; RECT ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: How To Insert Activex dynamically

  1. How To Insert Activex dynamically

    Hi to all.

    I need to insert "n" ActiveX on a CFormView or CMainFrame using a Menu
    Bar. I did the next:

    void CMainFrame::OnFileNew()
    {
    // TODO: Add your command handler code here
    CImagXpress mm;

    DWORD style = WS_VISIBLE;
    RECT r;
    r.top = 0;
    r.left = 0;
    r.bottom = 10;
    r.right = 10;

    mm.CreateControl(mm.GetClsid(), "otro", style, r, this, 1003);
    mm.SetFileName("C:\\projects\\MFC\\mas\\res\\img1.jpg");

    }
    The ActiveX may show an image, but don't work.

    After this i tried to put the same code in CFormView

    void CMasView::OnFileOpen()
    {
    // TODO: Add your command handler code here

    CImagXpress mm;

    DWORD style = WS_VISIBLE;
    RECT r;
    r.top = 0;
    r.left = 0;
    r.bottom = 10;
    r.right = 10;

    mm.CreateControl(m_imagen.GetClsid(), "otro", style, r, this, 1003);
    mm.SetFileName("C:\\projects\\MFC\\mas\\res\\img1.jpg");
    }

    but don't work.

    mm object isn't NULL. Trying ideas I've put

    this->Attach((HWND)mm.GetHWnd()); in CMasView::OnFileOpen()

    and I got
    ASSERT(m_hWnd == NULL); // only attach once, detach on destroy
    but I can saw the Image on the ActiveX.

    I put the first ActiveX with FormEditor and it works, methods, events
    handlers, etc...


    I dont'know what can i do.

    I think i need to "attach" the news activeX in some place for
    displaying and events control.

    Do Somebody have some idea?

    Thanks for advance.

  2. Re: How To Insert Activex dynamically

    faemino wrote:
    > Hi to all.
    >
    > I need to insert "n" ActiveX on a CFormView or CMainFrame using a Menu
    > Bar. I did the next:
    >
    > void CMainFrame::OnFileNew()
    > {
    > // TODO: Add your command handler code here
    > CImagXpress mm;
    >
    > DWORD style = WS_VISIBLE;
    > RECT r;
    > r.top = 0;
    > r.left = 0;
    > r.bottom = 10;
    > r.right = 10;
    >
    > mm.CreateControl(mm.GetClsid(), "otro", style, r, this, 1003);
    > mm.SetFileName("C:\\projects\\MFC\\mas\\res\\img1.jpg");
    >
    > }
    > The ActiveX may show an image, but don't work.


    Your mm object is created on the stack. This means it is destroyed when
    OnFileNew returns. Make it a member variable instead so it will
    continue to exist as long as CMainFrame exists.

    Also move the code to the view class if you want the control to be
    visible. The mainframe client area is not visible when you have a view
    window.

    --
    Scott McPhillips [VC++ MVP]


+ Reply to Thread