Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

OnSize CWGraph causes assertion error

My current environment is listed at the bottom.

I created an MDI application in Visual Studio C++ and am having my View class inheriting from CFormView. I created my dialog in the dialog editor with 1 CWGraph control. I then added the OnSize event to the class and the following code:

CRect client;
GetClientRect(&client);
m_graph.MoveWindow(client);

This causes an assert error as the CWGraph isn't a window yet. I know this is the case b/c first I changed the code to

CRect client;
GetClientRect(&client);
if (m_resize)
m_graph.MoveWindow(client);

where m_resize initializes to false and clicking a button after the graph's complete creation causes it to resize when i drag the window.

I then wrote in a quick littl
e hack to change the if statement above to
if (::IsWindow(m_graph.GetSafeHwnd()))

This is the only way the code will work. I'm wondering mostly what the issue is here as it seems as though it would be an issue inside of the CWGraph control, albeit, my experience with the order of execution and creation of Active X controls in MFC isn't what it probably should be.

TIA

Environment:
Windows XP SP1
Measurement Studio 7.0
Visual Studio C++ .NET IDE (mfc app, not c++ .net)
0 Kudos
Message 1 of 4
(3,659 Views)
Hello

Do you have an example project you could post? I would like to see if the same problem happens on my machine too.

Thanks

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 2 of 4
(3,659 Views)
The example is located at http://www.microstrain.com/dev/CrashingGraph.zip. I was having problems w/the NI attach file program (most likely b/c it's about 9 megs...mostly project space, but might as well send the entire thing over). If there's some goofy coding error I've made, please, let me know.

The CFormView class is called Graph (I forgot the C when making up the application crashing example).

Look in Graph.cpp in the OnSize function for the lines I'm discussing.

Take care,
Adam
0 Kudos
Message 3 of 4
(3,659 Views)
The problem is that the control is not actaully initialized when you first call MoveWindow on the graph control. When Onsize is called while the Window is being created, m_graph's handle will not be ready, hence causing the assertion when you try to manipulate the control. This is not a problem specific to the CWGraph control, it is pretty much standard with all MFC controls. You'll see the same thing happen if you do the same thing with a command button.

Your workaround is the correct way to set this up. You could also have use a boolean to indicate when the window has finished initializing and then change the size of the graph control. Either way, MFC has to initialize the control before it can do anything to it.

I hope this helps

Bi
lal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 4 of 4
(3,659 Views)