Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Getting message from child control

Posted on 1998-05-24
8
197 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.

840 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