Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Intercepting WM_CHAR before TranslateMessage - how to read lParam

266 views
Skip to first unread message

jonatha...@gmail.com

unread,
Oct 12, 2008, 10:10:55 PM10/12/08
to
Hey I'm experimenting on how to translate messages for myself, sort of
uncover the mystery behind the message loop. I'm having trouble
understanding the WM_CHAR message that is sent. I've read the MSDN
page for it (http://msdn.microsoft.com/en-us/library/ms646276.aspx)
but it's not much help on how to take lParam apart. If anyone could
give me some help with dissecting the message loop I'd really
appreciate it. Thanks in advance, oh and here's some code from what I
plan on using this information for (accelerator keys).

ACCEL preLoadHK[2];

/*
typedef struct {
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
} MSG, *PMSG;
*/

BOOL PongsAccel(HWND hwnd, ACCEL *HKTable, int size, MSG *msg)
{
BOOL pass = FALSE;

if(size > 0)
{
if(HKTable != NULL)
{
if((*msg).message == WM_CHAR)
{
/*Translate keys being pressed, CTRL+X or X or ALT+X*/
}
}
}
return pass;
}

...


while ( (bRet = GetMessage(&messages, (HWND) NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
// Check for accelerator keystrokes.
if (!PongsAccel(hwnd, &preLoadHK,
ARRAYSIZE(preLoadHK),&messages))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
}
}

Markus Schaaf

unread,
Oct 13, 2008, 5:11:22 PM10/13/08
to
jonatha...@gmail.com wrote:
> Hey I'm experimenting on how to translate messages for myself, sort of
> uncover the mystery behind the message loop. I'm having trouble
> understanding the WM_CHAR message that is sent. I've read the MSDN
> page for it (http://msdn.microsoft.com/en-us/library/ms646276.aspx)
> but it's not much help on how to take lParam apart.

The numbers in lParam's description are bit positions. To get the
scan code for instance, you would use `(lParam >> 16) & 0xff`. Also
your subject is nonsense. TranslateMessage generates WM_CHAR
messages from WM_KEYDOWN.

sudheer

unread,
Oct 14, 2008, 2:07:12 AM10/14/08
to

Hi,

when you press a key a WM_KEYDOWN is generated (having the virtual key
code) then a WM_CHAR is sent which has the key value (ASCII/UNICODE)
the a WM_KEYUP is generated.

u can use filtermessage for message and u can use key board hook proc
for controlling the messages(i mean the input)

please let me know what r u lookingh for in detail ...I will be glad
to help

jonatha...@gmail.com

unread,
Oct 14, 2008, 3:47:37 PM10/14/08
to
Thanks alot, this was a lot of help... A bit more information is:

1. Is there a site that can tell me which messages TranslateMessage
creates and which one's are in the MSG structure
2. A tutorial on working with the bits, don't really understand the
"(lParam >> 16) & 0xff", get most of it, but want to know everything I
can do with bits
3. Is there any way to peek at the messages that programs are sending
within there message loop...programs that are not owned by you.
i.e I have my program hidden, a user has a notepad open and they
write "~Program~@pen", My program which is peeking at the notepad
records the key
actions and shows the window... Though I know this could be
used for viruses and such, so I guess it wouldn't be very safe for
windows to allow this...What
about just reading keyboard actions (I've read something about
capturing the mouse, is there one for the keyboard?)
4.a Port monitoring/sending messages, so that programs can read
messages (This one is a big one I know....Really hard for MSDN to give
me straight
answers...addrs would be nice)
4.b This is an extension, I'm trying to monitor all out going messages
from my computer, is there anyway I could catch a glimpse at these
messages and copy
them to a buffer?

sudheer

unread,
Oct 14, 2008, 3:56:03 PM10/14/08
to

ok..
one thing you do
u can download the source of freedownloadmanager from sf.net
u will find most of the source you needed.
AFAIK MSDN is the best.
also u can download a network monitoring tool from sf.net
u can c the source.Its the only way to learn.
if possible i will send you sm file u may find them helpful.

jonatha...@gmail.com

unread,
Oct 15, 2008, 4:24:25 PM10/15/08
to
I'm downloading the newest version of windows SDK, and I got the
source of "free download manager". If I need help with networks where
should I go to learn more about them, I doubt win32 can offer
everything I need for networks, what languages should I be looking
for...And one last question (concerning win32) is there a site that
offers windows...that sounds horrible, I'm into subclassing windows
(edit, list...), or just making my own windows (with there own set of
commands) but its getting annoying to make a whole new window class
(is my terminology correct?), so I'm looking for a place that offers
pre-written (portable of course) code for windows....I hate not
knowing the term for what I'm trying to say, hope you understand if
not I'll try again a different way, with examples
thanks for all the help, just saved my school marks, as well as my
sanity
0 new messages