Click here to Skip to main content
15,901,373 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: data storage Pin
anna mathew28-Oct-08 18:14
anna mathew28-Oct-08 18:14 
GeneralRe: data storage Pin
anna mathew29-Oct-08 1:34
anna mathew29-Oct-08 1:34 
GeneralRe: data storage Pin
Larry Mills Sr29-Oct-08 3:14
Larry Mills Sr29-Oct-08 3:14 
GeneralRe: data storage Pin
Larry Mills Sr29-Oct-08 4:32
Larry Mills Sr29-Oct-08 4:32 
GeneralRe: data storage Pin
anna mathew30-Oct-08 0:34
anna mathew30-Oct-08 0:34 
AnswerRe: data storage Pin
David Crow28-Oct-08 6:14
David Crow28-Oct-08 6:14 
AnswerRe: data storage Pin
Hamid_RT28-Oct-08 21:02
Hamid_RT28-Oct-08 21:02 
QuestionHow to monitor notepad close message with SetWindowsHookEx? Pin
syntax28uk28-Oct-08 0:44
syntax28uk28-Oct-08 0:44 
Hi there,

I've been trying a hook notepad using SetWindowsHookEx function and the WH_GETMESSAGE message but to no avail.

Below is my current running code. My code compiles and run, the problem is that the
LRESULT WINAPI GetMsgProc(UINT nCode, WPARAM wParam, LPARAM lParam) function is never called.

Can somebody please help as to why that function is never executed when I start/close notepad?

#define WIN32_LEAN_AND_MEAN																	// trim the excess fat from Windows
#include <stdlib.h>
#include <crtdbg.h>

#include <windows.h>
#include <windowsx.h>
#include <tchar.h>
#include <stdio.h>
#include <string.h>
#include <locale.h>
#include "Resource.h"

LRESULT WINAPI GetMsgProc(UINT, WPARAM, LPARAM);

/*Standard Dialog Call back function*/
BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
HWND hWndMainDialog;

// Global Hook handle
HHOOK hIISHook;
HINSTANCE hinstDLL; 

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	BOOL bOK = FALSE;
	
	hinstDLL = LoadLibrary((LPCTSTR) _T("c:/WINDOWS/system32/notepad.exe")); 

	hIISHook = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, hinstDLL, 0);


	bOK = (hIISHook != NULL);
	if (bOK)
	{
		MessageBox(NULL,_T("Low Level hook installed properly"), _T("Information"), MB_OK);
	}else
	{
		UnhookWindowsHookEx(hIISHook);
		MessageBox(NULL,_T("Error Installing Hook"), _T("Information"), MB_OK | MB_ICONSTOP);
	}

	DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_IIS), NULL, DlgProc);



	UnhookWindowsHookEx(hIISHook);
	_CrtDumpMemoryLeaks();	
	return 0;

}

LRESULT WINAPI GetMsgProc(UINT nCode, WPARAM wParam, LPARAM lParam)
{
	PMSG msg;
	msg = (PMSG)lParam;
	return CallNextHookEx(hIISHook, nCode, wParam, lParam);
}


BOOL CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{	
	BOOL b;
	switch(Msg)
	{
	case WM_INITDIALOG:
		hWndMainDialog = hWnd;
		return TRUE;
	case WM_COMMAND:
		switch(HIWORD(wParam))
		{
		case BN_CLICKED:
			switch(LOWORD(wParam))
			{
			case IDC_BTN_PROCESS:
				b = FALSE;
				if(!b)
				{
					MessageBox(NULL,_T("Button has been clicked"), _T("Information"), MB_OK | MB_ICONSTOP);
					return;
				}
				break;
			}
			break;
		}
		return TRUE;
	case WM_CLOSE:
		PostQuitMessage(0);
		return TRUE;
	case WM_DESTROY:
		PostQuitMessage(0);
		return TRUE;	
	}

	return FALSE;
}


</locale.h></string.h></stdio.h></tchar.h></windowsx.h></windows.h></crtdbg.h></stdlib.h>

AnswerRe: How to monitor notepad close message with SetWindowsHookEx? Pin
Prasann Mayekar28-Oct-08 2:07
Prasann Mayekar28-Oct-08 2:07 
GeneralRe: How to monitor notepad close message with SetWindowsHookEx? Pin
Prasann Mayekar28-Oct-08 2:13
Prasann Mayekar28-Oct-08 2:13 
Questionwhich directory to use to put shared dlls? Pin
sashoalm27-Oct-08 23:55
sashoalm27-Oct-08 23:55 
AnswerRe: which directory to use to put shared dlls? Pin
James R. Twine28-Oct-08 0:24
James R. Twine28-Oct-08 0:24 
GeneralRe: which directory to use to put shared dlls? Pin
sashoalm28-Oct-08 3:29
sashoalm28-Oct-08 3:29 
AnswerRe: which directory to use to put shared dlls? Pin
Roger Stoltz28-Oct-08 1:53
Roger Stoltz28-Oct-08 1:53 
QuestionAny effect on :: Pin
CodingLover27-Oct-08 22:44
CodingLover27-Oct-08 22:44 
AnswerRe: Any effect on :: Pin
Rajesh R Subramanian27-Oct-08 22:52
professionalRajesh R Subramanian27-Oct-08 22:52 
GeneralRe: Any effect on :: Pin
toxcct28-Oct-08 2:06
toxcct28-Oct-08 2:06 
AnswerRe: Any effect on :: Pin
Roger Stoltz27-Oct-08 23:05
Roger Stoltz27-Oct-08 23:05 
QuestionRe: Any effect on :: Pin
CodingLover27-Oct-08 23:40
CodingLover27-Oct-08 23:40 
AnswerRe: Any effect on :: Pin
Roger Stoltz27-Oct-08 23:58
Roger Stoltz27-Oct-08 23:58 
AnswerRe: Any effect on :: Pin
James R. Twine28-Oct-08 0:31
James R. Twine28-Oct-08 0:31 
AnswerRe: Any effect on :: Pin
Rajesh R Subramanian28-Oct-08 0:56
professionalRajesh R Subramanian28-Oct-08 0:56 
AnswerRe: Any effect on :: Pin
toxcct28-Oct-08 2:04
toxcct28-Oct-08 2:04 
GeneralRe: Any effect on :: Pin
CPallini27-Oct-08 23:49
mveCPallini27-Oct-08 23:49 
AnswerRe: Any effect on :: Pin
David Crow28-Oct-08 6:16
David Crow28-Oct-08 6:16 

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.