Click here to Skip to main content
       

C / C++ / MFC

 
GeneralRe: Regarding storing structures in database PinmemberMember 789460129-Apr-13 1:00 
GeneralRe: Regarding storing structures in database PinmemberMember 78946011-May-13 0:09 
Questionstrcat_memcpy Pinmemberkhushboo gupta25-Apr-13 18:37 
AnswerRe: strcat_memcpy Pinmemberpasztorpisti25-Apr-13 21:07 
GeneralRe: strcat_memcpy PinmemberFreak3026-Apr-13 2:15 
GeneralRe: strcat_memcpy Pinmemberpasztorpisti26-Apr-13 2:20 
AnswerRe: strcat_memcpy PinmvpRichard MacCutchan25-Apr-13 22:17 
QuestionDoModal in CWnd::PreTranslateMessage( MSG *pMsg ) PinmemberNewbie0025-Apr-13 10:26 
Hello,
 
I need to verify content of my edit control before I let it to loose focus. To do so I wrote my PreTranslateMessage like this:
 
BOOL CMyFrameWnd::PreTranslateMessage( MSG *pMsg )
{
   BOOL bMessageHandled = FALSE;
 
   switch( pMsg->message )
   {
      case WM_LBUTTONDOWN:
      {
        if( ::GetFocus == MyEditWnd )
        {
          if( !IsContentOfMyEditWndOK )
          {
            ShowMessageBox( "You cannot change value");
            //ShowMessageBox has got DoModal inside, which pumps messages.
           //Unfortunately it causes my *pMsg parameter to be changed.
          }
        }
        break;
      }
   }
  if( !bMessageHandled )
  {
     bMessageHandled = CFrameWnd::PreTranslateMessage( pMsg ); //I get assertion has failed here, because I am sending pMsg->Hwnd changed with 'ShowMessageBox'
  }
 
  return bMessageHandled; //I want to show messagebox and let WM_LBUTTONDOWN to be processed, because I do not want to trap focus in my Edit. So I am returning FALSE here. But it has no sence since the pMsg has changed. It is no longer WM_LBUTTONDOWN. 
}
In order to be able to show modal dialog in PreTranslateMessage and after it forward WM_LBUTTONDOWN I would like to do something like this:
BOOL CMyFrameWnd::PreTranslateMessage( MSG *pMsg )
{
   BOOL bMessageHandled = FALSE;
   MSG oRememberMsg;
 
   switch( pMsg->message )
   {
      case WM_LBUTTONDOWN:
      {
        if( ::GetFocus == MyEditWnd )
        {
          if( !IsContentOfMyEditWndOK )
          {
            oRememberMsg = *pMsg; 
            ShowMessageBox( "You cannot change value");
            *pMsg = oRememberMsg; //now pMsg is WM_LBUTTONDOWN again 
          }
        }
        break;
      }
   }
  if( !bMessageHandled )
  {
     bMessageHandled = CFrameWnd::PreTranslateMessage( pMsg ); //I am not getting assertion has failed, because pMsg->HWnd is correct now (the same as at the beginning)
  }
 
  return bMessageHandled; //Now I am forwarding my catch WM_LBUTTONDOWN and my Edit loses focus
}
But I am not sure if my code is ok from MFC structural point of view. Can I manipulate with MSG *pMsg parameter as I described above? I tried it and it seems to work, but I don't know... Does it make some side effects? Is something I am missing here? How do you think?
AnswerRe: DoModal in CWnd::PreTranslateMessage( MSG *pMsg ) Pinmemberjeron125-Apr-13 10:48 
GeneralRe: DoModal in CWnd::PreTranslateMessage( MSG *pMsg ) PinmemberNewbie0025-Apr-13 18:24 
AnswerRe: DoModal in CWnd::PreTranslateMessage( MSG *pMsg ) PinmvpRichard MacCutchan25-Apr-13 22:14 
GeneralRe: DoModal in CWnd::PreTranslateMessage( MSG *pMsg ) [modified] PinmemberNewbie0026-Apr-13 7:02 
GeneralRe: DoModal in CWnd::PreTranslateMessage( MSG *pMsg ) PinmvpRichard MacCutchan26-Apr-13 7:23 
GeneralRe: DoModal in CWnd::PreTranslateMessage( MSG *pMsg ) PinmemberNewbie0026-Apr-13 8:01 
GeneralRe: DoModal in CWnd::PreTranslateMessage( MSG *pMsg ) PinmvpRichard MacCutchan26-Apr-13 22:15 
QuestionC++ MVC framework for Linux/Motif [modified] PinmemberLeifUK25-Apr-13 6:35 
AnswerRe: C++ MVC framework for Linux/Motif Pinmemberpasztorpisti25-Apr-13 20:56 
QuestionCrystal Reports 2011 with C++/MFC Dev Studio 2010 PinmemberMember 983646924-Apr-13 18:42 
QuestionAudio in DirectShow PinmemberIndian Coder198924-Apr-13 17:40 
AnswerRe: Audio in DirectShow PinmemberVaclav_Sal25-Apr-13 3:03 
QuestionHow to create 4 dimenstional array Pinmemberjothivel k24-Apr-13 9:07 
AnswerRe: How to create 4 dimenstional array PinmvpRichard MacCutchan24-Apr-13 9:33 
AnswerRe: How to create 4 dimenstional array Pinmemberpasztorpisti24-Apr-13 9:45 
GeneralRe: How to create 4 dimenstional array Pinmemberjothivel k25-Apr-13 7:12 
GeneralRe: How to create 4 dimenstional array Pinmemberpasztorpisti25-Apr-13 20:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 30 Sep 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid