15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Temporary vs. Permanent Windows

ktm@ormec.com
Wednesday, November 06, 1996

Environment: VC++ 4.2b, WinNT 4.0

I've written an OCX and a specialized container application. The container
application allows the user to insert and delete instances of my OCX 
control dynamically as follows:
1) I used Insert | Component to create a wrapper class for my OCX in the
   container. Like all such wrappers, it's based on CWnd.

2) At run-time, the user selects a menu item to create a new instance

3) I determine an available control ID out of a predefined block

4) I allocate a new instance of the wrapper class with new
    CMyOCX* pItem = new CMyOCX();

5) I create the object
    pItem->Create(_T(""), 0, CRect(0,0,0,0), this, ControlID);

6) Naturally, I store the item for later access and destruction

7) I go on to invoke methods of the OCX

This works fine at first - if I immediately call a method of my OCX, all
is well. However, if I wait, it appears that MFC's idle processing is 
destroying my window, so attempting to call a method of the OCX fails.

What do I have to do differently so that the window sticks around?
 
  Katy
-- 
Katy Mulvey                            ktm@ormec.com
Software Development Engineer
ORMEC Systems                          http://www.ormec.com
19 Linden Park; Rochester, NY 14625



Marty Fried -- mfried@linex.com
Sunday, November 10, 1996

At 12:01 PM 11/6/96 -0500, ktm@ormec.com wrote:
>Environment: VC++ 4.2b, WinNT 4.0
>
>4) I allocate a new instance of the wrapper class with new
>    CMyOCX* pItem = new CMyOCX();
>
>5) I create the object
    pItem->Create(_T(""), 0, CRect(0,0,0,0), this, ControlID);
>  . . .

>This works fine at first - if I immediately call a method of my OCX, all
>is well. However, if I wait, it appears that MFC's idle processing is 
>destroying my window, so attempting to call a method of the OCX fails.
>
>What do I have to do differently so that the window sticks around?

It's not clear where you're doing these calls, but is pItem a stack
variable that goes out of scope at the end of the function?  Perhaps it
needs to be either static or global.  I don't see how that would cause the
window to be destroyed, though.  That should only happen if you delete
pItem or destroy the parent window.





| Вернуться в корень Архива |