Intercepting Win32 Messages - Control Looses Properties

  • Thread starter Christopher Pragash
  • Start date
C

Christopher Pragash

Hello All,

I am working on a Pocket PC 2003 device with a keyboard built into it. My
requirement is to capture key press events on each control (textbox,
checkbox, list box, etc). I tried capturing the OnKeyDown event for each
control, but could not achieve the behavior I expected - the up and down
arrow key presses were not captured using this event for check boxes. My
next approach was to intercept win32 messages - based on the article
http://msdn.microsoft.com/msdnmag/issues/04/04/KeyboardSupport/default.aspx
/ another source is the Yao Durant compact .net programming book chapter 9
which has a similar sample, but on both the samples I had the same problem.
The control is able to intercept key messages - but it looses properties
such as text values or checked values etc. A simple textbox1.text shows up a
blank value where as the designer shows the textbox with a value "Textbox1".
I narrowed down the problem to a specific function call - the control losses
its properties when a handle of that window is passed to a native dll
interceptor written in MFC or C++. Any thoughts or suggestions would be
really really helpful.

Thanks in advance.

Regards,
Chris
 
C

Christopher Pragash

Paul,

Following is my code. The behavior is that the control displays the textbox
value the first time (see Level 1 messagebox) but does not display the value
after the handle has been passed on to the native dll (see Level 2 message
box). I am not able to retrieve any values such as checked property for the
checkbox or text property for the textbox. The native dll is the one that is
explained in the article
http://msdn.microsoft.com/msdnmag/issues/04/04/KeyboardSupport/default.aspx
or another version of that is in the Yao Durant book (chapter 9). Please let
me know if you need any further clarification. Thanks for your response. Any
thoughts here?

Public Sub Initialize()
Dim con As Control

For Each con In m_lstControls 'Array List consisting of all the controls
in the form

'con.Focus()

'Dim handle As IntPtr = GetFocus()

Dim x As Integer = con.Top + m_frm.Top

Dim y As Integer = con.Left + m_frm.Left

Dim handle As IntPtr = WindowFromPointYX(y, x)

m_lstHandles.Add(handle)

'Level 1 messageBox

if con.gettype is gettype(textbox) then

msgbox con.text

end if

'Pass handle to C++/MFC native Dll for intercepting messages

CreateEventGrabber(handle, Message.Create(handle, 0, IntPtr.Zero,
IntPtr.Zero).HWnd)

SetEventFlags(handle, EVENT_KEYDOWN)

'Level 2 Message box

if con.gettype is gettype(textbox) then

msgbox con.text

end if

Next

End Sub

- Chris
 
P

Paul G. Tobey [eMVP]

Nothing just jumps right out at me. When you run this in the debugger,
you're saying that this code:
'Level 1 messageBox

if con.gettype is gettype(textbox) then

executes the if..then contents, but this code:
'Level 2 Message box

if con.gettype is gettype(textbox) then

does *not*? So the value returned from con.gettype() has changed? Are you
setting breakpoints in the message window message handler? What messages
are sent when that gettype property is accessed?

Paul T.
 
C

Christopher Pragash

Paul,

Again - thanks for the response. The code does not change the "gettype" but
the "text" value is EMPTY at the second level (ie after the control handle
has been passed on to the Native DLL). That piece of code is passes the
handle of each control on the form to a native DLL (C++ or MFC) for hooking
on to the Win32 message system and I am attempting to trap Keyboard events
at the win32 level. Once the handle is passed to the native dll, the control
looses its "Text" value!!! Any thoughts?

Thanks,
Chris
 
P

Paul G. Tobey [eMVP]

Well, I'm sure that .Text simply sends a WM_GETTEXT to the control so my
guess is that you're cutting that off, causing it to act like there was no
text. Again, judicious use of the debugger is needed!

Paul T.

Christopher Pragash said:
Paul,

Again - thanks for the response. The code does not change the "gettype"
but
the "text" value is EMPTY at the second level (ie after the control handle
has been passed on to the Native DLL). That piece of code is passes the
handle of each control on the form to a native DLL (C++ or MFC) for
hooking
on to the Win32 message system and I am attempting to trap Keyboard events
at the win32 level. Once the handle is passed to the native dll, the
control
looses its "Text" value!!! Any thoughts?

Thanks,
Chris

Paul G. Tobey said:
Nothing just jumps right out at me. When you run this in the debugger,
you're saying that this code:
'Level 1 messageBox

if con.gettype is gettype(textbox) then

