Using the SetWindowsHookEx (hello there!)

The situation:
Hello, I've been asked to create a very interesting app that blocks the user from using Windows unless he/she does something on screen. The UI is done in HTML so I used an HTA (HTML application) and through a 3rd-party method, I can call functions that are within a dll.

In the C++ dll:
First I'm trying to block the ALT+TAB combination. Then later I can worry about blocking Alt+Esc, Ctrl+Esc, Alt+F4, Ctrl+Shift+Esc, etc.

The problem:
I am trying to use the SetWindowsHookEx method to block key combinations. But my code isn't working. Maybe I'm not checking right.

The solution:
Anybody?

The code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// elocker32.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include <windows.h>

//Global Hook
HHOOK m_hDllKbdHook;

//Internal Callback function that fires everytime a key is touched
LRESULT CALLBACK wireKeyboardProc(int code,WPARAM wParam,LPARAM lParam)
{  
	//KBDLLHOOKSTRUCT Structure contains information about the key pressed
	DWORD vkCode = ((KBDLLHOOKSTRUCT *) lParam)->vkCode;
	DWORD scanCode = ((KBDLLHOOKSTRUCT *) lParam)->scanCode;
	DWORD flags = ((KBDLLHOOKSTRUCT *) lParam)->flags;
	DWORD time = ((KBDLLHOOKSTRUCT *) lParam)->time;
	ULONG_PTR dwExtraInfo = ((KBDLLHOOKSTRUCT *) lParam)->dwExtraInfo;


	if(code = HC_ACTION)
	{
        //If both the Alt and TAB keys are pressed, block?
		if((vkCode==VK_MENU) && (vkCode==VK_TAB))
		{
			MessageBox(0, L"Alt+Tab Blocked!", L"Notice", 0 );
			return 1; // Exit function
		}

	}

    //Call next hook
	return CallNextHookEx(m_hDllKbdHook, code, wParam, lParam);
}


//External Function
HHOOK LockWindows (HWND appHandle)
{

	MessageBox( appHandle, L"Warning: Windows is about to get locked", L"Greetings", 0 );	

	long appInstance = GetWindowLong(appHandle,-6);

	m_hDllKbdHook = SetWindowsHookEx(WH_KEYBOARD_LL, &wireKeyboardProc, (HINSTANCE)appInstance,0);
	return m_hDllKbdHook;
	
}
Topic archived. No new replies allowed.