DoModal in DropFiles Error ?!
-
Where is the assert? What this is saying is that the
HWND
identified by the member variablem_hWnd
is not a valid window. To say more I would need more info like: - The callstack. - Some code around the assert. - The value ofm_hWnd
. SteveThe assert is coming from wincore.cpp (void CWnd::AssertValid() const) If I comment out the domodal part of the code it works fine, it's only when domodal is called that the problem occurs at the end of the function.
void CWnd::AssertValid() const { if (m_hWnd == NULL) return; // null (unattached) windows are valid // check for special wnd??? values ASSERT(HWND_TOP == NULL); // same as desktop if (m_hWnd == HWND_BOTTOM) ASSERT(this == &CWnd::wndBottom); else if (m_hWnd == HWND_TOPMOST) ASSERT(this == &CWnd::wndTopMost); else if (m_hWnd == HWND_NOTOPMOST) ASSERT(this == &CWnd::wndNoTopMost); else { // should be a normal window **ASSERT(::IsWindow(m_hWnd));** // should also be in the permanent or temporary handle map CHandleMap* pMap = afxMapHWND(); ASSERT(pMap != NULL);
-
The assert is coming from wincore.cpp (void CWnd::AssertValid() const) If I comment out the domodal part of the code it works fine, it's only when domodal is called that the problem occurs at the end of the function.
void CWnd::AssertValid() const { if (m_hWnd == NULL) return; // null (unattached) windows are valid // check for special wnd??? values ASSERT(HWND_TOP == NULL); // same as desktop if (m_hWnd == HWND_BOTTOM) ASSERT(this == &CWnd::wndBottom); else if (m_hWnd == HWND_TOPMOST) ASSERT(this == &CWnd::wndTopMost); else if (m_hWnd == HWND_NOTOPMOST) ASSERT(this == &CWnd::wndNoTopMost); else { // should be a normal window **ASSERT(::IsWindow(m_hWnd));** // should also be in the permanent or temporary handle map CHandleMap* pMap = afxMapHWND(); ASSERT(pMap != NULL);
Stephen was asking for some code of your own. So, use the call stack to find in which function it crashes (or you can also use your debugger, which is very very helpfull).
-
Stephen was asking for some code of your own. So, use the call stack to find in which function it crashes (or you can also use your debugger, which is very very helpfull).
int RetVal; int nFiles = DragQueryFile(hDrop, -1, szDroppedFile, 2048); for(int i=0;i-1) // if x>-1 a duplicate filename already exists { CFileReplace md; md.ReturnValue=&RetVal; md.DoModal(); // Depending on RetVal value either replace the file or skip ... } ...
If I comment out the 3 lines regarding the CFileReplace function and assign a value to RetVal the function works fine, it's only by calling DoModal that the error occurs. -
Hi, I've coded a dialog based app that allows you to drop files into a listbox. Once the drop has taken place I've written some code to check if the files dropped are already listed in the lisbox - and if so a dialog box shows asking the user if they want to replace their existing files (pretty much like windows explorer). My problem is, everything works fine until the end of the DropFiles function is reached..when it returns the program crashes from the following Assert:
ASSERT(::IsWindow(m_hWnd));
Anyone know how to fix this? :confused: Thanks in advance. -
int RetVal; int nFiles = DragQueryFile(hDrop, -1, szDroppedFile, 2048); for(int i=0;i-1) // if x>-1 a duplicate filename already exists { CFileReplace md; md.ReturnValue=&RetVal; md.DoModal(); // Depending on RetVal value either replace the file or skip ... } ...
If I comment out the 3 lines regarding the CFileReplace function and assign a value to RetVal the function works fine, it's only by calling DoModal that the error occurs.What does the
CFileReplace
dialog do when it is being dismissed?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
What does the
CFileReplace
dialog do when it is being dismissed?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
it exits with OnOK()
-
it exits with OnOK()
GrumbleWeedster wrote:
it exits with OnOK()
That's all that's in
CFileReplace::OnOK()
? IsCFileReplace::ReturnValue
a pointer? Where does it get assigned a new value?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
GrumbleWeedster wrote:
it exits with OnOK()
That's all that's in
CFileReplace::OnOK()
? IsCFileReplace::ReturnValue
a pointer? Where does it get assigned a new value?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
At this moment it isn't returning a value because of the current problem, it's still a plain dialog box with an OnOK() to close.
-
At this moment it isn't returning a value because of the current problem, it's still a plain dialog box with an OnOK() to close.
Ok, so what happens in
CFileReplace::OnInitDialog()
?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
Ok, so what happens in
CFileReplace::OnInitDialog()
?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
Nothing. At the moment CFileReplace is an empty default dialog with and OK and Cancel button. There are no custom functions in place yet because I need to get around the initial error.
-
Nothing. At the moment CFileReplace is an empty default dialog with and OK and Cancel button. There are no custom functions in place yet because I need to get around the initial error.
GrumbleWeedster wrote:
At the moment CFileReplace is an empty default dialog with and OK and Cancel button. There are no custom functions in place...
Based on that, can we then assume that it has no bearing on the problem? Also, answering this question will go a long way towards the solution.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
GrumbleWeedster wrote:
At the moment CFileReplace is an empty default dialog with and OK and Cancel button. There are no custom functions in place...
Based on that, can we then assume that it has no bearing on the problem? Also, answering this question will go a long way towards the solution.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
I may have found a solution but can anyone tell me if it could cause a problem? Changing the code in
PreTranslateMessage(MSG* pMsg)
stopped the error from occuring: Original Code: (Not Working)if( pMsg->message == WM_DROPFILES) OnDropFiles(pMsg->wParam,pMsg->lParam); return CDialog::PreTranslateMessage(pMsg);
Modified Code: (Working)if( pMsg->message == WM_DROPFILES) { OnDropFiles(pMsg->wParam,pMsg->lParam); ::TranslateMessage(pMsg); ::DispatchMessage(pMsg); return TRUE; } else return CDialog::PreTranslateMessage(pMsg);
As I said, this does make the function work correctly, but is it a solution or is it just diverting from the error? -
I may have found a solution but can anyone tell me if it could cause a problem? Changing the code in
PreTranslateMessage(MSG* pMsg)
stopped the error from occuring: Original Code: (Not Working)if( pMsg->message == WM_DROPFILES) OnDropFiles(pMsg->wParam,pMsg->lParam); return CDialog::PreTranslateMessage(pMsg);
Modified Code: (Working)if( pMsg->message == WM_DROPFILES) { OnDropFiles(pMsg->wParam,pMsg->lParam); ::TranslateMessage(pMsg); ::DispatchMessage(pMsg); return TRUE; } else return CDialog::PreTranslateMessage(pMsg);
As I said, this does make the function work correctly, but is it a solution or is it just diverting from the error?GrumbleWeedster wrote:
if( pMsg->message == WM_DROPFILES)
What's this? Why are you looking for this message in the
PreTranslateMessage()
method? You should be handling theWM_DROPFILES
message via the message map:BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_MESSAGE(WM_DROPFILES, OnDropFiles)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
GrumbleWeedster wrote:
if( pMsg->message == WM_DROPFILES)
What's this? Why are you looking for this message in the
PreTranslateMessage()
method? You should be handling theWM_DROPFILES
message via the message map:BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_MESSAGE(WM_DROPFILES, OnDropFiles)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
Dialog based applications can't seem to handle drop files that way. Nothing is ever added to the list when items are dropped. The only way I've found to enable drag and drop in a dialog based app is intercept the message in
PreTranslateMessage()