Trying to create a Popup Window
-
I would like to add a graph (x vs y plot ) to my application. I would like this graph to be displayed in a new window. Therefore, I wrote the following code:
void CMyView::drawGraph() { /* virtual BOOL CreateEx( DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, LPVOID lpParam = NULL ); */ CRect rect1( 100, 200, 300, 400 ); CreateEx( 0, NULL, TEXT("Graph"), WS_OVERLAPPEDWINDOW|WS_CHILD, rect1, this, 0 ); } Unfortunately, the call to CWnd::CreateEx dies with an assertion error. The routine CWnd::CreateEx calls the routine AfxHookWindowCreate. This routine has the following assert statement in it: `ASSERT(pWnd->m_hWnd == NULL); // only do once` In my case, m_hWnd is non-NULL. Therefore, the program aborts. I am sure that I am doing something wrong in the call to CreateEx but I do not know what it is. Also, I find the documentation for this call to be lacking. For one thing, I could not find any examples where it was used to create a sub-window. Thanks Bob
-
I would like to add a graph (x vs y plot ) to my application. I would like this graph to be displayed in a new window. Therefore, I wrote the following code:
void CMyView::drawGraph() { /* virtual BOOL CreateEx( DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, LPVOID lpParam = NULL ); */ CRect rect1( 100, 200, 300, 400 ); CreateEx( 0, NULL, TEXT("Graph"), WS_OVERLAPPEDWINDOW|WS_CHILD, rect1, this, 0 ); } Unfortunately, the call to CWnd::CreateEx dies with an assertion error. The routine CWnd::CreateEx calls the routine AfxHookWindowCreate. This routine has the following assert statement in it: `ASSERT(pWnd->m_hWnd == NULL); // only do once` In my case, m_hWnd is non-NULL. Therefore, the program aborts. I am sure that I am doing something wrong in the call to CreateEx but I do not know what it is. Also, I find the documentation for this call to be lacking. For one thing, I could not find any examples where it was used to create a sub-window. Thanks Bob
BobInNJ wrote:
CRect rect1( 100, 200, 300, 400 ); CreateEx( 0, NULL, TEXT("Graph"), WS_OVERLAPPEDWINDOW|WS_CHILD, rect1, this, 0 );
Effectively, here you are trying to create CMyView again, where it already exists. You may want to do something like this
CRect rect1( 100, 200, 300, 400 );
m_wndYouwantotCreate.CreateEx( 0, NULL, TEXT("Graph"), WS_OVERLAPPEDWINDOW|WS_CHILD,
rect1, this, 0 ); -
I would like to add a graph (x vs y plot ) to my application. I would like this graph to be displayed in a new window. Therefore, I wrote the following code:
void CMyView::drawGraph() { /* virtual BOOL CreateEx( DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, LPVOID lpParam = NULL ); */ CRect rect1( 100, 200, 300, 400 ); CreateEx( 0, NULL, TEXT("Graph"), WS_OVERLAPPEDWINDOW|WS_CHILD, rect1, this, 0 ); } Unfortunately, the call to CWnd::CreateEx dies with an assertion error. The routine CWnd::CreateEx calls the routine AfxHookWindowCreate. This routine has the following assert statement in it: `ASSERT(pWnd->m_hWnd == NULL); // only do once` In my case, m_hWnd is non-NULL. Therefore, the program aborts. I am sure that I am doing something wrong in the call to CreateEx but I do not know what it is. Also, I find the documentation for this call to be lacking. For one thing, I could not find any examples where it was used to create a sub-window. Thanks Bob
You can create another window from your view, but it will be a bit complex. I can think of a couple of choices for you... The simplest one is to create a new CDialog based class, that only has one control in it. You can find plenty of graph controls here on codeproject that you can pop in this dialog. Then just call DoModal on it, let it stay up until the user presses OK, and all is nice. The other is a bit more complex. You could make a window like a popup control with your little graph on it, that goes away when the user moves the mouse again. This depends on how you want your software to be. Have a look at: http://www.dilascia.com/PixieDoc.htm#CPopupText[^] for a tooltip alike window - just change the drawing code / size to your desires. Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...