?
Solved

Getting message from child control

Posted on 1998-05-24
8
Medium Priority
?
200 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
[X]
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
  • 5
  • 3
8 Comments
 
LVL 3

Accepted Solution

by:
tma050898 earned 280 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
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

800 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