-
March 5th, 2014, 04:22 AM
#1
afxwin2.inl line 265
I have an MDI, where I have an dialog bar. There, I have an extended ComboBox. On OnCloseUpCombo event, I want to display something on CDialog ... but soon as CDialog is close up, I have ASSERT error: afxwin2.inl line 265, which tell me:
Code:
{ ASSERT(::IsWindow(m_hWnd)); return CWnd::FromHandle(::GetParent(m_hWnd)); }
Last edited by mesajflaviu; March 5th, 2014 at 07:32 AM.
-
March 5th, 2014, 07:32 AM
#2
-
March 5th, 2014, 08:29 AM
#3
Re: afxwin2.inl line 265
Originally Posted by mesajflaviu
I had solved my issue.
Good!
And what was the reason?
Victor Nijegorodov
-
March 6th, 2014, 03:03 AM
#4
Re: afxwin2.inl line 265
The situation: I have an MDI app, with a dialogbar. In that dialogbar, I have an extended CComboBox, and on
CMyDialogBar::OnCloseUpCombo()
I have a CMyDialog:oModal() ... after this CMyDialog has closed (but only when I closed with enter key), I had the above assert error ...
The cause was an direct call, in the extended CComboBox into PreTranslateMessage, like this:
Code:
BOOL CComboBoxExt::PreTranslateMessage(MSG* pMsg)
{
...
...
if(VK_RETURN == pMsg->wParam)
ShowDropDown(FALSE);
}
and the workaround was:
Code:
if(VK_RETURN == pMsg->wParam)
PostMessage(CB_SHOWDROPDOWN, (WPARAM)FALSE, (LPARAM)0);
The assert error lead me to nowhere, that's why I put this on forum, maybe somebody had the same problem ...
Last edited by mesajflaviu; March 6th, 2014 at 04:28 AM.
-
March 6th, 2014, 07:47 AM
#5
Re: afxwin2.inl line 265
1) PreTranslateMessage() is not the ideal place to handle/process messages.
it's purpose is to 'modify' or 'transform' messages.
One of the common uses is to translate keyboard shortcuts (accelerators) into WM_COMMAND messages via the TranslateAccelerator() API.
But you can use it to do your own transformations.
You do this by changing the contents of the pMsg structure.
2) Showing/forcing a dropdown in PreTranslateMessage is as a result a bad idea.
Changing this to a PostMessage() will "apparently" make the problem go away, but not for the reason you think
3) Your real issue is that if you have processed a message and don't need it to do anything else, you need to return TRUE from the function.
if you don',t then MFC will continue processing the message in the normal way.
Your Original function failed because:
YOu are forcing a dropdown
you are probably not returning TRUE
The DropDown is forced, and the VK_RETURN continues on to execute the default button click (OK or Cancel probably) and terminate the dialog at a moment it's unsafe to do so (the combo is pulled open)
Your 2nd attemt seems to work (but is equally wrong, and could subtly fail in some cases) because:
You are posting a message
You are probably still not returning TRUE
A message is posted
THe VK_RETURN is passed on, and executes the default button click
The dropdown posted message is (usually) never processed. because the dialog terminates at which point no code will process the posted message.
If you are doing something OTHER than transforming the message but "have to" to some sort of actual processing in PreTranslateMessage (not ideal, but it happens) then return TRUE right after your processing, don't call the parent implementation.
IDeally modify the message in pMSG only (and return TRUE if you did).
-
March 6th, 2014, 08:57 AM
#6
Re: afxwin2.inl line 265
Kindly thank you for your explanation. I learn something here.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|