Click here to Skip to main content
15,891,033 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: CAsyncSocket fails after a few successful OnReceive()'s Pin
Mark Salsbery8-Sep-08 8:17
Mark Salsbery8-Sep-08 8:17 
Questionconcatenate linked list of characters Pin
Sadaiyappan1-Sep-08 13:27
Sadaiyappan1-Sep-08 13:27 
AnswerRe: concatenate linked list of characters Pin
Robert.C.Cartaino1-Sep-08 14:51
Robert.C.Cartaino1-Sep-08 14:51 
QuestionA Global Keyboard hook problem. Pin
emmmatty11-Sep-08 9:33
emmmatty11-Sep-08 9:33 
AnswerRe: A Global Keyboard hook problem. Pin
Naveen1-Sep-08 15:21
Naveen1-Sep-08 15:21 
GeneralRe: A Global Keyboard hook problem. Pin
emmmatty11-Sep-08 18:49
emmmatty11-Sep-08 18:49 
GeneralRe: A Global Keyboard hook problem. Pin
Naveen1-Sep-08 19:00
Naveen1-Sep-08 19:00 
AnswerRe: A Global Keyboard hook problem. Pin
Rajesh R Subramanian1-Sep-08 20:51
professionalRajesh R Subramanian1-Sep-08 20:51 
emmmatty1 wrote:
The hook is installed in the InitDialog of this dialog.


Confused | :confused:

How will it work then? You are expecting to install a global keyboard hook - So, the hook should be installed from within a system-wide DLL, so that it could continue to process the hook messages. If it were installed from within a dialog which is not system-wide, and would work only when the dialog thread is active.

Try this:

Step 1. Create a DLL and write the hook procedure in the DLL.
#pragma data_seg(".SHARED")
    static HHOOK hKeyBD=NULL;
#pragma data_seg()

#define DLLEXPORT __declspec(dllexport)__stdcall

HINSTANCE hInst;

LRESULT DLLEXPORT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	if (((DWORD)lParam & 0x40000000) && (HC_ACTION==nCode))
	{	
		//Write stuff here
	}
	
	return CallNextHookEx(hKeyBD, nCode, wParam, lParam);
}

BOOL DLLEXPORT StartHook()
{
	hKeyBD=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc, hInst, 0);
	return TRUE;
}

BOOL DLLEXPORT StopHook()
{
     BOOL bStatus = UnhookWindowsHookEx(hKeyBD);
     return bStatus;
}

BOOL CHodllApp::InitInstance()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	hInst=AfxGetInstanceHandle();
	return TRUE;
}

Step 2. Start the hook from an external module and stop it when you're done. Write back if you have troubles doing this.

Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche

.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]

Questionrand() always returns 18467...whats going on.. [modified] Pin
montiee1-Sep-08 8:47
montiee1-Sep-08 8:47 
AnswerRe: rand() always returns 18467...whats going on.. Pin
Mark Salsbery1-Sep-08 11:20
Mark Salsbery1-Sep-08 11:20 
GeneralRe: rand() always returns 18467...whats going on.. Pin
montiee1-Sep-08 19:23
montiee1-Sep-08 19:23 
QuestionMy application is closing when i hit enter button through keyboard Pin
hariakuthota1-Sep-08 8:12
hariakuthota1-Sep-08 8:12 
AnswerRe: My application is closing when i hit enter button through keyboard Pin
Cedric Moonen1-Sep-08 8:16
Cedric Moonen1-Sep-08 8:16 
AnswerRe: My application is closing when i hit enter button through keyboard Pin
onlyjaypatel1-Sep-08 19:24
onlyjaypatel1-Sep-08 19:24 
Question3D World Pin
MrMcIntyre1-Sep-08 7:34
MrMcIntyre1-Sep-08 7:34 
AnswerRe: 3D World Pin
Cedric Moonen1-Sep-08 7:50
Cedric Moonen1-Sep-08 7:50 
GeneralRe: 3D World Pin
MrMcIntyre1-Sep-08 8:07
MrMcIntyre1-Sep-08 8:07 
GeneralRe: 3D World Pin
Cedric Moonen1-Sep-08 8:14
Cedric Moonen1-Sep-08 8:14 
GeneralRe: 3D World Pin
MrMcIntyre1-Sep-08 9:06
MrMcIntyre1-Sep-08 9:06 
GeneralRe: 3D World Pin
El Corazon1-Sep-08 15:12
El Corazon1-Sep-08 15:12 
GeneralRe: 3D World Pin
MrMcIntyre1-Sep-08 9:26
MrMcIntyre1-Sep-08 9:26 
GeneralRe: 3D World Pin
MrMcIntyre3-Sep-08 6:38
MrMcIntyre3-Sep-08 6:38 
QuestionHBITMAP to picture control Pin
cherrymotion1-Sep-08 6:42
cherrymotion1-Sep-08 6:42 
AnswerRe: HBITMAP to picture control Pin
Ștefan-Mihai MOGA1-Sep-08 8:06
professionalȘtefan-Mihai MOGA1-Sep-08 8:06 
AnswerRe: HBITMAP to picture control Pin
Mark Salsbery1-Sep-08 11:34
Mark Salsbery1-Sep-08 11:34 

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.