Link to home
Start Free TrialLog in
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
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

try to use PostMessage() instead of SendMessage()
Avatar of iphone
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?

I think it get the focus because it is the last control being created, maybe you can manually set focus to another control.
Avatar of 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
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial