CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2009
    Posts
    61

    CALLBACK errror on class

    #include "stdafx.h"
    #define _WIN32_WINNT 0x0500
    #include <windows.h>
    #include <stdio.h>

    HHOOK g_hMouseHook;
    class CHECK
    {
    public:
    LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
    };

    LRESULT CALLBACK CHECK::LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
    {
    if (nCode >= 0)
    {
    PMSLLHOOKSTRUCT pmll = (PMSLLHOOKSTRUCT) lParam;
    printf("msg: %lu, x:%ld, y:%ld\n", wParam, pmll->pt.x, pmll->pt.y);
    switch (wParam)
    {
    case WM_MBUTTONDOWN:
    ShowCursor(FALSE);
    break;

    case WM_MBUTTONUP:
    ShowCursor(TRUE);
    break;
    }
    }

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


    int _tmain(int argc, _TCHAR* argv[])
    {
    MSG msg;
    g_hMouseHook = SetWindowsHookEx( WH_MOUSE_LL, &CHECK::LowLevelKeyboardProc, GetModuleHandle(NULL), 0 );
    if (!g_hMouseHook) printf("err: %d\n", GetLastError());
    while ( GetMessage(&msg, NULL, 0, 0) )
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    UnhookWindowsHookEx(g_hMouseHook);
    return (int) msg.wParam;
    }


    Here i am getting error
    cannot convert parameter 2 from 'LRESULT (__stdcall CHECK::* )(int,WPARAM,LPARAM)' to 'HOOKPROC'

    What may be the error, i think its callback issue
    can anyone help me on implementing callback

  2. #2
    Join Date
    May 2000
    Location
    Armenia
    Posts
    201

    Re: CALLBACK errror on class

    First of all you can't use non-static member function of the class as the callback. You can use global function or static member function as the callback. And the next in SetWindowsHookEx function you should provide the address of the function, which is CHECK::LowLevelKeyboardProc without ampersand (&), in second parameter:
    Code:
    class CHECK
    {
    public:
    static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
    };
    and then in _tmain:
    Code:
    g_hMouseHook = SetWindowsHookEx( WH_MOUSE_LL, (HOOKPROC)CHECK::LowLevelKeyboardProc, GetModuleHandle(NULL), 0 );

  3. #3
    Join Date
    Jun 2009
    Posts
    61

    Re: CALLBACK errror on class

    Thanks dear...
    Now working fine...
    But now its working as infinite loop. I want to take control out or unload the mouse event after a single left click

  4. #4
    Join Date
    May 2000
    Location
    Armenia
    Posts
    201

    Re: CALLBACK errror on class

    You can handle WM_LBUTTONDOWN message in LowLevelKeyboardProc as below:
    Code:
    case WM_LBUTTONDOWN:
    
    PostQuitMessage(0); break;
    This will allow to exit from the message loop in _tmain when left mouse button is clicked.

  5. #5
    Join Date
    Jun 2009
    Posts
    61

    Re: CALLBACK errror on class

    Thanks a lot for u r valuable help.
    Now i am getting.
    If u dont mind may i asl 1 more question.

    How to show mouse pointer. Now i am not getting mouse pointer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured