Click here to Skip to main content
15,917,652 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Creating dynamic output in command prompt Pin
Cedric Moonen2-Apr-08 20:36
Cedric Moonen2-Apr-08 20:36 
GeneralRe: Creating dynamic output in command prompt Pin
Maximilien2-Apr-08 2:48
Maximilien2-Apr-08 2:48 
GeneralRe: Creating dynamic output in command prompt Pin
Auchioane2-Apr-08 16:00
Auchioane2-Apr-08 16:00 
QuestionCallStack checking? Pin
RamaraoPV2-Apr-08 0:35
RamaraoPV2-Apr-08 0:35 
GeneralRe: CallStack checking? Pin
Cedric Moonen2-Apr-08 0:57
Cedric Moonen2-Apr-08 0:57 
GeneralRe:Thanks still i have the question? Pin
RamaraoPV2-Apr-08 1:13
RamaraoPV2-Apr-08 1:13 
GeneralRe:Thanks still i have the question? Pin
Cedric Moonen2-Apr-08 2:14
Cedric Moonen2-Apr-08 2:14 
GeneralPrinter DC Pin
Developer6112-Apr-08 0:22
Developer6112-Apr-08 0:22 
GeneralRe: Printer DC Pin
_AnsHUMAN_ 2-Apr-08 1:14
_AnsHUMAN_ 2-Apr-08 1:14 
GeneralRe: Printer DC Pin
Developer6112-Apr-08 1:28
Developer6112-Apr-08 1:28 
GeneralRe: Printer DC Pin
Rajkumar R2-Apr-08 1:51
Rajkumar R2-Apr-08 1:51 
GeneralRe: Printer DC Pin
Rajkumar R2-Apr-08 1:19
Rajkumar R2-Apr-08 1:19 
GeneralRe: Printer DC Pin
Krishnakumartg3-Apr-08 21:37
Krishnakumartg3-Apr-08 21:37 
GeneralRe: Printer DC Pin
Hamid_RT7-Apr-08 3:54
Hamid_RT7-Apr-08 3:54 
QuestionHow to get focus to property sheet in windows programming(win32) Pin
Swty2-Apr-08 0:15
Swty2-Apr-08 0:15 
GeneralApplication is crashing when trying to display messagebox Pin
RamaraoPV2-Apr-08 0:11
RamaraoPV2-Apr-08 0:11 
QuestionRe: Application is crashing when trying to display messagebox Pin
CPallini2-Apr-08 1:51
mveCPallini2-Apr-08 1:51 
QuestionRe: Application is crashing when trying to display messagebox Pin
RamaraoPV2-Apr-08 2:10
RamaraoPV2-Apr-08 2:10 
GeneralRe: Application is crashing when trying to display messagebox Pin
Cedric Moonen2-Apr-08 2:21
Cedric Moonen2-Apr-08 2:21 
GeneralRe: Application is crashing when trying to display messagebox Pin
Maximilien2-Apr-08 2:55
Maximilien2-Apr-08 2:55 
QuestionRe: Application is crashing when trying to display messagebox Pin
David Crow2-Apr-08 3:40
David Crow2-Apr-08 3:40 
GeneralHooking Raw Input - Detect HID mice Pin
maszup2-Apr-08 0:03
maszup2-Apr-08 0:03 
Hello

I need to write an application to recognize which USB HID Mouse is using at the moment. At least two mice are connected to the PC at one time. It should work in background and show in the background window or write to file movement positions of currently moving mouse in the system.

My way of thinking is to:
1) create main application (exe or DLL) with window which will:
- detects all Raw Input HID mouses but not regist them yet
- recieve messages from its window and from hooking DLL
- detects in seperate thread which window is currently on top (Foreground)
- if new window is on top call first RegisterRawInputDevices with Handle to new window then call "CreateHook" from DLL to reset Hooks to new thread

Below the code for the thread detecting top most window:
	<br />
	while (Running) {<br />
		Sleep(1000);	<br />
                hWnd_curr = GetForegroundWindow();<br />
		if(hWnd_curr != hWnd_old) {<br />
			hWnd_old = hWnd_curr;<br />
			GetWindowText(hWnd_curr,window_name,sizeof(window_name));<br />
<br />
			Rid[0].hwndTarget = hWnd_curr;  //define to which window register raw input<br />
                        //here I get error: unused = CXX0030: Error: expression cannot be evaluated<br />
<br />
			if(!RegisterRawInputDevices(Rid, 1, sizeof (Rid[0]))) {<br />
				_snprintf(logevent,sizeof(logevent),"Register Raw Input Devices FAILED");<br />
				Write2File(logevent);<br />
				continue;<br />
			}<br />
	<br />
			if(pCreateHook != NULL && (dwThreadId = GetWindowThreadProcessId(hWnd_curr,&dwProcessId))!=0) <br />
						msgHook = pCreateHook(WH_CALLWNDPROC,hwndMain,dwThreadId);<br />
<br />
		}<br />
            }


Unfortunately I cannot register raw input devices to the other window than the one I created in main program.


2) create a DLL that that be using Global Hooks for all messages from the window that is on top. DLL will contains one external function:
- CreateHook - clears old hook if not NULL and sets new hook for given threadID
in the DLL there is a callback function for collecting hooked messages which are directly sent to main application

static LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam) {<br />
	<br />
	if(nCode < 0) {<br />
		CallNextHookEx(hook, nCode, wParam, lParam);<br />
		return 0;<br />
	}<br />
<br />
	INFO f; <br />
	f.code=nCode; <br />
	f.hhook=hook; <br />
	f.lParam=lParam;<br />
<br />
	cwpMessageParams = (PMSG)lParam;<br />
<br />
	if(cwpMessageParams->message == WM_INPUT) <br />
		SendMessage(mForm, messageCode, (WPARAM)(cwpMessageParams->message), (LPARAM)&f);<br />
<br />
	return CallNextHookEx(hook, nCode, wParam, lParam);<br />
}


The second problem with is that this callback never gets WM_INPUT even if raw inputs are register to the window created in main application.

I'm using Win32 in VC++.
Any suggestions? Or maybe my way of thinking is wrong??
How is it possible to get at least the name of currently working mouse??

Thanks for any help
Maciek

modified on Wednesday, April 2, 2008 6:10 AM

GeneralRe: Hooking Raw Input - Detect HID mice Pin
Randor 2-Apr-08 5:04
professional Randor 2-Apr-08 5:04 
GeneralSwitch Pin
john56321-Apr-08 23:43
john56321-Apr-08 23:43 
GeneralRe: Switch Pin
Cedric Moonen1-Apr-08 23:47
Cedric Moonen1-Apr-08 23:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.