Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending global mouse messages to one window

Status
Not open for further replies.

mirr2001

Programmer
Mar 29, 2002
24
DK
Hi,
I have a question that I hope can be answered in this forum.
What I want is quite simple to explain: I want global mouse messages (especially WM_LBUTTONDOWN, RBUTTONDOWN and DBLCLK) to be blocked and if they are over my app-window to be sent to it.
What I want to achieve is to block people from clicking on the start-button or taskbar or to open any other apps.
I have already locked the keybord by calling SetWindowsHookEx and doing everything necessary (CTRL+ALT+DEL isn't blocked, but I can live with that) and I have done the same thing with the mouse. The thing is, it works fine with the start button (no reaction on click), but I want the mouse to work in the app-window. And because Buttons etc. are windows to, they wont get any mouse messages too; only the main window. Has anyone an idea how I can find out, if a message has to be sent to a button anf if yes how to get the HWND I need for PostMessage???
Any suggestions are highly appreciated
 
Well, if you know the rectangle of your window, you can change the mouse hook procedure to allow events that fall within that rectangle.

But as far as what you're trying to do, I strongly discourage it.

It violates the fundamental principles of a multi-tasking user interface.

Sorry to be so blunt, but most likely, your users will HATE that feature.

[sub]I REALLY hope that helps.[/sub]
Will
 
Thx. I haven't really thought about that quite simple solution (guess I was blind after a 100 tries).
Btw. the feature is not meant to harm users. I program kinda juke-box for parties. This feature can be turned on by the admin (with pass) so no stranger can f*** up his computer but only control what he is meant to.
 
Might I ask you to post the code for how u managed to make your application keep focus?? I can block the events I want, but only as long as the mouse is over the window, or the Dialog box is in the foreground.
 
For Controlling global messages I have written a small dll file which I use in my app. The header is like this (dont pay attention to the comments):

[/code]
#pragma once

#ifndef INPUT_CTRL_H
#define INPUT_CTRL_H

#include <windows.h>
#include <atltypes.h>

#ifdef __cplusplus
extern &quot;C&quot;
{
#endif

//#ifdef KEYDLL3_EXPORTS
#define EXP __declspec(dllexport)
//#else
//#define EXP __declspec(dllimport)
//#endif


EXP void SetPermissionRect(int left, int top, int right, int bottom);
EXP bool MouseHook();
EXP void MouseUnhook();
EXP bool KeyHook();
EXP void KeyUnhook();
EXP void SetAllowedKeyWindow(char* title);
EXP LRESULT CALLBACK llKeyBoardProc(int nCode,WPARAM wParam, LPARAM lParam);
EXP LRESULT CALLBACK llMouseProc(int nCode, WPARAM wParam, LPARAM lParam);
EXP LRESULT CALLBACK keyBoardProc(int nCode, WPARAM wParam, LPARAM lParam);


#ifdef __cplusplus
}
#endif

#endif[/code]
And the Mouse hookoing could look like this: (in .cpp file)
Code:
bool MouseHook()
{
	static HINSTANCE hinstDLL= LoadLibrary((LPCSTR)&quot;InputCtrl.dll&quot;);
	if(hinstDLL==NULL)
	{
		return false;
	}
	llMouseHook= SetWindowsHookEx(14, llMouseProc, hinstDLL, 0);
	if(llMouseHook==NULL)
	{
		return false;
	}
	else
	{
		return true;
	}
}
LRESULT CALLBACK llMouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	if(nCode<0)
	{
		return CallNextHookEx(llMouseHook, nCode, wParam, lParam);
	}
	else
	{
		CPoint pos;
		if(wParam== WM_MOUSEMOVE)
		{
			return CallNextHookEx(llMouseHook, nCode, wParam, lParam);//behave as usual
		}
		else if(::GetCursorPos(&pos)==TRUE)
		{
			if(permissionRect.PtInRect(pos)==TRUE)
			{
				return CallNextHookEx(llMouseHook, nCode, wParam, lParam);//behave as usual
			}
			else
			{
				return wParam;//this will cause nothing to happen
			}
		}
		else//could not retrive cursor - security: proceed as normal
			return CallNextHookEx(llMouseHook, nCode, wParam, lParam);
	}
}[\code]
This code is simply for blocking purposes (for other LowLevel Hooks see MSDN), but could be modified by sending specialized messages to one special window etc.



By the way; I found an easier way to keep the Task manager from appearing. It is not the best but it works fine for my purposes. Simply add a key to the registry (win2000, xp); HKEY_CURENT_USER->Software->Microsoft->Windows->CurrentVersion->Policies->System (System has to be added).
Then set a new DWORD value (CRegKey::SetDWORDValue) named DisableTaskMgr to 1 to deactivate and to 0 to activate (when deactivated there will appear a window saying &quot;The Task manager has been disabled by the administrator&quot;).

Hope this helps
 
Hmmm, I will have to look over that a few times. Basically what I want to do is have my application keep focus until I tell it not too.

Basically, I have a dialog window with a user name and password that pops up, sort of like the initial login to win2k, I just don't want them to be able to access the programs until they are cleared to access them. So while they are over my window it is ok for eveything to work, and when they aren't, nothing works.

I am just wondering if this is the only way to allow my program to be greedy and take the all focus and nothing but the focus. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top