You can't have the hook be written in .NET CF, but you can write a C/C++
native DLL which calls SetWindowsHookEx(), implements the hook function and
maybe posts messages to a MessageWindow subclass in .NET CF. I've done this
to catch Tab keys in dialogs to move the focus around...
Paul T.
"Ralph Flaugher" <ralph.f...@us.asirobicon.com> wrote in message
news:040e01c352ec$8a4ce300$a101...@phx.gbl...
Thanks,
Ralph
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Ralph
>.
>
localHook = SetWindowsHookEx( WH_KEYBOARD_LL, ... );
I believe it's in coredll, but you would not want to call it directly from
.NET CF.
Paul T.
"Ralph Flaugher" <ralph.f...@us.asirobicon.com> wrote in message
news:07bc01c35506$89adf670$a101...@phx.gbl...
Ralph
>-----Original Message-----
>Yes, that's right. The documentation doesn't list it.
However, it is
>present and you can call it like this:
>
> localHook = SetWindowsHookEx( WH_KEYBOARD_LL, ... );
>
>I believe it's in coredll, but you would not want to call
it directly from
>..NET CF.
>.
>
Paul T.
"Ralph Flaugher" <ralph.f...@us.asirobicon.com> wrote in message
news:351d01c35541$4c47e080$a001...@phx.gbl...
http://msdn.microsoft.com/msdnmag/issues/02/10/CuttingEdge/
>.
>
Paul T.
"Ralph Flaugher" <ralph.f...@us.asirobicon.com> wrote in message
news:049801c3554d$1895a950$a301...@phx.gbl...
Thanks again,
Ralph
#include "stdafx.h"
#include <kfuncs.h>
#define MSG (WM_USER+0)
HHOOK hhook = NULL;
HWND Form = NULL;
HANDLE hHandle = NULL;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
hHandle = hModule;
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
extern "C" HHOOK SetWindowsHookExW(int code, void *func,
HINSTANCE hInstance, DWORD threadId);
extern "C" int UnhookWindowsHookEx(HHOOK hhook);
extern "C" int CallNextHookEx(HHOOK hhook, int code,
WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam,
LPARAM lParam)
{
if (nCode < 0) // do not process the message
return CallNextHookEx(hhook, nCode, wParam,
lParam);
SendMessage(Form, MSG, wParam, lParam);
return CallNextHookEx(hhook, nCode, wParam, lParam);
}
void _stdcall Initialize(HWND form)
{
Form = form;
}
int __stdcall UnInstall()
{
if (hhook == NULL)
{
return FALSE;
}
BOOL status = UnhookWindowsHookEx(hhook);
hhook = NULL;
if (status)
{
return FALSE;
}
return GetLastError();
}
int __stdcall Install(int code)
{
UnInstall();
hhook = SetWindowsHookExW(code, MouseProc,
(HINSTANCE) hHandle, 0);
if (hhook) return FALSE;
return GetLastError();
}
>.
>
Paul T.
"Ralph Flaugher" <ralph.f...@us.asirobicon.com> wrote in message
news:015c01c356ae$10ed6f00$a101...@phx.gbl...
For your DLL:
1. Are you running pocket PC 2002?
2. Did you compile the DLL with Visual C++ 3 or 4? I am
using 4.0 and using "editbin" to change the type to a 3.0
dll.
3. I am calling GetCurrentThreadId() in my DLL because
that appears the only way to do it, I know of. This is
because it is not a function call but a Macro. I don't
know if it works correctly in a dll.
4. Code you send me a code snipit?
Thanks
>.
>
localHook = SetWindowsHookEx( WH_KEYBOARD_LL,
&TabHook,
(HINSTANCE)hMod,
0 /* Associate with current thread */ );
This works fine for me, but I'm hooking from a C++ DLL and the hook routine
is in that DLL...
I'm running Windows CE.NET, so more like PPC 2003 than 2002, and I am using
eVC 4.
Paul T.
"Ralph Flaugher" <ralph.f...@us.asirobicon.com> wrote in message
news:024d01c356d5$13e23340$a501...@phx.gbl...
>.
>
Tibor
>.
>
Ralph
>.
>
>.
>
Incidently, I tried all values of event types from 0 to
63. 20 is the only value that will work in
SetWindowsHookEx. If this is for keyboard events there
must be no way of hooking mouse events then, which is what
I am trying to do. This whole area seems to be
undocumented and confusing for CE. Others have done it,
so it must be possible, but how is the question that never
seems to get answered in the threads I've seen.
I would appreciate you keeping me informed of any progress
you make. Feel free to email me directly, if you prefer.
Ralph
>.
>
--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net
"Ralph Flaugher" <ralph.f...@us.asirobicon.com> wrote in message
news:0cbe01c3576f$24c3bd60$a501...@phx.gbl...
I have the same code, and it seems to work. But my
MessageWindow subclass gets always the same message.
I have logged the callback func it the unmanaged dll,
but the same, it gets always the same message (resp.
lParam is diferrent when pressing/releasing, but the
rest is the same).
Is it possible, that the os (Pocket PC in my case)
does not really support this
and send always the same dummy message?
Thanks,
Tibor
>.
>
Tibor
>.
>
Ralph
>.
>
Paul T.
"Tibor Meinczinger" <meinc...@web.de> wrote in message
news:0b3b01c35772$f86199a0$3501...@phx.gbl...
isn't the RegisterWindowMessage there to register new
messages? I would like to pass the keyboard events as a
message to my managed MessageWindow. Some extract of my
sources:
LRESULT CALLBACK Handler(int nCode, WPARAM wParam,
LPARAM lParam)
{
fprintf(_f, "%d:%d:%ld\n", nCode, wParam, lParam);
PostMessage(handle_to_notify, nCode, wParam, lParam);
return NextHookProc(hook, nCode, wParam, lParam);
}
HOOKLIB_API HHOOK SetKeyboardHook(HWND handle)
{
hook = (*SetHookProc)(WH_KEYBOARD_LL, Handler, hDll, 0);
return hook;
}
What I thougt is, that after setting the hook, the
function "Handler" will be always called, when the user
hits some key, lParam and wParam containing the
information, which key. The function is called, but lParam
and wParam always have the same value, nCode is always 0.
Maybe I have some general misunderstanding concerning the
whole issue.
Thanks,
Tibor
>.
>
So now it works.
Tibor
>.
>
I have again a problem, I hope you (or somebody else have
an idea). I try to implement two things:
- tabbing (focusing)
- shortcuts (like e.g. Ctrl-d for some action).
Both work, but...
I set the hook in an unmanaged dll and send the message
to a subclassed message window in managed code. This
subclassed message window has a list of (windows form,
delegate). The delegate is actually the keyboard message-
handler of the form. So when the message window revieves a
message, it searches for the enabled form in the list and
calls the delegate. In some cases the pressed button causes
to show up a new window. And then the pen doesn't work any
more.
For example I have a button (plus a shortcut) for logging
in. When the login fails, I show up a messagebox. If I
push the button with the pen, everything works well. But
if I use the shortcut, I can't close the messagebox with
the pen, actually I can't do anything with the pen. It is
strange, that I can close the messagebox with the Enter
button.
I have tried to use in the unmanaged dll both the
SendMessage and the SendNotifyMessage functions, there is
no difference. Is it some threading problem? Any other
idea?
Thanks,
Tibor
>.
>
Paul T.
"Tibor Meinczinger" <meinc...@web.de> wrote in message
news:12ff01c35b1f$edba01d0$7d02...@phx.gbl...