mfc >> Keyboard Messages not intercepted when PreTranslateMessage is used

by punitparikh » Thu, 20 Jan 2005 13:25:59 GMT

Hi

Mine is a MFC ActiveX Ctrl. I am using PreTranslateMessage as follows
so that keystrokes like backspace can be detected in IE, but though
SendMessage gets called, the Keystrokes like Arrow keys, delete
backspace don't function at all in
ActiveX container as well as IE. Am I missing something or do I need
to explicitly write WM_KEYDOWN (KEYUP) message handlers? Please let me know.

BOOL CMegafleetPluginCtrl::PreTranslateMessage(MSG* pMsg)
{

switch (pMsg->message)
{
case WM_KEYDOWN:
case WM_KEYUP:
switch (pMsg->wParam)
{
case VK_UP:
case VK_DOWN:
case VK_LEFT:
case VK_RIGHT:
case VK_HOME:
case VK_BACK:
case VK_DELETE:
SendMessage (pMsg->message, pMsg->wParam, pMsg->lParam);
// Windowless controls won't be able to call
SendMessage.
// Instead, just respond to the message here.
return TRUE;

}
break;
}
return COleControl::PreTranslateMessage(pMsg);
}

Thanks,
Punit


mfc >> Keyboard Messages not intercepted when PreTranslateMessage is used

by punitparikh » Tue, 01 Feb 2005 20:03:50 GMT


Got it working. The control now responds to keys like
backspace,delete,tab etc in ActiveX Container as well as IE.
Now i override PreTranslateMessage as follows: ( with reference to some
other posts on MFC related groups)

BOOL CMegafleetPluginCtrl::PreTranslateMessage(MSG* pMsg)
{
bool isHandledNow = false;

if (IsDialogMessage (pMsg))
return true;

else
return COleControl::PreTranslateMessage(pMsg);
}

it seems too be working fine...

Thanks,
Punit




Similar Threads

1. Using SoapExtensions to intercept and decrypt MIME formatted SOAP messages

Hi,

Please bear with me as I have only 1 weeks .NET experience.

I am using VB.NET to write a stand-alone client application that
connects to a Web service.  I successfully send a request for a list
of items (i.e. getItemList), and successfully receive the list.  I
then send a request for individual items from the list (i.e. getItem),
and successfully receive the item.

The situation is that the individual item/SOAP response contains
multipart MIME sections.

I would like to intercept (using SoapExtensions) the SOAP message
before it is deserialized and be able to decode the MIME sections,
before sending the SOAP message onto the deserializer.

I know I must intercept and decode the MIME as the deserializer
complains about the formatting of the SOAP message when it attempts to
read the message.  (My requests are not encoded, only the responses
for the individual items are.)

I know that I must intercept the message when the message state is
BeforeDeserialize and perform the relevant actions.

I would be grateful if anyone can point me in the right direction for
HOW to decode the MIME and send the decoded message forward onto the
deserializer.  Any examples would be greatly appreciated.

Thanks in advance.

AIM

2. Keyboard Message Not getting Processed..........

3. Keyboard Message Not getting Processed....

Hi all,

I have an WebBrowser Control on a Dialog Box

where in i have an Text Box control.

all the keys are Processed except +%,RETURN key and &

i already have a message Handler

MESSAGE_RANGE_HANDLER(WM_KEYFIRST, WM_KEYLAST, OnKeyMsg)

and Method like this

