Solved

Getting message from child control

Posted on 1998-05-24
8
194 Views
Last Modified: 2013-11-20
Hi .. I create a class CInformation derided from CWnd
from this CInformation i create a variable which i call 'm_pEdit' and which is type of CEdit*
when the focus is set to my m_pEdit variable , how could the parent window (CInformation) knows the user type the key : -Return or Escape- from the child control ?

Please help .. i try so much stoof , AS WM_NOTIFY or other stoof like this and still didn't success ...
0
Comment
Question by:SkizoWalker
  • 5
  • 3
8 Comments
 
LVL 3

Accepted Solution

by:
tma050898 earned 70 total points
ID: 1314651
Override PreTranslateMessage in the CInformation class. Details on the way...
0
 
LVL 3

Expert Comment

by:tma050898
ID: 1314652
For the parent (CInformation) to know that Return or Escape was hit when the m_pEdit had focus.

BOOL CInformation::PreTranslateMessage(MSG* pMsg)
{  
 BOOL bHandledMsg = FALSE;

 switch (pMsg->message)
 {                      
  case WM_KEYDOWN:
      {
   // Get the CWnd* for the current child control
   CWnd* pwndCurrent = NULL;
   pwndCurrent = GetFocus();              
   // here you can compare pwndCurrent.GetSafeHwnd() to m_pEdit.GetSafeHwnd()
       // if you care that it was the m_pEdit control that had focus

   switch (pMsg->wParam)
   {
    case VK_ESCAPE:
     // your Esc code here
     bHandledMsg = TRUE;
    break;

    case VK_RETURN:  
     // your Return, or Enter code here
     bHandledMsg = TRUE;                  
    break;

    default: break;
  } // switch (pMsg->wParam)
  break;

  default: break;                  
 } // switch (pMsg->message)                  

 // continue normal translation and dispatching            
 return (bHandledMsg ? TRUE : (CInformation Base Class)::PreTranslateMessage(pMsg);
}

0
 
LVL 3

Expert Comment

by:tma050898
ID: 1314653
SkizoWalker,

Couple of corrections and comments.

I should mention that you should use ClassWizard to create a PreTranslateMessage override and then modify the PreTranslateMessage as follows. I left comments where you probably want to put your own application specific code. Lemme know if you need any additional information.

Understand that by returning TRUE from the PreTranslateMessage, you are saying that you DO NOT want processing to continue. Therefore, for example, if you placed this code into an AppWiz generated dialog-based app right now, pressing the Enter key or the Esc key would not do anything as far as dismissing the dialog. This is because the PreTranslateMessage function is "eating" those keystrokes by return TRUE. Obviously, what you do with these keys is app specific.

BOOL CInformation::PreTranslateMessage(MSG* pMsg)
{  
 BOOL bHandledMsg = FALSE;

 switch (pMsg->message)
 {                      
  case WM_KEYDOWN:
  {
   // Get the CWnd* for the current child control
   CWnd* pwndCurrent = NULL;
   pwndCurrent = GetFocus();              
   // here you can compare pwndCurrent.GetSafeHwnd() to m_pEdit.GetSafeHwnd()
   // if you care that it was the m_pEdit control that had focus

   switch (pMsg->wParam)
   {
    case VK_ESCAPE:
     // your Esc code here
     bHandledMsg = TRUE;
    break;

    case VK_RETURN:  
     // your Return, or Enter code here
     bHandledMsg = TRUE;                  
    break;

    default: break;
   } // switch (pMsg->wParam)
  } // WM_KEYDOWN
  break;

  default: break;                  
 } // switch (pMsg->message)                  

 // continue normal translation and dispatching            
 return (bHandledMsg ? TRUE : (CInformation Bas Class::PreTranslateMessage(pMsg));
}
0
 

Author Comment

by:SkizoWalker
ID: 1314654
thanx very much for such an answer .. here the points you had the real merit to win .. ur welcome ;) anyway i didn't use aPPwizard to create this class (CInformation : public Cwnd) , so what is the correct function defintion i should use ?
afx_msg BOOL PreTranslateMessage(MSG* pMsg) ? hope it gonna works ...

cya ,
Mickael
France

http://wwwperso.hol.fr/~mgilaber/ for some OpenGL / Glide sourcecode and sample of my own!

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:tma050898
ID: 1314655
No. It's a virtual function...

virtual BOOL PreTranslateMessage(MSG* pMsg);

0
 

Author Comment

by:SkizoWalker
ID: 1314656
i have troubel .. when i try to implement this method in my CWnd derived class  , it nevers calls the function PreTranslateMsg ... how could i make sure this function will be called at each message ?? !
0
 
LVL 3

Expert Comment

by:tma050898
ID: 1314657
1. Did you make the function virtual?

virtual BOOL PreTranslateMessage(MSG* pMsg);

2. How are you creating this window? IOW, can you post the code as to how you are creating and displaying this window?
0
 

Author Comment

by:SkizoWalker
ID: 1314658
okay here is the code i did :

CWndSaisie::CWndSaisie(CWnd* parent)
{
m_rect.top = 175;
m_rect.left = 160;
m_rect.right = m_rect.left + 450;
m_rect.bottom = m_rect.top + 250;

CString wndClass;
wndClass = AfxRegisterWndClass(0,NULL,(HBRUSH) (COLOR_WINDOW),NULL);


DWORD dwStyle   = WS_OVERLAPPED | WS_BORDER | WS_DLGFRAME | WS_VISIBLE | WS_CAPTION | WS_SYSMENU;
DWORD dwStyleEx = WS_EX_TOOLWINDOW;

CreateEx(dwStyleEx,wndClass,"Saisie",dwStyle,m_rect,parent,NULL);
ShowWindow(TRUE);
}

hope it could help you .

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expand macro to ask for filename column 8 37
child constructor and parent constructor, overriding and overloading 6 77
Change to event 1 100
unix example issues 18 73
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now