Avatar of iphone
iphone
 asked on

How to sendmessage to parent pretranslatemessage?

I created a edit box with the follow code:

HWND hEdit = CreateWindowEx(
                        0,
                        L"EDIT",
                        L"",
                        WS_VISIBLE | WS_CHILD | WS_TABSTOP,
                        GLOBAL_bgX+535,
                        GLOBAL_bgY+702,
                        35,
                        17,
                        AfxGetApp()->GetMainWnd()->m_hWnd,
                        (HMENU)ID_EDITT,
                        (HINSTANCE)GetWindowLong(AfxGetApp()->GetMainWnd()->m_hWnd,GWL_HINSTANCE),
                        NULL);
      
                  OldEdit = (WNDPROC) SetWindowLong(hEdit,GWL_WNDPROC,(LPARAM)EditProc);

And below are the proc code:

LRESULT CALLBACK EditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
            
      if(message == WM_KEYDOWN && wParam == VK_RETURN){            
                MessageBox(L"aaa",L"sdfdsf",MB_OK);
            SendMessage(hWnd,WM_COMMAND,MAKELONG(ID_EDITT,VK_RETURN),(LPARAM)hWnd);                  
      }

      return CallWindowProc(OldEdit,hWnd,message,wParam,lParam);
}

And i have :

BOOL CMFCBookReaderDlg::PreTranslateMessage(MSG* pMsg)
{

case WM_COMMAND:
            {                  
                  TCHAR textBoxValue[50];
                  char textBoxInt[50];
                  GetDlgItemText(ID_EDITT, textBoxValue,50);

                  MessageBox(L" bbb",L"sdfdsf",MB_OK);
                  
                  if (LOWORD(pMsg->wParam)==ID_EDITT && HIWORD(pMsg->wParam) == VK_RETURN)
                  {
                                      MessageBox(L"ccc",L"sdfdsf",MB_OK);
                  }
                  return 0;
            }
}

===================

I got the message show aaa, but not for bbb and ccc, meaning the msg does not send to the pretranslatemessage. Can anyone tell me what is wrong in this code? I know some people would said why not using CEdit. Because i was translate the application from win32api code to MFC.

Thanks in advance
System Programming

Avatar of undefined
Last Comment
Jaime Olivares

8/22/2022 - Mon
Jaime Olivares

try to use PostMessage() instead of SendMessage()
iphone

ASKER
That solve my problem.....but i have another problem here.

This is the only edit box in my MFC APP, and when the application start it will automatically focus on this edit box. This is an simple application which have some image draw on the HDC and then will move around following mouse pointer, with using GDI++.

Is there anyway to avoid focusing to editbox?

Jaime Olivares

I think it get the focus because it is the last control being created, maybe you can manually set focus to another control.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
iphone

ASKER
This is the only control i have in the application
In Win32app it was alright but in MFC it focus on this only control
ASKER CERTIFIED SOLUTION
Jaime Olivares

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question