|
-
April 12th, 2004, 02:47 PM
#1
need help really bad please
HI. I am in a bit of a spot, I have some trouble. I have to make this program that blocks all keyboard and mouse input from all active windows exept one, the one window where the keyboard and mouse input are not blocked is the one where you are supposed to enter a password and if this password is correct you can unlock the other windows as well(they will once again be able to recieve keyboard and mouse input).I am using windows hooks(if you know another way I am all ears). So my problem is that after the user inserts the correct password and clicks ok the program terminates but the hooks that have been set on the other windows still run so even after the user inserts the correct pass he still can't work with the windows that have been activated during the time that the program has been active.
ok, so I am using to dlls and a main program, one dll is for the keyboard hook, one is for the mouse hook and one for the mouse hook, I am only going to post about the mouse hook because I think this is the most important one of them all.
Code:
#include "a.h"
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include <windef.h>
static BOOL bHooked = FALSE;
DWORD tid1=0;
BOOL still_hook;
static mouse=0,CBT=0;
static HINSTANCE hInst;
static int count;
int c=0;
HHOOK hookuri[100];
DWORD iduri[100];
LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK MouseProc(int code, WPARAM wParam, LPARAM lParam);
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason, LPVOID lpvReserved)
{
int i;
for(i=0;i<101;i++)
{
hookuri[i]=NULL;
iduri[i]=0;
}
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
hInst=hinstDLL;
count=0;
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
default:
break;
}
return TRUE;
}
DLL_EXPORT void OpresteMousu(void)
{
if(!bHooked)
{
CBT = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc, hInst, (DWORD)NULL);
bHooked = TRUE;
}
}
DLL_EXPORT void PornesteMousu(void)
{
UnhookWindowsHookEx(mouse);
UnhookWindowsHookEx(CBT);
}
LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam)
{
char x[100];
DWORD tid;
int q;
if(code==HCBT_ACTIVATE)
{
tid = GetWindowThreadProcessId(wParam, NULL);
GetWindowText((HWND)wParam,x,100);
if(!(_stricmp(x,"Criognia password window")==0))
{
if (tid!=tid1)
{
UnhookWindowsHookEx(mouse);
mouse= SetWindowsHookEx(WH_CBT, (HOOKPROC)MouseProc, hInst, tid);
tid1=tid;
}
}
}
return CallNextHookEx(CBT, code, wParam, lParam);
}
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HC_ACTION)
{
if (wParam == WM_LBUTTONDOWN)
Beep(500, 200);
}
return nCode < 0 ? CallNextHookEx(mouse, nCode, wParam, lParam) : -1;
}
please help
this project I have to do by next tuesday
thank you in advance
If I don't do it I may not get my 10(the equivalent of an A in america I should think)
I code stuff all the time. Greatest hobby man could have. Hope it to be a job one day.
-
April 12th, 2004, 03:02 PM
#2
Hi.
Perhaps I missunderstood your task, but why don't you simply use a system modal dialog box for the passwort ?
-
April 13th, 2004, 12:58 PM
#3
what's that?
I code stuff all the time. Greatest hobby man could have. Hope it to be a job one day.
-
April 13th, 2004, 02:52 PM
#4
A Dialog box that is system modal (means: as long as this dialog box is open no other window on the desktop can be activated (I think there are a few possibilities such as the task manager, but nothing else).
I don't know which passwort are you want to verify, but there is also the possibility (at least for NT) to bring up the user login screen ( I think the function call doing that was LockWorkStation() or something very similar).
-
April 14th, 2004, 02:21 AM
#5
so how do I do that?
SO how do I create a dialog box that is system modal? what functions, what API calls do I use and stuff? And would the mouse hook no longer be necesarry? but the keyboard hook would still be necesarry no?
I code stuff all the time. Greatest hobby man could have. Hope it to be a job one day.
-
April 14th, 2004, 09:16 AM
#6
1. Look up MessageBox() in the MSVC help.
2. Go to MS and search for MessageBox.
If you want to work in any programming environment, you need
to get to know the API that is available to you.
-
April 14th, 2004, 05:29 PM
#7
Hi.
Sorry, forget everything about "system modal". obviously a system modal dialog isn't really system modal anymore in win 2k.
But if using Win 2K or XP:
- Do you know "LockWorkStation()" ?
try:
"#define _WIN32_WINNT 0x0500"
before the #includes in your stdafx.h
call "LockWorkStation()" somewhere in your code ...
-
April 21st, 2004, 03:06 PM
#8
I have had to do this exact thing for my own corporation [medical environment and Privacy concerns involved]. What we needed was a password dialog (for our own internal applications) that would prevent users from clicking other apps, bringing them to the foreground, or doing ANYTHING ELSE.
What you're looking to do is install a low-level mouse hook (WH_MOUSE_LL). I'm assuming here that you are running on Windows 2000 or XP. I had the luxury of a dedicated program which could do the SetWindowsHookEx(WH_MOUSE_LL, ) call, passing in the address of the actual mousehook code in my custom DLL. I never had good luck trying to install the mouse hook from the hook DLL itself -- seems a bad idea to me.
You'll have to combine that with a specially-marked shared memory section defined via compiler directives, as follows:
Code:
#pragma data_seg(".mcshr")
HWND hFilterHWnd = NULL;
HWND hTIPWnd = NULL;
DWORD dwFilterWndPID = 0;
#pragma data_seg()
You will also need to add the following to your linker settings:
Code:
/section:.mcshr,rws
What you want your mouse hook to do, basically, is eat messages that aren't bound for any HWND except for the one you want. I couldn't figure out how to redirect the message back to the window that has focus, so I just eat everything. Obviously my mouse-hook is set up to allow messages to all windows of this process (this dialog has a help window), but you see I am also storing the desired HWND so I could filter a single window just as easily.
There are a few gotchas here, but so far I have been able to overcome all of them and have a nicely-functioning dialog where all mouse activity stays within the dialog.
Keyboard activity I restrict simply by:
- Making the dialog system modal
- Overriding WM_ACTIVATE and WM_ACTIVATEAPP to return focus to my window when it is leaving
It's not completely secure, but we have never needed more (although I have ideas for enhancing it further, perhaps via a WH_KEYBOARD_LL hook).
Last edited by LeeND; April 21st, 2004 at 03:16 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|