MoveWindow() causing crash on closing maximized child window with listbox
-
I have a listview within an MDI child window. There is another child window with tree control also in the MDI application. Steps to replicate the problem: First I open the child window with tree control, leave it as it is in non-maximized state. Then I open the second child window which has the list view. Maximize the child window which has listview. Close the listview from maximized state. Application crashes. I have cornered it to a MoveWindow() call, but could not go any further, is this a known problem with listview, is there any specfic tweaking that needs to be done? It causes the crash irrespective of data filled in the listview! Environment: OS- XP SP3 Pure Win32 application No MFC is used This is my call to create the listview:
CreateWindowEx( WS_EX_CLIENTEDGE, WC_LISTVIEW, "", //caption not required WS_CHILD | WS_VISIBLE | LVS_REPORT, 0, 0, rect.right, // width rect.bottom,// height m_hwndParent, NULL, (HINSTANCE) GetWindowLong (m_hwndParent, GWL_HINSTANCE), NULL);
-
I have a listview within an MDI child window. There is another child window with tree control also in the MDI application. Steps to replicate the problem: First I open the child window with tree control, leave it as it is in non-maximized state. Then I open the second child window which has the list view. Maximize the child window which has listview. Close the listview from maximized state. Application crashes. I have cornered it to a MoveWindow() call, but could not go any further, is this a known problem with listview, is there any specfic tweaking that needs to be done? It causes the crash irrespective of data filled in the listview! Environment: OS- XP SP3 Pure Win32 application No MFC is used This is my call to create the listview:
CreateWindowEx( WS_EX_CLIENTEDGE, WC_LISTVIEW, "", //caption not required WS_CHILD | WS_VISIBLE | LVS_REPORT, 0, 0, rect.right, // width rect.bottom,// height m_hwndParent, NULL, (HINSTANCE) GetWindowLong (m_hwndParent, GWL_HINSTANCE), NULL);
Where is the MoveWindow called? On which window is MoveWindow called?
«_Superman_» I love work. It gives me something to do between weekends.
-
Where is the MoveWindow called? On which window is MoveWindow called?
«_Superman_» I love work. It gives me something to do between weekends.
Hi Superman, Thanks very much for your reply. Sorry for missing out that detail. MoveWindow() is called on WM_SIZE of child window in winproc of the child window which has the list view in it.
case WM_SIZE:
// Redraw controls
RECT rect;
GetClientRect(hWnd, &rect); // gets childwindow client areaMoveWindow(m\_hwndListView, //Handle to the window. 0, // \[in\] Specifies the new position of the left side of the window. 0, // \[in\] Specifies the new position of the top of the window. rect.right, // Specifies the new width of the window. rect.bottom,// Specifies the new height of the window. true); // Boolean that specifies whether the window is to be repainted. break; //Do not return since this should be processed by DefMDIChildProc
-
Hi Superman, Thanks very much for your reply. Sorry for missing out that detail. MoveWindow() is called on WM_SIZE of child window in winproc of the child window which has the list view in it.
case WM_SIZE:
// Redraw controls
RECT rect;
GetClientRect(hWnd, &rect); // gets childwindow client areaMoveWindow(m\_hwndListView, //Handle to the window. 0, // \[in\] Specifies the new position of the left side of the window. 0, // \[in\] Specifies the new position of the top of the window. rect.right, // Specifies the new width of the window. rect.bottom,// Specifies the new height of the window. true); // Boolean that specifies whether the window is to be repainted. break; //Do not return since this should be processed by DefMDIChildProc
I'm guessing the crash occurs because MoveWindow is called on the list view after it is destroyed. Try putting an IsWindow check over the MoveWindow.
if (IsWindow(m_hwndListView))
{
MoveWindow(m_hwndListView, //Handle to the window.
0, // [in] Specifies the new position of the left side of the window.
0, // [in] Specifies the new position of the top of the window.
rect.right, // Specifies the new width of the window.
rect.bottom,// Specifies the new height of the window.
true); // Boolean that specifies whether the window is to be repainted.
}«_Superman_» I love work. It gives me something to do between weekends.
-
I'm guessing the crash occurs because MoveWindow is called on the list view after it is destroyed. Try putting an IsWindow check over the MoveWindow.
if (IsWindow(m_hwndListView))
{
MoveWindow(m_hwndListView, //Handle to the window.
0, // [in] Specifies the new position of the left side of the window.
0, // [in] Specifies the new position of the top of the window.
rect.right, // Specifies the new width of the window.
rect.bottom,// Specifies the new height of the window.
true); // Boolean that specifies whether the window is to be repainted.
}«_Superman_» I love work. It gives me something to do between weekends.
Thanks very much for your reply. IsWindow() did not help. Crash occurs only under following condition: Child window containing tree control is opened and kept in non-maximized state Then, child window containing the list is maximized and then this closed. :( Anything else that you could think of?
-
Thanks very much for your reply. IsWindow() did not help. Crash occurs only under following condition: Child window containing tree control is opened and kept in non-maximized state Then, child window containing the list is maximized and then this closed. :( Anything else that you could think of?
You could try to use MoveWindow only when the wParam parameter of WM_SIZE is SIZE_RESTORED.
«_Superman_» I love work. It gives me something to do between weekends.
-
You could try to use MoveWindow only when the wParam parameter of WM_SIZE is SIZE_RESTORED.
«_Superman_» I love work. It gives me something to do between weekends.
That also does not help :(
-
That also does not help :(
Thanks for your time and help superman. Tried
IsZoomed(hWnd)
to do some conditional operation when closing in maximized state, but that also did not help. Problem was that an allocated object was being deleted inWM_CLOSE
. When this was moved toWM_DESTROY
the crash is solved. Still not sure why this was causing the crash only when in maximized state!! :confused: Will look into this at a later time.