Click here to Skip to main content
15,889,335 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
GeneralRe: Switch Pin
Mark Salsbery2-Apr-08 6:18
Mark Salsbery2-Apr-08 6:18 
GeneralRe: Switch Pin
Hamid_RT7-Apr-08 3:52
Hamid_RT7-Apr-08 3:52 
QuestionThread Pin
Member 34205091-Apr-08 23:37
Member 34205091-Apr-08 23:37 
GeneralRe: Thread Pin
Cedric Moonen1-Apr-08 23:41
Cedric Moonen1-Apr-08 23:41 
GeneralRe: Thread Pin
Maxwell Chen1-Apr-08 23:50
Maxwell Chen1-Apr-08 23:50 
GeneralRe: Thread Pin
Cedric Moonen1-Apr-08 23:59
Cedric Moonen1-Apr-08 23:59 
GeneralRe: Thread Pin
toxcct2-Apr-08 0:05
toxcct2-Apr-08 0:05 
QuestionRe: Thread Pin
Member 34205092-Apr-08 2:21
Member 34205092-Apr-08 2:21 
GeneralRe: Thread Pin
Maximilien2-Apr-08 3:00
Maximilien2-Apr-08 3:00 
GeneralRe: Thread Pin
Member 34205092-Apr-08 23:01
Member 34205092-Apr-08 23:01 
GeneralRe: Thread Pin
Hamid_RT7-Apr-08 3:51
Hamid_RT7-Apr-08 3:51 
QuestionMessgeBoxIndirect ( ) is causing a crash? Pin
RamaraoPV1-Apr-08 23:15
RamaraoPV1-Apr-08 23:15 
GeneralRe: MessgeBoxIndirect ( ) is causing a crash? Pin
Cedric Moonen1-Apr-08 23:27
Cedric Moonen1-Apr-08 23:27 
QuestionRe: MessgeBoxIndirect ( ) is causing a crash? Pin
RamaraoPV2-Apr-08 0:07
RamaraoPV2-Apr-08 0:07 

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.