afxwin2.inl line 265
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: afxwin2.inl line 265

  1. #1
    Join Date
    Jan 2009
    Posts
    40

    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 06:32 AM.

  2. #2
    Join Date
    Jan 2009
    Posts
    40

    Re: afxwin2.inl line 265

    I had solved my issue.

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,278

    Re: afxwin2.inl line 265

    Quote Originally Posted by mesajflaviu View Post
    I had solved my issue.
    Good!
    And what was the reason?
    Victor Nijegorodov

  4. #4
    Join Date
    Jan 2009
    Posts
    40

    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 03:28 AM.

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,763

    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).

  6. #6
    Join Date
    Jan 2009
    Posts
    40

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center