Click here to Skip to main content
15,925,505 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: TIMER API Pin
Serge Velikevitch3-Oct-00 9:38
sussSerge Velikevitch3-Oct-00 9:38 
GeneralRe: TIMER API Pin
Larry7-Oct-00 9:18
Larry7-Oct-00 9:18 
GeneralRe: TIMER API Pin
Erik Funkenbusch4-Oct-00 13:08
Erik Funkenbusch4-Oct-00 13:08 
GeneralNon Owner-Draw Button Color Pin
gc3-Oct-00 5:47
gc3-Oct-00 5:47 
GeneralRe: Non Owner-Draw Button Color Pin
Erik Funkenbusch4-Oct-00 13:09
Erik Funkenbusch4-Oct-00 13:09 
GeneralPush Button Color Pin
gc3-Oct-00 4:45
gc3-Oct-00 4:45 
GeneralRe: Push Button Color Pin
Roger3-Oct-00 4:47
Roger3-Oct-00 4:47 
GeneralReally Desperate Spy Modification Pin
Larry3-Oct-00 4:45
Larry3-Oct-00 4:45 
hi I need to modify the below Spy sample program but dont know how to modify it .Can anyone point out to me what is there to be changed in the Spy sample program because I dont know how to. I need to detect when any running active application refreshes its screen as a result of input from keyboard and mouse and by the way is wm_paint the message I should monitor for my program? I am really desperate because I am very new to c++ programming and I really hope you can help me . Thanks for replying.

/*****************************************************************************\
* hook.c - Windows message spy application dll
*
* Functions:
*
* DllMain()
* FindSpyWindow()
* HookProc()
* SpyGetMsgProc()
* SpyCallWndProc()
* DbgPrintf()
*
* Comments:
*
\*****************************************************************************/

#include <windows.h>
#include "..\hook.h"


PRIVATE HWND ghwndSpyHook = NULL; // the handle back to the spy executable
PRIVATE SPYMSGDATA gsmd;
PRIVATE COPYDATASTRUCT gcds = { 0, sizeof(SPYMSGDATA), &gsmd };


PRIVATE VOID FindSpyWindow(VOID);

#ifdef DBG
VOID DbgPrintf(LPTSTR fmt, ...);
#endif



/*****************************************************************************\
* DllMain (hModule,cbHeap,lpchCmdLine)
*
* Called when the libary is loaded
*
* Arguments:
* PVOID hModule - Module handle for the libary.
* ULONG ulReason - DLL purpose
* PCONTEXT pctx - not used
*
* Returns:
* TRUE - Everything is ok
* FALSE- Error.
\*****************************************************************************/

BOOL
APIENTRY DllMain(
PVOID hModule,
ULONG ulReason,
PCONTEXT pctx
)
{
UNREFERENCED_PARAMETER(hModule);
UNREFERENCED_PARAMETER(pctx);

//
// This function is called for every instance of the DLL. We must find
// and store the handle to the spy window every time an instance of the
// DLL is instantiated.
//
if ( ulReason == DLL_PROCESS_ATTACH ) {
FindSpyWindow();
}

return TRUE;
}



/*****************************************************************************\
* FindSpyWindow
*
* Finds the spy window and store a local copy in this instances data.
* This must be called everytime that a new instance of the DLL is
* created.
*
* Arguments:
* none
*
* Returns:
* VOID
\*****************************************************************************/

PRIVATE VOID
FindSpyWindow(
VOID
)
{
ghwndSpyHook = FindWindow(HOOKWINDOWCLASS, HOOKWINDOWNAME);
}


/*****************************************************************************\
* HookProc( hWnd, uiMessage, wParam, lParam )
*
* The hook proc for the windows hook being spied on
*
* Arguments:
* HWND hWnd - window handle for the parent window
* UINT uiMessage - message number
* WPARAM wParam - message-dependent
* LPARAM lParam - message-dependent
*
* Returns:
* 0 if processed, nonzero if ignored
\*****************************************************************************/

BOOL WINAPI
HookProc(
HWND hwnd,
UINT uiMessage,
WPARAM wParam,
LPARAM lParam
)
{
HWND hwndSpyingOn;
HWND hwndSpyApp;

if (ghwndSpyHook == NULL || !IsWindow(ghwndSpyHook))
{
//
// Spy has terminated. Find the new window.
//
FindSpyWindow();
}

if (ghwndSpyHook != NULL && hwnd != ghwndSpyHook)
{
hwndSpyingOn = (HWND)GetWindowLong(ghwndSpyHook, 0);
hwndSpyApp = (HWND)GetWindowLong(ghwndSpyHook, sizeof(HWND));
//DbgPrintf("H ghwndSpyHook:%8.8x", ghwndSpyHook);
//DbgPrintf("H hwndSpyingOn:%8.8x", hwndSpyingOn);
//DbgPrintf("H hwndSpyApp:%8.8x", hwndSpyApp);

//
// Send the message on asynchronously for Spy to deal with if
// it is the appropriate hwndSpyingOn window to spy on.
//

if (hwndSpyingOn == hwnd
|| (hwndSpyingOn == HWND_ALL && hwnd != hwndSpyApp
&& !IsChild(hwndSpyApp, hwnd)))
{
gsmd.wParam = wParam;
gsmd.lParam = lParam;

gcds.dwData = uiMessage;

//DbgPrintf("H Sending Message hwnd:%8.8x msg:%d", hwnd, uiMessage);
SendMessage(ghwndSpyHook, WM_COPYDATA, (WPARAM)hwnd, (LPARAM)&gcds);
//DbgPrintf("H Sent Message hwnd:%8.8x msg:%d", hwnd, uiMessage);

//DbgPrintf("");
return TRUE;
}
//DbgPrintf("");
}

return FALSE;
}



