Solved

ListView VK_F5 WM_NOTIFY

Posted on 2007-03-27
5
1,116 Views
Last Modified: 2013-12-04
My app is a win32 app written in C++. I have a SysListView32 in a window and I need to get notification when the user presses the F5 key. With Spy++ I can see that the ListView window is seeing the WM_KEYDOWN for VK_F5, but this information is not being sent back to the partent window handler (ie MY code). I've tried to look for it in a WM_NOTIFY message, but the ListView does not seem to send that to me for an F5 key press. Any ideas?
0
Comment
Question by:dddogget
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 18801954
Brute force: Hook into the SysListView32's message processing using a local "WH_KEYBOARD" or "WH_GETMESSAGE" hook, e.g.

HHOOK       g_hhk   =   NULL;
HWND        g_hwndNotify = NULL;

LRESULT CALLBACK HookProc   (   int     nCode,  // hook code
                                WPARAM  wParam, // removal flag
                                LPARAM  lParam  // address of structure with message
                            )
{
    PMSG    pmsg    =   ( PMSG) lParam;

    if  (   0   >   nCode   ||  PM_NOREMOVE ==  wParam)
        {
            return  (   CallNextHookEx  (   g_hhk,
                                            nCode,
                                            wParam,
                                            lParam
                                        )
                    );
        }

    if  (       WM_KEYDOWN  ==  pmsg->message
            ||  WM_KEYUP    ==  pmsg->message  
        )
        {

            g_iMap  =   g_map.find  (   pmsg->wParam);

            if  (   VK_F5 == pmsg->wParam) PostMessage ( g_hwndNotify, /* other parameters here */);
        }

    return  (   CallNextHookEx  (   g_hhk,
                                    nCode,
                                    wParam,
                                    lParam
                                )
            );
}

LONG InitHook   ( HWND hwndNotify)
{


    if  (   g_hhk)  return  (   ERROR_ALREADY_EXISTS);

    g_hwndNotify = hwndNotify;

    g_hhk   =   SetWindowsHookEx    (   WH_GETMESSAGE,
                                        ( HOOKPROC) HookProc,
                                        0,
                                        0
                                    );
    return 0;
}

For more on hooks, see http://msdn2.microsoft.com/en-us/library/ms997537 ("Win32 Hooks")
0
 
LVL 86

Expert Comment

by:jkr
ID: 18801958
Ooops, please ignore the line 'g_iMap  =   g_map.find  (   pmsg->wParam);'
0
 
LVL 86

Accepted Solution

by:
jkr earned 125 total points
ID: 18802170
Hn, actually, you should filter for the SysListView32's HWND. Then that should be

HOOK       g_hhk   =   NULL;
HWND        g_hwndNotify = NULL;
HWND        g_hwndToWatch = NULL;

LRESULT CALLBACK HookProc   (   int     nCode,  // hook code
                                WPARAM  wParam, // removal flag
                                LPARAM  lParam  // address of structure with message
                            )
{
    PMSG    pmsg    =   ( PMSG) lParam;

    if  (   0   >   nCode   ||  PM_NOREMOVE ==  wParam || pmsghWnd != g_hwndToWatch)
        {
            return  (   CallNextHookEx  (   g_hhk,
                                            nCode,
                                            wParam,
                                            lParam
                                        )
                    );
        }

    if  (       WM_KEYDOWN  ==  pmsg->message
            ||  WM_KEYUP    ==  pmsg->message  
        )
        {

            if  (   VK_F5 == pmsg->wParam) PostMessage ( g_hwndNotify, /* other parameters here */);
        }

    return  (   CallNextHookEx  (   g_hhk,
                                    nCode,
                                    wParam,
                                    lParam
                                )
            );
}

LONG InitHook   ( HWND hwndNotify, HWND hwndToWatch)
{


    if  (   g_hhk)  return  (   ERROR_ALREADY_EXISTS);

    g_hwndNotify = hwndNotify;
    g_hwndToWatch = hwndToWatch

    g_hhk   =   SetWindowsHookEx    (   WH_GETMESSAGE,
                                        ( HOOKPROC) HookProc,
                                        g_hThisDll,
                                        0
                                    );
    return 0;
}
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 125 total points
ID: 18806083
>>>>> Brute force: Hook into the SysListView32's message

If using MFC it's much easier to overload your dialog or view class PreTranslateMessage member function. Here you'll get all keyboard message before they are dispatched to the controls.

If not using MFC you might change the message loop of your parent's window. Here you should have something like

    while (GetMessage(..))
    {
          TranslateMessage(...);
          DispatchMessage(...);
    }

There you may filter any keyboard message before it is transferred to the controls.

Regards, Alex
0
 

Author Comment

by:dddogget
ID: 18845735
I appreciate both solutions. While both look like they should work, I implented teh one from "itsmeandnobodyelse" because of it's simplicity. Generally, 10 lines of code is better than 30.

Much thanks to both!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question