executes the if..then contents, but this code:
'Level 2 Message box

if con.gettype is gettype(textbox) then

does *not*? So the value returned from con.gettype() has changed? Are you
setting breakpoints in the message window message handler? What messages
are sent when that gettype property is accessed?

Paul T.

Christopher Pragash said:
Paul,

Following is my code. The behavior is that the control displays the
textbox
value the first time (see Level 1 messagebox) but does not display the
value
after the handle has been passed on to the native dll (see Level 2 message
box). I am not able to retrieve any values such as checked property for
the
checkbox or text property for the textbox. The native dll is the one that
is
explained in the article
http://msdn.microsoft.com/msdnmag/issues/04/04/KeyboardSupport/default.aspx
or another version of that is in the Yao Durant book (chapter 9).
Please
let
me know if you need any further clarification. Thanks for your
response.
Any
thoughts here?

Public Sub Initialize()
Dim con As Control

For Each con In m_lstControls 'Array List consisting of all the
controls
in the form

'con.Focus()

'Dim handle As IntPtr = GetFocus()

Dim x As Integer = con.Top + m_frm.Top

Dim y As Integer = con.Left + m_frm.Left

Dim handle As IntPtr = WindowFromPointYX(y, x)

m_lstHandles.Add(handle)

'Level 1 messageBox

if con.gettype is gettype(textbox) then

msgbox con.text

end if

'Pass handle to C++/MFC native Dll for intercepting messages

CreateEventGrabber(handle, Message.Create(handle, 0,
IntPtr.Zero,
IntPtr.Zero).HWnd)

SetEventFlags(handle, EVENT_KEYDOWN)

'Level 2 Message box

if con.gettype is gettype(textbox) then

msgbox con.text

end if

Next

End Sub

- Chris

"Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam DOT
com>
wrote in message "Loses its properties"? That doesn't have an obvious meaning, so you're
going to have to tell us what you mean by that. When you call this
function, what, exactly, happens? The value of the .Text property of an
edit control changes? I doubt that!

Paul T.

Hello All,

I am working on a Pocket PC 2003 device with a keyboard built into it.
My requirement is to capture key press events on each control
(textbox, checkbox, list box, etc). I tried capturing the OnKeyDown
event for each control, but could not achieve the behavior I
expected
- the up and down arrow key presses were not captured using this event
for check boxes. My next approach was to intercept win32 messages -
based on the article

http://msdn.microsoft.com/msdnmag/issues/04/04/KeyboardSupport/default.aspx
/ another source is the Yao Durant compact .net programming book
chapter 9 which has a similar sample, but on both the samples I had
the same problem. The control is able to intercept key messages -
but
it looses properties such as text values or checked values etc. A
simple textbox1.text shows up a blank value where as the designer
shows the textbox with a value "Textbox1". I narrowed down the problem
to a specific function call - the control losses its properties when a
handle of that window is passed to a native dll interceptor written in
MFC or C++. Any thoughts or suggestions would be really really
helpful.

Thanks in advance.

Regards,
Chris




Hello All,

I am working on a Pocket PC 2003 device with a keyboard built into it. My
requirement is to capture key press events on each control (textbox,
checkbox, list box, etc). I tried capturing the OnKeyDown event for each
control, but could not achieve the behavior I expected - the up and down
arrow key presses were not captured using this event for check boxes. My
next approach was to intercept win32 messages - based on the article

http://msdn.microsoft.com/msdnmag/issues/04/04/KeyboardSupport/default.aspx
/ another source is the Yao Durant compact .net programming book chapter
9
which has a similar sample, but on both the samples I had the same
problem.
The control is able to intercept key messages - but it looses properties
such as text values or checked values etc. A simple textbox1.text
shows
up
a
blank value where as the designer shows the textbox with a value
"Textbox1".
I narrowed down the problem to a specific function call - the control
losses
its properties when a handle of that window is passed to a native dll
interceptor written in MFC or C++. Any thoughts or suggestions would be
really really helpful.

Thanks in advance.

Regards,
Chris
 
C

Chris Tacke, eMVP

So once the control is hooked by your DLL, how are you getting notified of
messages (like WM_GETTEXT in this case)?

--
<ctacke/>
www.opennetcf.org/sdf
Winner of the 2004 Pocket PC Magazine Best Software award


Christopher Pragash said:
Paul,