LRESULT CRightPanelDlg::OnKeyMsg(UINT uMsg, WPARAM wParam, LPARAM
lParam, BOOL& bHandled)
{
  APVU_METHOD(CRightPanelDlg,OnKeyMsg)
	HWND hWndCtlF = ::GetFocus();
	HWND hWndCtl  = hWndCtlF;

	if(IsChild(hWndCtl))
	{
		// find a direct child of the dialog from the window that has focus
		while(::GetParent(hWndCtl) != m_hWnd)
			hWndCtl = ::GetParent(hWndCtl);

		MSG msg;

		msg.hwnd    = hWndCtlF;
		msg.message = uMsg;
		msg.wParam  = wParam;
		msg.lParam  = lParam;
		msg.time    = 0;
		memset(&(msg.pt), 0, sizeof(POINT));



		if(msg.message >= WM_KEYFIRST &&
		   msg.message <= WM_KEYLAST  &&
		   (msg.wParam == VK_BACK))
			return 0;


		FILE *fp = fopen("C:\\PreTranslateMessage.txt", "ab");
		fprintf(fp, "message = %d (%04X) ", msg.message, msg.message);
		/*if (pMsg->message == WM_SYSKEYDOWN) fputs("WM_SYSKEYDOWN", fp);
		if (pMsg->message == WM_SYSKEYUP) fputs("WM_SYSKEYUP", fp);
		if (pMsg->message == WM_KEYUP) fputs("WM_KEYUP", fp);*/
		if (msg.message == WM_CHAR) fputs("WM_CHAR", fp);
		fprintf(fp, "\twParam = %d (%04X) %c\r\n", msg.wParam, msg.wParam,
msg.wParam);
		fclose(fp);






				// give control a chance to translate this message
		if(::SendMessage(hWndCtl, WM_CHAR, 0, (LPARAM)&msg) != 0)
		{
			return 1;
		}
	}

	return 0;
}


I see all the keys including +,&,and % key information in the text
file and even

SendMessage API is Processing +,&,% keys Simlar to other keys been
processed but


"Note:+,&,%  keys never Appear on the Text Control Hosted by the
WebBrowser"

but iam Sure all the Keys are Handled Properly in this Function

I tried to Override PreTranslateMessag API but the method is never
called while Execution.

It would be nice if i get a clue What might be going wrong here......

4. keyboard input messages can NOT be received...

5. Intercepting keyboard event

Hi to everyone,
I have a problem in a MFC application...I hope this is the right
newsgroup and that someone would help me :-)

In my MFC application I have a CFormView that contains an ActiveX
control (actually MapPoint Control).
I have created this Control class by means of the class wizard,
selecting "create an MFC class from an ActiveX control": the wizard has
generated a ccontrol1.h file, containing "wrapped" (is right?) method.

My problem is that I want intercept keyboard event, while the control
is running:

I have tried to use the

CControl1::OnKeyDown()

event, but it works only if the control isn't still executing...
I explain: when I load a map into the control, the control itself loose
focus (OnKillFocus event is called) and OnKeyDown() doesn't work.

Is there a way to "intercept" keyboard event, maybe from a higher
level??? I have read that keyboard events go to the component that has
focus....but I'm not able to understand which is it.

I have tried the following code to understand which control gain focus:

void CControl1::OnKillFocus(CWnd* pNewWnd)
{
	int ctrlID = pNewWnd->GetDlgCtrlID(); // 59648
}

The method gives me that int value when I have loaded a map in the
control and I click the first time into it. It seems that the MapPoint
ActiveX control "internal engine" takes focus (and gain keyboard
control)...


Would someone give me a hint to solve this problem?

Or giving me the right newsgroup to post this message, if this is the
wrong one???

Many many thanks!!!

HS

6. Intercept Keyboard events - Windows CE

7. Parameter as reference but I am not using "ref"

Hi,

In the follow program I would like to have the parameter "c" in method
"doSomething" as a value parameter, but it's running as a reference
parameter. Why?  How can I get parameter "c" as a value (or clone,
copy)?

Current result:
value1
value2

Expected result:
value1

class Program
{
        static void Main(string[] args)
        {
                SqlCommand sqlCommandSelect = new SqlCommand();
                sqlCommandSelect.Parameters.AddWithValue("@col1",
"value1");
                doSomething(sqlCommandSelect.Parameters);

                foreach (SqlParameter param in
sqlCommandSelect.Parameters)
                {
                        Console.WriteLine(param.Value);
                }
                Console.ReadLine();
        }

        private static void doSomething(SqlParameterCollection c)
        {
                c.AddWithValue("@col2", "value2");
                //I want to use the new value only here
        }

}

8. Well not exactly MFC....though I am using it in MFC :)