Click here to Skip to main content
15,913,486 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Need Help in add-in Pin
Mike Melnikov2-Oct-00 22:07
Mike Melnikov2-Oct-00 22:07 
GeneralRe: Need Help in add-in Pin
Achyut2-Oct-00 22:20
Achyut2-Oct-00 22:20 
GeneralRe: Need Help in add-in Pin
Mike Melnikov3-Oct-00 23:54
Mike Melnikov3-Oct-00 23:54 
GeneralICM TranslateColors Problems Pin
Kurt1-Oct-00 10:14
Kurt1-Oct-00 10:14 
GeneralGet Parent Process Pin
Peter Scheir1-Oct-00 7:21
sussPeter Scheir1-Oct-00 7:21 
GeneralRe: Get Parent Process Pin
Gert Boddaert1-Oct-00 10:02
Gert Boddaert1-Oct-00 10:02 
Generaldll Pin
Larry1-Oct-00 7:16
Larry1-Oct-00 7:16 
GeneralRe: dll Pin
Mustafa Demirhan1-Oct-00 8:57
Mustafa Demirhan1-Oct-00 8:57 
Hi,
You need to write this into a dll. Here is an example that implements keyboard hooks. Yours is similar. You can modify this:
<br />
// SystemHook.cpp : Defines the entry point for the DLL application.<br />
//<br />
<br />
#include "stdafx.h"<br />
#include "SystemHook.h"<br />
#include <stdlib.h><br />
<br />
#define ID_CMD_KEYPRESSED	WM_USER+200<br />
<br />
// Globals for this module <br />
HWND   ghWndMain;      // Handle to main window -- used to post msgs<br />
static HHOOK    hHook;          // A handle to our installed hook <br />
static BOOL     bHookInstalled; // TRUE if hook has been installed <br />
<br />
HINSTANCE ghDLLInst;   // Handle to the DLL's instance.  Set in DllMain.<br />
<br />
// Local function.  Although this function is exported from our DLL (Windows <br />
// needs to call it directly), no other app needs to call this, so we can <br />
// just prototype it here.  <br />
 <br />
//SYSTEMHOOK_API LRESULT CALLBACK KeyboardProc (int nCode, WORD wParam, DWORD lParam ); <br />
<br />
BOOL APIENTRY DllMain( HANDLE hModule, <br />
                       DWORD  ul_reason_for_call, <br />
                       LPVOID lpReserved)<br />
{<br />
    switch (ul_reason_for_call)<br />
	{<br />
		case DLL_PROCESS_ATTACH:<br />
		case DLL_THREAD_ATTACH:<br />
		case DLL_THREAD_DETACH:<br />
		case DLL_PROCESS_DETACH:<br />
			break;<br />
    }<br />
	ghDLLInst=(HINSTANCE)hModule;<br />
    return TRUE;<br />
}<br />
<br />
<br />
// This is an example of an exported variable<br />
SYSTEMHOOK_API int nSystemHook=0;<br />
<br />
// This is an example of an exported function.<br />
SYSTEMHOOK_API int fnSystemHook(void)<br />
{<br />
	return 42;<br />
}<br />
<br />
// This is the constructor of a class that has been exported.<br />
// see SystemHook.h for the class definition<br />
CSystemHook::CSystemHook()<br />
{ <br />
	return; <br />
}<br />
<br />
//********************************************************************** <br />
// <br />
// KeyboardHook() <br />
// <br />
// This is the Keyboard Hook function which windows will call every <br />
// time it gets a keyboard message.  In this function, we check to <br />
// see if the key pressed was Ctrl+Alt+F9, and if it is, we post <br />
// the proper message to our main window which will do the right <br />
// thing.   <br />
// <br />
// Note that the window handle that we post from was set by a call to <br />
// InstallHook() above. <br />
// <br />
// Parameters/return value: <br />
// <br />
// Standard 3.1 KeyboardProc.  See docs for "KeyboardProc". <br />
// <br />
//********************************************************************* <br />
SYSTEMHOOK_API LRESULT CALLBACK KeyboardProc(<br />
	int code,       // hook code<br />
	WPARAM wParam,  // virtual-key code<br />
	LPARAM lParam)  // keystroke-message information<br />
{<br />
	if (code>=0) <br />
	{<br />
		if(HIWORD(lParam) & 0x8000) <br />
		{<br />
			if(!GetKeyState(VK_RMENU))<br />
			{<br />
				HWND h=::FindWindow(NULL,"WinScheduler");<br />
				PostMessage(h, ID_CMD_KEYPRESSED , wParam, lParam);<br />
			}<br />
			else<br />
			{<br />
				//BURAYA GEREKLI KODU EKLE<br />
			}<br />
		}<br />
	}<br />
	// If we haven't returned 1 by the time we get here, then we <br />
	// need to pass on the message to CallNextHookEx.<br />
	return (int)CallNextHookEx(hHook, code, wParam, lParam); <br />
}<br />
<br />
//********************************************************************** <br />
// InstallHook() <br />
// <br />
// Installs/Removes Filter function for the WH_KEYBOARD hook. <br />
// <br />
// Parameters: <br />
// HWND hWnd      Handle to main window to receive posted messages.  See <br />
//                KeyboardProc() for more info on how it works. <br />
//  <br />
// BOOL bCode     TRUE to hook, FALSE to unhook <br />
// <br />
// Returns: <br />
// 1 if successful, 0 if not. <br />
// <br />
//********************************************************************** <br />
SYSTEMHOOK_API int WINAPI InstallHook (HWND hWnd, BOOL bCode )<br />
{<br />
    int nReturn = 1;<br />
	ghWndMain = hWnd;  // Store app's window handle in DLL global variable <br />
<br />
    // Make sure that we are installing/removing in the proper order <br />
    if (bCode == bHookInstalled) <br />
        return 0; <br />
 <br />
    if (bCode) <br />
    { <br />
        hHook=(HHOOK)SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,ghDLLInst,0); <br />
        if (!hHook) <br />
            return 0; <br />
        bHookInstalled = TRUE; <br />
    } <br />
    else <br />
    { <br />
        nReturn = UnhookWindowsHookEx(hHook); <br />
        bHookInstalled = FALSE; <br />
    } <br />
    return nReturn; <br />
}<br />
<br />
// The following ifdef block is the standard way of creating macros which make exporting <br />
// from a DLL simpler. All files within this DLL are compiled with the SYSTEMHOOK_EXPORTS<br />
// symbol defined on the command line. this symbol should not be defined on any project<br />
// that uses this DLL. This way any other project whose source files include this file see <br />
// SYSTEMHOOK_API functions as being imported from a DLL, wheras this DLL sees symbols<br />
// defined with this macro as being exported.<br />
#ifdef SYSTEMHOOK_EXPORTS<br />
#define SYSTEMHOOK_API __declspec(dllexport)<br />
#else<br />
#define SYSTEMHOOK_API __declspec(dllimport)<br />
#endif<br />
<br />
// This class is exported from the SystemHook.dll<br />
class SYSTEMHOOK_API CSystemHook {<br />
public:<br />
	CSystemHook(void);<br />
	// TODO: add your methods here.<br />
};<br />
<br />
extern SYSTEMHOOK_API int nSystemHook;<br />
<br />
SYSTEMHOOK_API int fnSystemHook(void);<br />
<br />
SYSTEMHOOK_API LRESULT CALLBACK KeyboardProc(int code,WPARAM wParam,LPARAM lParam);<br />
SYSTEMHOOK_API int WINAPI InstallHook (HWND hWnd, BOOL bCode );<br />