/*****************************************************************************\
* SpyGetMsgProc
*
* The Get Message hook function.
*
\*****************************************************************************/

LRESULT CALLBACK
SpyGetMsgProc(
INT hc,
WPARAM wParam,
LPARAM lParam
)
{
PMSG pmsg;

pmsg = (PMSG)lParam;

if (hc >= 0 && pmsg && pmsg->hwnd)
{
return HookProc(pmsg->hwnd, pmsg->message, pmsg->wParam, pmsg->lParam);
}

//
// Note that CallNextHookEx ignores the first parameter (hhook) so
// it is acceptable (barely) to pass in a NULL.
//
return CallNextHookEx(NULL, hc, wParam, lParam);
}



/*****************************************************************************\
* SpyCallWndProc
*
* The Call Window Proc (Send Message) hook function.
*
\*****************************************************************************/

LRESULT CALLBACK
SpyCallWndProc(
INT hc,
WPARAM wParam,
LPARAM lParam
)
{
PCWPSTRUCT pcwps;

pcwps = (PCWPSTRUCT)lParam;

if (hc >= 0 && pcwps && pcwps->hwnd)
{
return HookProc(pcwps->hwnd, pcwps->message, pcwps->wParam, pcwps->lParam);
}

//
// Note that CallNextHookEx ignores the first parameter (hhook) so
// it is acceptable (barely) to pass in a NULL.
//
return CallNextHookEx(NULL, hc, wParam, lParam);
}



#ifdef DBG
/****************************************************************************
* DBGprintf
*
* This debugging function prints out a string to the debug output.
* An optional set of substitutional parameters can be specified,
* and the final output will be the processed result of these combined
* with the format string, just like printf. A newline is always
* output after every call to this function.
*
* Arguments:
* LPTSTR fmt - Format string (printf style).
* ... - Variable number of arguments.
* Returns:
* VOID
\****************************************************************************/

VOID DbgPrintf(
LPTSTR fmt,
...
)
{
va_list marker;
TCHAR szBuf[256];

va_start(marker, fmt);
wvsprintf(szBuf, fmt, marker);
va_end(marker);

OutputDebugString(szBuf);
OutputDebugString(TEXT("\r\n"));
}
#endif
GeneralCase Sensetive ComboBox Selection Pin
nogga3-Oct-00 3:52
nogga3-Oct-00 3:52 
GeneralSTL and dynamic objects Pin
JoJo3-Oct-00 2:47
JoJo3-Oct-00 2:47 
GeneralRe: STL and dynamic objects Pin
Erik Funkenbusch4-Oct-00 13:11
Erik Funkenbusch4-Oct-00 13:11 
GeneralSending data in separate TCP packets using Visual C++ Pin
Sergei2-Oct-00 21:42
Sergei2-Oct-00 21:42 
GeneralRe: Sending data in separate TCP packets using Visual C++ Pin
Member 12089653-Oct-00 4:58
Member 12089653-Oct-00 4:58 
GeneralRe: Sending data in separate TCP packets using Visual C++ Pin
Erik Funkenbusch4-Oct-00 13:16
Erik Funkenbusch4-Oct-00 13:16 
GeneralSEH problem in release mode Pin
Robin2-Oct-00 18:26
Robin2-Oct-00 18:26 
GeneralRe: SEH problem in release mode Pin
Feng Yuan2-Oct-00 19:38
Feng Yuan2-Oct-00 19:38 
GeneralRe: SEH problem in release mode Pin
JoeBloggs5-Oct-00 17:34
JoeBloggs5-Oct-00 17:34 
GeneralHandle to a window Pin
Roger2-Oct-00 5:31
Roger2-Oct-00 5:31 
GeneralRe: Handle to a window Pin
Sam Hobbs2-Oct-00 19:39
Sam Hobbs2-Oct-00 19:39 
GeneralRe: Handle to a window Pin
Roger3-Oct-00 1:13
Roger3-Oct-00 1:13 
GeneralRe: Handle to a window Pin
Frank Deo3-Oct-00 1:37
Frank Deo3-Oct-00 1:37 
GeneralRe: Handle to a window Pin
Roger3-Oct-00 1:38
Roger3-Oct-00 1:38 
GeneralRe: Handle to a window Pin
Frank Deo3-Oct-00 1:44
Frank Deo3-Oct-00 1:44 
GeneralRe: Handle to a window Pin
Roger3-Oct-00 1:47
Roger3-Oct-00 1:47 
GeneralRe: Handle to a window Pin
Roger3-Oct-00 1:55
Roger3-Oct-00 1:55 

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.