Again - thanks for the response. The code does not change the "gettype"
but
the "text" value is EMPTY at the second level (ie after the control handle
has been passed on to the Native DLL). That piece of code is passes the
handle of each control on the form to a native DLL (C++ or MFC) for
hooking
on to the Win32 message system and I am attempting to trap Keyboard events
at the win32 level. Once the handle is passed to the native dll, the
control
looses its "Text" value!!! Any thoughts?

Thanks,
Chris

Paul G. Tobey said:
Nothing just jumps right out at me. When you run this in the debugger,
you're saying that this code:
'Level 1 messageBox

if con.gettype is gettype(textbox) then

executes the if..then contents, but this code:
'Level 2 Message box

if con.gettype is gettype(textbox) then

does *not*? So the value returned from con.gettype() has changed? Are you
setting breakpoints in the message window message handler? What messages
are sent when that gettype property is accessed?

Paul T.

Christopher Pragash said:
Paul,

Following is my code. The behavior is that the control displays the
textbox
value the first time (see Level 1 messagebox) but does not display the
value
after the handle has been passed on to the native dll (see Level 2 message
box). I am not able to retrieve any values such as checked property for
the
checkbox or text property for the textbox. The native dll is the one that
is
explained in the article
http://msdn.microsoft.com/msdnmag/issues/04/04/KeyboardSupport/default.aspx
or another version of that is in the Yao Durant book (chapter 9).
Please
let
me know if you need any further clarification. Thanks for your
response.
Any
thoughts here?

Public Sub Initialize()
Dim con As Control

For Each con In m_lstControls 'Array List consisting of all the
controls
in the form

'con.Focus()

'Dim handle As IntPtr = GetFocus()

Dim x As Integer = con.Top + m_frm.Top

Dim y As Integer = con.Left + m_frm.Left

Dim handle As IntPtr = WindowFromPointYX(y, x)

m_lstHandles.Add(handle)

'Level 1 messageBox

if con.gettype is gettype(textbox) then

msgbox con.text

end if

'Pass handle to C++/MFC native Dll for intercepting messages

CreateEventGrabber(handle, Message.Create(handle, 0,
IntPtr.Zero,
IntPtr.Zero).HWnd)

SetEventFlags(handle, EVENT_KEYDOWN)

'Level 2 Message box

if con.gettype is gettype(textbox) then

msgbox con.text

end if

Next

End Sub

- Chris

"Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam DOT
com>
wrote in message "Loses its properties"? That doesn't have an obvious meaning, so you're
going to have to tell us what you mean by that. When you call this
function, what, exactly, happens? The value of the .Text property of an
edit control changes? I doubt that!

Paul T.

Hello All,

I am working on a Pocket PC 2003 device with a keyboard built into it.
My requirement is to capture key press events on each control
(textbox, checkbox, list box, etc). I tried capturing the OnKeyDown
event for each control, but could not achieve the behavior I
expected
- the up and down arrow key presses were not captured using this event
for check boxes. My next approach was to intercept win32 messages -
based on the article

http://msdn.microsoft.com/msdnmag/issues/04/04/KeyboardSupport/default.aspx
/ another source is the Yao Durant compact .net programming book
chapter 9 which has a similar sample, but on both the samples I had
the same problem. The control is able to intercept key messages -
but
it looses properties such as text values or checked values etc. A
simple textbox1.text shows up a blank value where as the designer
shows the textbox with a value "Textbox1". I narrowed down the problem
to a specific function call - the control losses its properties when a
handle of that window is passed to a native dll interceptor written in
MFC or C++. Any thoughts or suggestions would be really really
helpful.

Thanks in advance.

Regards,
Chris




Hello All,

I am working on a Pocket PC 2003 device with a keyboard built into it. My
requirement is to capture key press events on each control (textbox,
checkbox, list box, etc). I tried capturing the OnKeyDown event for each
control, but could not achieve the behavior I expected - the up and down
arrow key presses were not captured using this event for check boxes. My
next approach was to intercept win32 messages - based on the article

http://msdn.microsoft.com/msdnmag/issues/04/04/KeyboardSupport/default.aspx
/ another source is the Yao Durant compact .net programming book chapter
9
which has a similar sample, but on both the samples I had the same
problem.
The control is able to intercept key messages - but it looses properties
such as text values or checked values etc. A simple textbox1.text
shows
up
a
blank value where as the designer shows the textbox with a value
"Textbox1".
I narrowed down the problem to a specific function call - the control
losses
its properties when a handle of that window is passed to a native dll
interceptor written in MFC or C++. Any thoughts or suggestions would be
really really helpful.

Thanks in advance.

Regards,
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top