Mustafa Demirhan
QuestionHow to catch the 'Stop Build' event? Pin
GeVanCo1-Oct-00 2:04
GeVanCo1-Oct-00 2:04 
GeneralSendKeys Pin
Mustafa Demirhan1-Oct-00 0:16
Mustafa Demirhan1-Oct-00 0:16 
GeneralAdd Message Map Pin
S moses30-Sep-00 17:21
sussS moses30-Sep-00 17:21 
GeneralRe: Add Message Map Pin
Sam Hobbs30-Sep-00 18:11
Sam Hobbs30-Sep-00 18:11 
GeneralManualy add cpp and h file to project Pin
S moses30-Sep-00 11:42
sussS moses30-Sep-00 11:42 
GeneralRe: Manualy add cpp and h file to project Pin
Frank Deo30-Sep-00 12:00
Frank Deo30-Sep-00 12:00 
GeneralRe: Manualy add cpp and h file to project Pin
S moses30-Sep-00 17:20
sussS moses30-Sep-00 17:20 
GeneralProblem with CListCtrl::SetBkImage(..) Pin
Ronald L. Russell Jr. (Ron)30-Sep-00 11:12
sussRonald L. Russell Jr. (Ron)30-Sep-00 11:12 
GeneralRe: Problem with CListCtrl::SetBkImage(..) Pin
Michael Dunn2-Oct-00 9:55
sitebuilderMichael Dunn2-Oct-00 9:55 
General Disabling MS Language extensions Pin
Jim Crafton30-Sep-00 5:47
Jim Crafton30-Sep-00 5:47 
GeneralDisabling MS Language extensions Pin
Jim30-Sep-00 5:43
Jim30-Sep-00 5:43 
GeneralRe: Disabling MS Language extensions Pin
Erik Funkenbusch4-Oct-00 13:32
Erik Funkenbusch4-Oct-00 13:32 
GeneralGetCapture Pin
KarlKlose30-Sep-00 2:11
KarlKlose30-Sep-00 2:11 
GeneralAn interesting ICQ add-on library Pin
Eq30-Sep-00 0:31
Eq30-Sep-00 0:31 
GeneralRe: An interesting ICQ add-on library Pin
helloworld30-Sep-00 0:32
helloworld30-Sep-00 0:32 
GeneralRe: An interesting ICQ add-on library Pin
Eq30-Sep-00 0:33
Eq30-Sep-00 0:33 
GeneralMFC App: Need some help with architecture Pin
Lutz Heinrichs29-Sep-00 9:12
Lutz Heinrichs29-Sep-00 9:12 

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.