Solved

Getting message from child control

Posted on 1998-05-24
8
193 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

707 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

12 Experts available now in Live!

Get 1:1 Help Now