initial oogynize check in _ this actually used to work!

This commit is contained in:
2016-02-14 21:16:31 -08:00
parent b183af5d55
commit 532ea133bc
337 changed files with 30692 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,17 @@
// ButtonHook.h
#pragma once
#include "CWHPaccess.h"
#ifdef DLLAPI_BUTTON_HOOK
#define ENTRY_FUNCTION extern "C" _declspec(dllexport)
#else
#define ENTRY_FUNCTION extern "C" _declspec(dllimport)
#endif
////
// Entry-Point (Exposed)Functions
////
ENTRY_FUNCTION BOOL WINAPI StartButtonHook(void);
ENTRY_FUNCTION BOOL WINAPI StopButtonHook(void);
ENTRY_FUNCTION BOOL WINAPI IsButtonHookSet(void);
ENTRY_FUNCTION int WINAPI GetAllHookedWindowHandles(int* pBuf);

View File

@@ -0,0 +1,236 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="ButtonHook"
ProjectGUID="{5E8EB95C-9C4F-4DE3-A5E4-827268AF4E9B}"
RootNamespace="ButtonHook"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(InputDir)Target\$(ConfigurationName)"
IntermediateDirectory="$(InputDir)Target\$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;BUTTONHOOK_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="Psapi.lib"
LinkIncremental="2"
DelayLoadDLLs=""
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
CommandLine="copy $(InputDir)Target\$(ConfigurationName)\ButtonHook.dll $(SolutionDir)Target\$(ConfigurationName) /Y&#x0D;&#x0A;copy $(InputDir)Target\$(ConfigurationName)\ButtonHook.pdb $(SolutionDir)Target\$(ConfigurationName) /Y"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(InputDir)Target\$(ConfigurationName)"
IntermediateDirectory="$(InputDir)Target\$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="1"
WholeProgramOptimization="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;BUTTONHOOK_EXPORTS"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="Psapi.lib"
LinkIncremental="1"
GenerateManifest="true"
DelayLoadDLLs=""
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
CommandLine="copy $(InputDir)Target\$(ConfigurationName)\ButtonHook.dll $(SolutionDir)Target\$(ConfigurationName) /Y"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\ButtonHook.cpp"
>
</File>
<File
RelativePath=".\CWHPaccess.cpp"
>
</File>
<File
RelativePath=".\Stdafx.cpp"
>
</File>
<File
RelativePath=".\WPFCaller.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\ButtonHook.h"
>
</File>
<File
RelativePath=".\CWHPaccess.h"
>
</File>
<File
RelativePath=".\resource.h"
>
</File>
<File
RelativePath=".\Stdafx.h"
>
</File>
<File
RelativePath=".\thread.h"
>
</File>
<File
RelativePath=".\WPFCaller.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,390 @@
#include "StdAfx.h"
#include "ButtonStrategy.h"
//#include "HiddenWindow.h" // for Some Strategies we need to create
// a hidden window and draw the buttons on it
////
// We are delay-loading the UXTheme.dll. In case we are running on
// a system where the dll doesn't exist, we'll only load it we know
// that this is a system where it should exist
////
#include "uxtheme.h"
////
// We are delay-loading the DWMapi.dll. In case we are running on
// a system where the dll doesn't exist, we'll only load it we know
// that this is a system where it should exist
////
#include "dwmapi.h"
using namespace Ooganizer;
//********************************************************************
// Clss ButtonStrategy
//
// Programmer Daniel Romischer
// Ooganizer Development Team
//
// Description Base/Abstract Class for all Button Strategies
//
// Note CalcCaptionRect() and CalcCaptionButtonRect()
// is implemented in the base class for now (as it appears
// to be the same calculation for all Button Strategies).
//
// Created 06-01-2008
//********************************************************************
//////////////////////////////////////////////////////////////////////
//********************************************************************
// Construction / Destruction
//********************************************************************
//////////////////////////////////////////////////////////////////////
ButtonStrategy::ButtonStrategy(void)
{
}
ButtonStrategy::~ButtonStrategy(void)
{
}
//////////////////////////////////////////////////////////////////////
// Func: CalcCaptionRect()
// Desc: Calculates the dimensions of the Caption Bar
//
// Prms: +hWnd, handle to a Windows
// +-Rect, returns the x,y RECT area dimension coordinates of the caption bar
// +-SIZE, returns the width and height of the Caption bar
//////////////////////////////////////////////////////////////////////
void ButtonStrategy::CalcCaptionRect(HWND hWnd, RECT &RectCaption, SIZE &heightNwidth)const
{
RECT Rect;
SIZE sFrame;
DWORD dStyle = GetWindowLong( hWnd, GWL_STYLE );
// Get frame size of window
// (x and y height width dim of the resizable or non-resizable windows frame)
sFrame.cy = GetSystemMetrics( ( dStyle & WS_THICKFRAME ) ? SM_CYSIZEFRAME : SM_CYFIXEDFRAME );
sFrame.cx = GetSystemMetrics( ( dStyle & WS_THICKFRAME ) ? SM_CXSIZEFRAME : SM_CXFIXEDFRAME );
// Gets the location of the Window
GetWindowRect( hWnd, &Rect );
// Height and Width of the Window
LONG height = Rect.bottom - Rect.top; // Window height not intersting to us (not used)
LONG width = Rect.right - Rect.left;
// Pass the CaptionBar Dimension out
RectCaption.top = sFrame.cy; // 4, 8
RectCaption.left = sFrame.cx; // 4, 8
RectCaption.right = width - sFrame.cy; // 771
// SM_CYCAPTION = The height of a caption area, in pixels
// SM_CYBORDER = The height of a window border
int heightCaption = GetSystemMetrics( SM_CYCAPTION ); // 20
int heightWindowBorder = GetSystemMetrics( SM_CYBORDER ); // 1
RectCaption.bottom = heightCaption;
//heightCaption gives us the correct caption height, but in order to get the exact RECT location,
//calculated from top left, we need to add sFrame.cy to it. ~we substract the bottom border because,
//otherwise the height will be too long
//sFrame.cy + heightCaption - heightWindowBorder;
// sample return
// top = 4, left = 4, bottom = 23, right = 771
// Pass out the height & Width of the CaptionBar
heightNwidth.cx = heightCaption;
heightNwidth.cy = width;
}
//********************************************************************
// Clss ClassicButtonStrategy
//
// Description Implementation for our Windows Classic Theme Strategy
//
// Note Uses DrawFrameControl() to draw the Button. This will
// Only work in Windows2000/XP without theme (classic View)
//
// Created 06-01-2008
//********************************************************************
//////////////////////////////////////////////////////////////////////
//********************************************************************
// Construction / Destruction
//********************************************************************
//////////////////////////////////////////////////////////////////////
ClassicButtonStrategy::ClassicButtonStrategy()
{
}
ClassicButtonStrategy::~ClassicButtonStrategy()
{
}
//////////////////////////////////////////////////////////////////////
// Func: draw()
// Desc: generic draw function - called for all default messages
//////////////////////////////////////////////////////////////////////
void ClassicButtonStrategy::draw(HWND hWnd, const HDC &hDc, const RECT &rPos) const
{
// Use the regular Frame Control *Windows Classic*
// DrawFrameControl( hDc, const_cast<LPRECT>(&rPos), DFC_BUTTON, DFCS_BUTTONPUSH );
HICON hIcon = (HICON) LoadImage(NULL, L"C:\\bridge.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
DrawIcon(hDc, rPos.left, rPos.top, hIcon);
}
//////////////////////////////////////////////////////////////////////
// Func: drawButtonUp()
// Desc: draw the button in an up state
//////////////////////////////////////////////////////////////////////
void ClassicButtonStrategy::drawButtonUp(HWND hWnd, const HDC &hDc, const RECT &rPos) const
{
// Use the regular Frame Control *Windows Classic*
// DrawFrameControl( hDc, const_cast<LPRECT>(&rPos), DFC_BUTTON, DFCS_BUTTONPUSH );
HICON hIcon = (HICON) LoadImage(NULL, L"C:\\bridge.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
DrawIcon(hDc, rPos.left, rPos.top, hIcon);
}
//////////////////////////////////////////////////////////////////////
// Func: drawButtonDown()
// Desc: draw the button in a down state
//////////////////////////////////////////////////////////////////////
void ClassicButtonStrategy::drawButtonDown(HWND hWnd, const HDC &hDc, const RECT &rPos) const
{
// Use the regular Frame Control *Windows Classic*
// DrawFrameControl( hDc, const_cast<LPRECT>(&rPos), DFC_BUTTON, DFCS_BUTTONPUSH | DFCS_PUSHED );
HICON hIcon = (HICON) LoadImage(NULL, L"C:\\bridge.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
DrawIcon(hDc, rPos.left, rPos.top, hIcon);
}
//********************************************************************
// Clss AeroButtonStrategy
//
// Description Implementation for our Windows Aero Theme Strategy
//
// Note
//
//
// Created 06-01-2008
//********************************************************************
//////////////////////////////////////////////////////////////////////
//********************************************************************
// Construction / Destruction
//********************************************************************
//////////////////////////////////////////////////////////////////////
AeroButtonStrategy::AeroButtonStrategy()
{
}
AeroButtonStrategy::~AeroButtonStrategy()
{
}
//////////////////////////////////////////////////////////////////////
// Func: CalcCaptionButtonRect()
// Desc: Calculates the dimensions of the Caption Button. Takes into
// account the number of caption buttons on the window and returns
// the pos (RECT) where to draw the Caption Button.
//
// Prms: +hWnd, handle to a Windows
// +-RectButtonPos, returns the x,y dimension of where to place the Button
//////////////////////////////////////////////////////////////////////
void AeroButtonStrategy::CalcCaptionButtonRect(HWND hWnd, RECT& RectButtonPos) const
{
// Button Constants
const LONG BUTTON_MARGIN = 2; // The Margin Space between the Buttons
//The width of a button in a window caption or title bar, in pixels
const LONG CAPTION_WIDTH = GetSystemMetrics(SM_CXSIZE); // should be 28
log(LOGGING_HIGH, "Caption Width = %i", CAPTION_WIDTH);
RECT rect;
SIZE size;
// Get The dimensions of the CaptionBar
CalcCaptionRect(hWnd,rect,size);
// sample return from CalcCaptionRect()
// top = 4, left = 4, bottom = 23, right = 771
// On Aero the distance of the Button is 10 not 6. Calculating by multiplying top * 2 (=8)
// ~this makes sense because our Rect start at the top most location (not where vista wants to draw the button
const LONG TOP_PLACEMENT = (2 * rect.top) + BUTTON_MARGIN;
const LONG BOTTOM_PLACEMENT = rect.bottom - BUTTON_MARGIN;
// Left and Right Placement has to be calculated using the spacing on the right, the caption button widths,
// of (close, max, min) and the margins in between the buttons. (RECT includes all caption buttons),
// we also subtract rect.top from the left because a window border on right is not considered (+ another margin)
const LONG RIGHT_PLACEMENT = rect.right - (CAPTION_WIDTH * 3) - (BUTTON_MARGIN * 3) - (rect.top + BUTTON_MARGIN);
const LONG LEFT_PLACEMENT = RIGHT_PLACEMENT - CAPTION_WIDTH; // - BUTTON_MARGIN?
////
// Pass out the dimension of the CaptionButton
////
RectButtonPos.top = TOP_PLACEMENT;
RectButtonPos.bottom = BOTTOM_PLACEMENT;
RectButtonPos.right = RIGHT_PLACEMENT;
RectButtonPos.left = LEFT_PLACEMENT;
}
//////////////////////////////////////////////////////////////////////
// Func: draw()
// Desc: generic draw function - called for all default messages
//////////////////////////////////////////////////////////////////////
void AeroButtonStrategy::draw(HWND hWnd, const HDC &hDc, const RECT &rPos) const
{
// HTHEME hTheme = OpenThemeData(hWnd, L"OkButton;Button;Window");
// HTHEME hTheme = OpenThemeData(hWnd, L"Button");
// DrawThemeParentBackground(hWnd,hDc,&rPos);
// DrawThemeBackground(hTheme,hDc,0,0,&rPos,0);
HICON hIcon = (HICON) LoadImage(NULL, L"C:\\VistaNoAero.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
DrawIcon(hDc, rPos.left, rPos.top, hIcon);
}
//////////////////////////////////////////////////////////////////////
// Func: drawButtonUp()
// Desc: draw the button in an up state
//////////////////////////////////////////////////////////////////////
void AeroButtonStrategy::drawButtonUp(HWND hWnd, const HDC &hDc, const RECT &rPos) const
{
HICON hIcon = (HICON) LoadImage(NULL, L"C:\\bridge.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
DrawIcon(hDc, rPos.left, rPos.top, hIcon);
}
//////////////////////////////////////////////////////////////////////
// Func: drawButtonDown()
// Desc: draw the button in a down state
//////////////////////////////////////////////////////////////////////
void AeroButtonStrategy::drawButtonDown(HWND hWnd, const HDC &hDc, const RECT &rPos) const
{
HICON hIcon = (HICON) LoadImage(NULL, L"C:\\bridge.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
DrawIcon(hDc, rPos.left, rPos.top, hIcon);
}
//********************************************************************
// Clss VistaNoAeroStrategy
//
// Description Implementation for Vista when Aero (Glass) is not running
//
// Note
//
//
// Created 06-01-2008
//********************************************************************
//////////////////////////////////////////////////////////////////////
//********************************************************************
// Construction / Destruction
//********************************************************************
//////////////////////////////////////////////////////////////////////
VistaNoAeroStrategy::VistaNoAeroStrategy()
{
}
VistaNoAeroStrategy::~VistaNoAeroStrategy()
{
}
//////////////////////////////////////////////////////////////////////
// Func: CalcCaptionButtonRect()
// Desc: Calculates the dimensions of the Caption Button. Takes into
// account the number of caption buttons on the window and returns
// the pos (RECT) where to draw the Caption Button.
//
// Prms: +hWnd, handle to a Windows
// +-RectButtonPos, returns the x,y dimension of where to place the Button
//////////////////////////////////////////////////////////////////////
void VistaNoAeroStrategy::CalcCaptionButtonRect(HWND hWnd, RECT& RectButtonPos) const
{
// Button Constants
const LONG BUTTON_MARGIN = 2; // The Margin Space between the Buttons
//The width of a button in a window caption or title bar, in pixels
const LONG CAPTION_WIDTH = GetSystemMetrics(SM_CXSIZE); // 32 (appears to include left and righ Margin)
RECT rect;
SIZE size;
// Get The dimensions of the CaptionBar
CalcCaptionRect(hWnd,rect,size);
log(LOGGING_HIGH, "rect is top %i, bottom %i, left %i, right %i", rect.top, rect.bottom, rect.left, rect.right);
// sample return from CalcCaptionRect()
// Vista Aero
// top = 4, left = 4, bottom = 23, right = 771
// Vista NoAero
// rect is top 8, bottom 27, left 8, right 831
// On Aero the distance of the Button is 10 not 6. Calculating by multiplying top * 2 (=8)
// ~this makes sense because our Rect start at the top most location (not where vista wants to draw the button
const LONG TOP_PLACEMENT = 10; //(2 * rect.top) + BUTTON_MARGIN;
const LONG BOTTOM_PLACEMENT = rect.bottom - BUTTON_MARGIN;
// Left and Right Placement has to be calculated using the spacing on the right, the caption button widths,
// of (close, max, min) and the margins in between the buttons. (RECT includes all caption buttons),
// we also subtract rect.top from the left because a window border on right is not considered (+ another margin)
// 96
const LONG RIGHT_PLACEMENT = rect.right - 96;
const LONG LEFT_PLACEMENT = RIGHT_PLACEMENT - 28; // - BUTTON_MARGIN?
////
// Pass out the dimension of the CaptionButton
////
RectButtonPos.top = TOP_PLACEMENT;
RectButtonPos.bottom = BOTTOM_PLACEMENT;
RectButtonPos.right = RIGHT_PLACEMENT;
RectButtonPos.left = LEFT_PLACEMENT;
}
//////////////////////////////////////////////////////////////////////
// Func: draw()
// Desc: generic draw function - called for all default messages
//////////////////////////////////////////////////////////////////////
void VistaNoAeroStrategy::draw(HWND hWnd, const HDC &hDc, const RECT &rPos) const
{
HICON hIcon = (HICON) LoadImage(NULL, L"C:\\VistaNoAero.ico", IMAGE_ICON, 28, 15, LR_LOADFROMFILE);
DrawIcon(hDc, rPos.left, rPos.top, hIcon);
}
//////////////////////////////////////////////////////////////////////
// Func: drawButtonUp()
// Desc: draw the button in an up state
//////////////////////////////////////////////////////////////////////
void VistaNoAeroStrategy::drawButtonUp(HWND hWnd, const HDC &hDc, const RECT &rPos) const
{
}
//////////////////////////////////////////////////////////////////////
// Func: drawButtonDown()
// Desc: draw the button in a down state
//////////////////////////////////////////////////////////////////////
void VistaNoAeroStrategy::drawButtonDown(HWND hWnd, const HDC &hDc, const RECT &rPos) const
{
}
//********************************************************************
// Clss XPButtonStrategy
//
// Description Implementation for Windows XP Themed Strategy
//
// Note
//
//
// Created 06-01-2008
//********************************************************************
//////////////////////////////////////////////////////////////////////
//********************************************************************
// Construction / Destruction
//********************************************************************
//////////////////////////////////////////////////////////////////////
XPButtonStrategy::XPButtonStrategy()
{
}
XPButtonStrategy::~XPButtonStrategy()
{
}
//////////////////////////////////////////////////////////////////////
// Func: draw()
// Desc: generic draw function - called for all default messages
//////////////////////////////////////////////////////////////////////
void XPButtonStrategy::draw(HWND hWnd, const HDC &hDc, const RECT &rPos) const
{
}
//////////////////////////////////////////////////////////////////////
// Func: drawButtonUp()
// Desc: draw the button in an up state
//////////////////////////////////////////////////////////////////////
void XPButtonStrategy::drawButtonUp(HWND hWnd, const HDC &hDc, const RECT &rPos) const
{
}
//////////////////////////////////////////////////////////////////////
// Func: drawButtonDown()
// Desc: draw the button in a down state
//////////////////////////////////////////////////////////////////////
void XPButtonStrategy::drawButtonDown(HWND hWnd, const HDC &hDc, const RECT &rPos) const
{
}

View File

@@ -0,0 +1,102 @@
#pragma once
namespace Ooganizer
{
//////////////////////////////////////////////////////////////////////
// Itce: ButtonStrategy
// Desc: This interface allows us to abstract out specific implementations
// for different caption buttons with different Themes.
//
// Note: following functions will be called from the windows messages to
// be implemented directly here independently and draw only the button.
//
// Note2: Each Button Strategy is directly tied to a C
//////////////////////////////////////////////////////////////////////
class ButtonStrategy
{
public:
// generic draw function - called for all default messages
virtual void draw(HWND hWnd, const HDC &hdc, const RECT &rpos) const = 0;
// draw the button in an up state
virtual void drawButtonUp(HWND hWnd, const HDC &hDc, const RECT &rPos) const = 0;
// draw the button in a down state
virtual void drawButtonDown(HWND hWnd, const HDC &hDc, const RECT &rPos) const = 0;
// returns the RECT position of the the CaptionButton
virtual void CalcCaptionButtonRect(HWND hWnd, RECT& RectButtonPos) const = 0;
////
// returns the dimension / size of the caption / title bar (impl. in base)
////
void CalcCaptionRect(HWND hWnd, RECT& RectCaption, SIZE &heightNwidth) const;
ButtonStrategy(void);
virtual ~ButtonStrategy(void);
};
//////////////////////////////////////////////////////////////////////
// Clss: ClassicButtonStrategy
// Desc: Implementation for our Windows Classic Theme Strategy
//////////////////////////////////////////////////////////////////////
class ClassicButtonStrategy : public ButtonStrategy
{
public:
void draw(HWND hWnd, const HDC &hdc, const RECT &rpos) const;
void drawButtonUp(HWND hWnd, const HDC &hDc, const RECT &rPos) const;
void drawButtonDown(HWND hWnd, const HDC &hDc, const RECT &rPos) const;
void CalcCaptionButtonRect(HWND hWnd, RECT& RectButtonPos) const {};
ClassicButtonStrategy();
virtual ~ClassicButtonStrategy();
};
//////////////////////////////////////////////////////////////////////
// Clss: AeroButtonStrategy
// Desc: Implementation for our Windows Aero (Glass) Strategy
//////////////////////////////////////////////////////////////////////
class AeroButtonStrategy : public ButtonStrategy
{
public:
virtual void draw(HWND hWnd, const HDC &hdc, const RECT &rpos) const;
void drawButtonUp(HWND hWnd, const HDC &hDc, const RECT &rPos) const;
void drawButtonDown(HWND hWnd, const HDC &hDc, const RECT &rPos) const;
void CalcCaptionButtonRect(HWND hWnd, RECT& RectButtonPos) const;
AeroButtonStrategy();
virtual ~AeroButtonStrategy();
};
//////////////////////////////////////////////////////////////////////
// Clss: VistaNoAeroStrategy
// Desc: Implementation for Vista when Aero (Glass) is not running
//////////////////////////////////////////////////////////////////////
class VistaNoAeroStrategy : public ButtonStrategy
{
public:
virtual void draw(HWND hWnd, const HDC &hdc, const RECT &rpos) const;
void drawButtonUp(HWND hWnd, const HDC &hDc, const RECT &rPos) const;
void drawButtonDown(HWND hWnd, const HDC &hDc, const RECT &rPos) const;
void CalcCaptionButtonRect(HWND hWnd, RECT& RectButtonPos) const;
// Uses Hidden Window Strategy
VistaNoAeroStrategy();
virtual ~VistaNoAeroStrategy();
};
//////////////////////////////////////////////////////////////////////
// Clss: XPButtonStrategy
// Desc: Implementation for Windows XP Themed Strategy
//////////////////////////////////////////////////////////////////////
class XPButtonStrategy : public ButtonStrategy
{
public:
virtual void draw(HWND hWnd, const HDC &hdc, const RECT &rpos) const;
void drawButtonUp(HWND hWnd, const HDC &hDc, const RECT &rPos) const;
void drawButtonDown(HWND hWnd, const HDC &hDc, const RECT &rPos) const;
void CalcCaptionButtonRect(HWND hWnd, RECT& RectButtonPos) const{};
XPButtonStrategy();
virtual ~XPButtonStrategy();
};
}

View File

@@ -0,0 +1,414 @@
#include "stdafx.h"
#include "CWHPaccess.h"
using namespace Ooganizer;
//////////////////////////////////////////////////////////////////////
//********************************************************************
// Global variables - Shared Data Segment (Shared across all instances
// of this dll!)
//********************************************************************
//////////////////////////////////////////////////////////////////////
#pragma data_seg( ".CWHP" )
HHOOK CWHPaccess::hHook = NULL;
HookWndItem CWHPaccess::HList[MAX_PATH] = {NULL,NULL,NULL,NULL};
UINT CWHPaccess::HListI = 0;
wchar_t CWHPaccess::ALLOWED_PROCESS_NAMES[MAX_PATH][MAX_PATH] = {0};
UINT CWHPaccess::NUMBER_OF_ALLOWED_PROCESS_NAMES = 0;
wchar_t CWHPaccess::ALLOWED_WINDOW_TITLES[MAX_PATH][MAX_PATH] = {0};
UINT CWHPaccess::NUMBER_OF_ALLOWED_WINDOW_TITLES = 0;
wchar_t CWHPaccess::ALLOWED_WINDOW_CLASSES[MAX_PATH][MAX_PATH] = {0};
UINT CWHPaccess::NUMBER_OF_ALLOWED_WINDOW_CLASSES = 0;
UINT CWHPaccess::nLoggingDetail = LOGGING_NONE;
wchar_t CWHPaccess::LoggingPath[MAX_PATH] = {0};
#pragma data_seg()
#pragma comment( linker, "/SECTION:.CWHP,rws" )
//////////////////////////////////////////////////////////////////////
// Constructor / Destructor
//////////////////////////////////////////////////////////////////////
CWHPaccess::CWHPaccess()
{
InitializeCriticalSection(&cs);
}
CWHPaccess::~CWHPaccess()
{
DeleteCriticalSection(&cs);
}
// Set/Get hHook
void CWHPaccess::set_hHook(HHOOK hook)
{
EnterCS();
hHook = hook;
LeaveCS();
}
HHOOK CWHPaccess::get_hHook()
{
return hHook;
}
// Public CRITICAL_SECTION Accessors
void CWHPaccess::EnterCS()
{
EnterCriticalSection(&cs);
}
void CWHPaccess::LeaveCS()
{
LeaveCriticalSection(&cs);
}
//////////////////////////////////////////////////////////////////////
// Func: ClearHookItem()
// Desc: Clears a single Hook Item
//////////////////////////////////////////////////////////////////////
void CWHPaccess::ClearHookItem(UINT nItem)
{
if((nItem < 0) || (nItem >= MAX_PATH))
return;
HList[nItem].hWnd = NULL;
HList[nItem].DefWndProc = NULL;
HList[nItem].HookWndProc = NULL;
HList[nItem].wpfcaller = NULL;
}
//////////////////////////////////////////////////////////////////////
// Func: ClearHookSData()
// Desc: Clears all the data stored in the Shared DS segment's Hook List
//////////////////////////////////////////////////////////////////////
void CWHPaccess::ClearHookSData()
{
EnterCS();
hHook = NULL;
HListI = 0;
for (int i=0; i < MAX_PATH; ++i)
ClearHookItem(i);
LeaveCS();
}
//////////////////////////////////////////////////////////////////////
// Func: InsertHookedWndItem()
// Desc: Inserts a HookWndItem into the Shared DS's HookedList
//////////////////////////////////////////////////////////////////////
BOOL CWHPaccess::InsertHookedWndItem(HookWndItem &Item)
{
BOOL bRetVal = FALSE;
EnterCS();
for (UINT i = 0;i < MAX_PATH; ++i)
{
if(HList[i].hWnd == NULL)
{
HList[i] = Item;
log(LOGGING_DEBUG, L"Inserting HookedItem into DS index = %i", i);
// Keep track of the list top index *performance*
if(i > HListI)
{
HListI = i;
log(LOGGING_DEBUG, L"Inserting HookedItem setting HListI = %i", HListI);
}
bRetVal = TRUE;
break;
}
}
LeaveCS();
return bRetVal;
}
//////////////////////////////////////////////////////////////////////
// Func: FindHookedWnd()
// Desc: Finds Inserts a HookWndItem into the Shared DS's HookedList
//////////////////////////////////////////////////////////////////////
BOOL CWHPaccess::FindHookedWnd(HWND hWnd)
{
BOOL bRetVal = FALSE;
EnterCS();
for (UINT i = 0;i <= HListI;++i)
{
if(HList[i].hWnd == hWnd)
{
bRetVal = TRUE;
break;
}
}
LeaveCS();
return bRetVal;
}
//////////////////////////////////////////////////////////////////////
// Func: GetHookedWndItem()
// Desc: Returns a matchin HookWndItem (.hWnd will be NULL if not found)
//////////////////////////////////////////////////////////////////////
HookWndItem CWHPaccess::GetHookedWndItem(HWND hWnd)
{
BLANK_HookWndItem(retVal);
EnterCS();
for (UINT i = 0;i <= HListI;++i)
{
if(HList[i].hWnd == hWnd)
{
retVal = HList[i];
}
}
LeaveCS();
return(retVal);
}
//////////////////////////////////////////////////////////////////////
// Func: GetHookedWindowListNSize()
// Desc: Use this to get a copy of the hooked window buffer and size in the Shared DS
//////////////////////////////////////////////////////////////////////
void CWHPaccess::GetHookedWindowListNSize(int* nbuf, int* nsize)
{
EnterCS();
// write out the size
*nsize = HListI;
for (UINT i = 0;i <= HListI;++i)
{
// write out the actual buffer
*(nbuf + i) = (int) HList[i].hWnd;
}
LeaveCS();
}
//////////////////////////////////////////////////////////////////////
// Func: SetHookedWndItem()
// Desc: Use this to overwrite Hook information for a window in the Shared DS
//////////////////////////////////////////////////////////////////////
BOOL CWHPaccess::SetHookedWndItem(HWND hWnd, HookWndItem& Item)
{
BOOL bRetVal = FALSE;
EnterCS();
for (UINT i = 0;i <= HListI;++i)
{
if((HList[i].hWnd == hWnd) &&
(hWnd == Item.hWnd))
{
HList[i] = Item;
bRetVal = TRUE;
}
}
LeaveCS();
return bRetVal;
}
//////////////////////////////////////////////////////////////////////
// Func: DeleteHookedWnd()
// Desc: Finds Inserts a HookWndItem into the Shared DS's HookedList
//////////////////////////////////////////////////////////////////////
BOOL CWHPaccess::DeleteHookedWnd(HWND hWnd)
{
BOOL retVal = FALSE;
EnterCS();
// Is it the Last Item in the list?
if(HList[HListI].hWnd == hWnd)
{
ClearHookItem(HListI);
if(HListI > 0)
{
HListI = HListI - 1;
log(LOGGING_DEBUG, L"DeleteHookedWnd HListI set to %i", HListI);
}
retVal = TRUE;
}
else
{
for (UINT i = 0; i <= HListI; ++i)
{
if(HList[i].hWnd == hWnd)
{
ClearHookItem(i);
deltaListTopI(i);
retVal = TRUE;
break;
}
}
}
LeaveCS();
return retVal;
}
//////////////////////////////////////////////////////////////////////
// Func: deltaListTopI()
// Desc: *for performance * adjusts the Top index responding to a delete
//////////////////////////////////////////////////////////////////////
void CWHPaccess::deltaListTopI(int deletedIndex)
{
UINT i;
EnterCS();
for(i = deletedIndex + 1; i <= HListI; ++i)
{
if(HList[i].hWnd == NULL)
{
continue;
}
break;
}
if(i > HListI)
{
if(deletedIndex > 0)
{
HListI = deletedIndex - 1;
log(LOGGING_DEBUG, L"deltaListTopI HListI set to %i", HListI);
}
else
{
log(LOGGING_DEBUG, L"deltaListTopI HListI set to %i", HListI);
HListI = 0;
}
}
LeaveCS();
}
//////////////////////////////////////////////////////////////////////
// Func: AddAllowedProcessName()
// Desc: Add Allowed Process Name
//////////////////////////////////////////////////////////////////////
void CWHPaccess::AddAllowedProcessName(wchar_t* strProcessNameInUpperCase)
{
if(strProcessNameInUpperCase)
{
EnterCS();
int i = NUMBER_OF_ALLOWED_PROCESS_NAMES;
lstrcpyn(ALLOWED_PROCESS_NAMES[i], strProcessNameInUpperCase, MAX_PATH - 1);
NUMBER_OF_ALLOWED_PROCESS_NAMES = i + 1;
LeaveCS();
log(LOGGING_DEBUG, L"Allowing Process %s", strProcessNameInUpperCase);
}
}
//////////////////////////////////////////////////////////////////////
// Func: IsAllowedProcessName()
// Desc: Find Allowed Process Name
//////////////////////////////////////////////////////////////////////
BOOL CWHPaccess::IsAllowedProcessName(wchar_t* strProcessNameInUpperCase)
{
BOOL bRetVal = FALSE;
if(strProcessNameInUpperCase)
{
EnterCS();
for (UINT i = 0; i < NUMBER_OF_ALLOWED_PROCESS_NAMES; ++i)
{
if(wcsstr(strProcessNameInUpperCase, ALLOWED_PROCESS_NAMES[i]))
{
bRetVal = TRUE;
break;
}
}
LeaveCS();
}
return bRetVal;
}
//////////////////////////////////////////////////////////////////////
// Func: AddAllowedApplication()
// Desc: Add Allowed Windows Titles
//////////////////////////////////////////////////////////////////////
void CWHPaccess::AddAllowedWindowsTitle(wchar_t* strWindowsTitleInUpperCase)
{
if(strWindowsTitleInUpperCase)
{
EnterCS();
int i = NUMBER_OF_ALLOWED_WINDOW_TITLES;
lstrcpyn(ALLOWED_WINDOW_TITLES[i], strWindowsTitleInUpperCase, MAX_PATH - 1);
NUMBER_OF_ALLOWED_WINDOW_TITLES = i + 1;
LeaveCS();
log(LOGGING_DEBUG, L"Allowing Window %s", strWindowsTitleInUpperCase);
}
}
//////////////////////////////////////////////////////////////////////
// Func: IsAllowedWindowsTitle()
// Desc: Find Allowed Window Title
//////////////////////////////////////////////////////////////////////
BOOL CWHPaccess::IsAllowedWindowsTitle(wchar_t* strWindowsTitleInUpperCase)
{
BOOL bRetVal = FALSE;
if(strWindowsTitleInUpperCase)
{
EnterCS();
for (UINT i = 0; i < NUMBER_OF_ALLOWED_WINDOW_TITLES; ++i)
{
if(wcsstr(strWindowsTitleInUpperCase, ALLOWED_WINDOW_TITLES[i]))
{
bRetVal = TRUE;
break;
}
}
LeaveCS();
}
return bRetVal;
}
//////////////////////////////////////////////////////////////////////
// Func: AddAllowedWindowsClass()
// Desc: Add Allowed Windows Class
//////////////////////////////////////////////////////////////////////
void CWHPaccess::AddAllowedWindowsClass(wchar_t* strWindowsClassInUpperCase)
{
if(strWindowsClassInUpperCase)
{
EnterCS();
int i = NUMBER_OF_ALLOWED_WINDOW_CLASSES;
lstrcpyn(ALLOWED_WINDOW_CLASSES[i], strWindowsClassInUpperCase, MAX_PATH - 1);
NUMBER_OF_ALLOWED_WINDOW_CLASSES = i + 1;
LeaveCS();
log(LOGGING_DEBUG, L"Allowing Window Class %s", strWindowsClassInUpperCase);
}
}
//////////////////////////////////////////////////////////////////////
// Func: IsAllowedWindowsClass()
// Desc: Find Allowed Window Class
//////////////////////////////////////////////////////////////////////
BOOL CWHPaccess::IsAllowedWindowsClass(wchar_t* strWindowsClassInUpperCase)
{
BOOL bRetVal = FALSE;
if(strWindowsClassInUpperCase)
{
EnterCS();
for (UINT i = 0; i < NUMBER_OF_ALLOWED_WINDOW_CLASSES; ++i)
{
if(wcsstr(strWindowsClassInUpperCase, ALLOWED_WINDOW_CLASSES[i]))
{
bRetVal = TRUE;
break;
}
}
LeaveCS();
}
return bRetVal;
}
//////////////////////////////////////////////////////////////////////
// Func: SetLoggingDetail()
// Desc: Allows us to set a global used by all button hooks to log
//////////////////////////////////////////////////////////////////////
void CWHPaccess::SetLoggingDetail(LoggingDetail nLoggingDetailSetting)
{
EnterCS();
nLoggingDetail = nLoggingDetailSetting;
LeaveCS();
}
//////////////////////////////////////////////////////////////////////
// Desc: Returns the Detail of our Logging (high, medium, low, or none)
//////////////////////////////////////////////////////////////////////
LoggingDetail CWHPaccess::GetLoggingDetail()
{
return (static_cast<LoggingDetail>(nLoggingDetail));
}
//////////////////////////////////////////////////////////////////////
// Desc: Get Directory location where we should log to
//////////////////////////////////////////////////////////////////////
wchar_t* CWHPaccess::GetLogPath()
{
return reinterpret_cast<wchar_t*>(&LoggingPath);
}
//////////////////////////////////////////////////////////////////////
// Desc: Set Directory location where we should log to
//////////////////////////////////////////////////////////////////////
void CWHPaccess::SetLogPath(wchar_t* buf)
{
EnterCS();
lstrcpyn(LoggingPath,buf,MAX_PATH - 1);
EnterCS();
}

View File

@@ -0,0 +1,97 @@
// CWHPaccess.h
#pragma once
#include "WPFCaller.h"
namespace Ooganizer
{
//////////////////////////////////////////////////////////////////////
//********************************************************************
// DS access Class - Created to easily enforce critical sections and
// share the statically created DS
//********************************************************************
//////////////////////////////////////////////////////////////////////
class CWHPaccess
{
public:
////
// All these statics are put into the DS and shared accross all DLL instances
// ~Use accessor functions below to modify these
////
static HINSTANCE hModule;
static HHOOK hHook;
static HookWndItem HList[MAX_PATH];
static UINT HListI;
static wchar_t ALLOWED_PROCESS_NAMES[MAX_PATH][MAX_PATH];
static UINT NUMBER_OF_ALLOWED_PROCESS_NAMES;
static wchar_t ALLOWED_WINDOW_TITLES[MAX_PATH][MAX_PATH];
static UINT NUMBER_OF_ALLOWED_WINDOW_TITLES;
static wchar_t ALLOWED_WINDOW_CLASSES[MAX_PATH][MAX_PATH];
static UINT NUMBER_OF_ALLOWED_WINDOW_CLASSES;
static UINT nLoggingDetail;
static wchar_t LoggingPath[MAX_PATH];
// Hook Handle
void set_hHook(HHOOK);
HHOOK get_hHook();
// Clears all Shared DS segment's Hook List data
// (imp, when releasing the hook)
void ClearHookSData();
// Allows a Caller to get a copy of all hooked Window Handles
// and size of the hooked window list
void GetHookedWindowListNSize(int* nbuf, int* nsize);
////
// Find,Insert,Deletion of HookWnd
////
BOOL InsertHookedWndItem(HookWndItem& Item);
BOOL FindHookedWnd(HWND hWnd);
HookWndItem GetHookedWndItem(HWND hWnd);
BOOL SetHookedWndItem(HWND hWnd, HookWndItem& Item);
BOOL DeleteHookedWnd(HWND hWnd);
////
// Allowed ProcessNames & WindowTitles & Classes WhiteList
////
void AddAllowedProcessName(wchar_t* strProcessNameInUpperCase);
BOOL IsAllowedProcessName(wchar_t* strProcessNameInUpperCase);
void AddAllowedWindowsTitle(wchar_t* strWindowsTitleInUpperCase);
BOOL IsAllowedWindowsTitle(wchar_t* strWindowsTitleInUpperCase);
void AddAllowedWindowsClass(wchar_t* strWindowsClassInUpperCase);
BOOL IsAllowedWindowsClass(wchar_t* strWindowsClassInUpperCase);
////
// Get/Set and use Logging Detail Levels
////
void SetLoggingDetail(LoggingDetail nLoggingDetailSetting);
LoggingDetail GetLoggingDetail();
wchar_t* GetLogPath();
void SetLogPath(wchar_t* buf);
// CRITICAL_SECTION
void EnterCS();
void LeaveCS();
CWHPaccess();
~CWHPaccess();
private:
////
// Private functions to keep track of iteration
////
void deltaListTopI(int);
////
// Private Helper Functions
////
void ClearHookItem(UINT nItem);
//Many threads could update the DS.
CRITICAL_SECTION cs;
};
}

151
Hooks/ButtonHook/HookList.h Normal file
View File

@@ -0,0 +1,151 @@
//#pragma once
//
//#include "malloc.h"
//
//namespace Ooganizer
//{
//
// enum ButtonState{BUTTON_UP,BUTTON_DOWN};
//
// //////////////////////////////////////////////////////////////////////
// // Clss: HookItem
// // Desc: Hook Item is used in the HookList. Each HookItem keeps track
// // of all the addresses needed for each hook, as well as the
// // hookstate.
// //
// // Note: Add State Items for a Window as neccessary
// //////////////////////////////////////////////////////////////////////
// class HookItem
// {
// public:
// HWND m_hWnd;
// WNDPROC m_HookWndProc;
// WNDPROC m_DefWndProc;
// ButtonState m_btnState;
//
// // Constructor
// HookItem(HWND hWnd, WNDPROC hookWndProc, WNDPROC defWndProc):
// m_hWnd(hWnd),
// m_HookWndProc(hookWndProc),
// m_DefWndProc(defWndProc),
// m_btnState(BUTTON_UP)
// {
// }
// };
// //////////////////////////////////////////////////////////////////////
// // Clss: HookList
// // Desc: Generic List / Custom written list for the sake of speed.
// // Hook list is made up of individual HookItems.
// //
// // Note: You can use GetNext() to iterate thru all the items in the list.
// // ~adding or removing an item causes GetNext() to start over.
// //////////////////////////////////////////////////////////////////////
// class HookList
// {
// public:
// //////////////////////////////////////////////////////////////////////
// // Func: AddItem()
// // Desc: Adds a HookItem to the List
// //////////////////////////////////////////////////////////////////////
// void AddItem(HookItem* pItem)
// {
// m_NbrItems++;
//
// if ( m_pHookItem == NULL )
// m_pHookItem = (HookItem*) malloc( m_NbrItems * sizeof( HookItem ) );
// else
// m_pHookItem = (HookItem*) realloc( m_pHookItem, m_NbrItems * sizeof( HookItem ) );
//
// log(pItem->m_hWnd,"hase been added");
//
// memcpy( m_pHookItem+(m_NbrItems-1), pItem, sizeof( HookItem ) );
// }
// //////////////////////////////////////////////////////////////////////
// // Func: GetItem()
// // Desc: Get a HookItem from the List
// //////////////////////////////////////////////////////////////////////
// HookItem* GetItem(HWND hWnd)
// {
// UINT i;
// HookItem * pItem = m_pHookItem;
// for( i=0; i<m_NbrItems && pItem->m_hWnd!=hWnd; i++, pItem++ );
// return ( i < m_NbrItems ) ? pItem : NULL;
// }
// //////////////////////////////////////////////////////////////////////
// // Func: DelItem()
// // Desc: Deletes a HookItem from the List
// //////////////////////////////////////////////////////////////////////
// void DelItem(HWND hWnd)
// {
// UINT i;
// HookItem * pItem = m_pHookItem;
// for( i =0; i<m_NbrItems && pItem->m_hWnd!=hWnd; i++, pItem++ );
// if ( i < m_NbrItems )
// {
// m_NbrItems--;
// memcpy( pItem, pItem+1, ( m_NbrItems - i ) * sizeof( HookItem ) );
// m_pHookItem = (HookItem*) realloc( m_pHookItem, m_NbrItems * sizeof( HookItem ) );
//
// log(pItem->m_hWnd,"hase been deleted");
// }
// }
// //////////////////////////////////////////////////////////////////////
// // Func: DelAllItems()
// // Desc: Deletes all HookItems from the List
// //////////////////////////////////////////////////////////////////////
// void DelAllItems()
// {
// if ( m_pHookItem != NULL )
// free( m_pHookItem );
// m_pHookItem = NULL;
// m_NbrItems = 0;
// }
// //////////////////////////////////////////////////////////////////////
// // Func: UnhookAllItems()
// // Desc: Responsible for iterating through entire list and 'unhooking'
// // the WndProc function of every HookItem
// //
// // Note: has to be put in here since the list has to be iterated here
// //////////////////////////////////////////////////////////////////////
// void UnhookAllItems()
// {
// HookItem * pItem;
//
// while ( m_NbrItems > 0 )
// {
// pItem = m_pHookItem+(m_NbrItems-1);
//
// // Unhook window
// HWND hWnd = pItem->m_hWnd;
//
// log(hWnd,"Unhooking...");
// SetWindowLong( hWnd, GWL_WNDPROC, (LONG) pItem->m_DefWndProc );
// SendMessage( hWnd, WM_NCPAINT, 1, 0 );
// log(hWnd,"Sending WM_NCPAINT message...");
//
// // Delete item
// DelItem( hWnd );
// }
// }
// //////////////////////////////////////////////////////////////////////
// // Func: CleanUp()
// // Desc: Unhooks all HookItems in the list and deletes the list
// //////////////////////////////////////////////////////////////////////
// void CleanUp()
// {
// UnhookAllItems();
// DelAllItems();
// }
// //////////////////////////////////////////////////////////////////////
// //********************************************************************
// // Construction / Destruction
// //********************************************************************
// //////////////////////////////////////////////////////////////////////
// HookList():m_NbrItems(0),m_pHookItem(NULL){}
// ~HookList(){CleanUp();}
//
// protected:
// UINT m_NbrItems;
// HookItem* m_pHookItem;
// };
//}

View File

@@ -0,0 +1,20 @@
// HookWndItem.h
#pragma once
extern class CaptionButton;
//////////////////////////////////////////////////////////////////////
// Strc: HookWndItem
// Desc: Hook Item is used in the HookedWndList. Each HookWndItem keeps track
// of all the addresses needed for each hook for each Windows,
// as well as each Window's ButtonState.
//
// Note: Add State Items for a Window as neccessary
//////////////////////////////////////////////////////////////////////
struct HookWndItem
{
HWND hWnd;
WNDPROC HookWndProc;
WNDPROC DefWndProc;
ButtonState state;
CaptionButton* button;
};

153
Hooks/ButtonHook/Stdafx.cpp Normal file
View File

@@ -0,0 +1,153 @@
// stdafx.cpp : source file that includes just the standard includes
// Ooganizer-Hook.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
//////////////////////////////////////////////////////////////////////
// Func: SetLoggingDetail()
//////////////////////////////////////////////////////////////////////
void SetLoggingDetail(LoggingDetail detail, wchar_t* logPath)
{
#ifdef _DEBUG
g_LoggingDetail = LOGGING_DEBUG;
#else
g_LoggingDetail = detail;
#endif
// If the log path is set externally set it here internally
// else set the log path to %USERPROFILE%\AppData\Local\Temp
if(logPath && logPath[0] != 0)
{
lstrcpyn(g_LogPath, logPath, (MAX_PATH - lstrlen(g_LOG_FILE_NAME)));
}
else
{
size_t len = 0;
errno_t err = 0;
wchar_t* pValue = NULL;
if(err = _wdupenv_s( &pValue, &len, L"TMP"))
if(err = _wdupenv_s( &pValue, &len, L"TEMP"))
return;
if(pValue != NULL)
lstrcpyn(g_LogPath, pValue, (MAX_PATH - lstrlen(g_LOG_FILE_NAME)));
}
// Make sure Path ends with '\'
if(g_LogPath[lstrlen(g_LogPath) - 1] != L'\\')
lstrcat(g_LogPath, L"\\");
// Add the Log File name to the path variable (now we have everything)
// ~we are ready to do some serious logging
lstrcat(g_LogPath,g_LOG_FILE_NAME);
}
//////////////////////////////////////////////////////////////////////
// Func: GetLoggingDetail()
//////////////////////////////////////////////////////////////////////
_LoggingDetail GetLoggingDetail()
{
return g_LoggingDetail;
}
//////////////////////////////////////////////////////////////////////
// Func: log()
// Desc: Logs to Ooganizer.log in defined LogPath or temporary folder
// Prms: Variable # of params
//
// Usge: Log("%s %d %d %d", "test", 1, 2, 3)
//////////////////////////////////////////////////////////////////////
//void log( LoggingDetail detail, char * pFmt, ... )
//{
// if(g_LoggingDetail >= detail)
// {
// FILE* pFile = NULL;
// errno_t err = 0;
//
// if ( !( err = fopen_s( &pFile, g_LogPath, "at" ) ) )
// {
// fprintf( pFile, "ThreadId %i -", GetCurrentThreadId());
// va_list arg;
// va_start( arg, pFmt );
// vfprintf( pFile, pFmt, arg );
// va_end( arg );
//
// if ( pFmt[strlen( pFmt ) - 1] != '\n' )
// fprintf( pFile, "\n" );
// fclose( pFile );
// }
// }
//}
//////////////////////////////////////////////////////////////////////
// Func: log()
// Desc: Logs to Ooganizer.log in defined LogPath or temporary folder using Wide Char
// Prms: Variable # of params
//
// Usge: Log("%s %d %d %d", "test", 1, 2, 3)
//////////////////////////////////////////////////////////////////////
void log( LoggingDetail detail, wchar_t * pFmt, ... )
{
if(g_LoggingDetail >= detail)
{
FILE* pFile = NULL;
errno_t err = 0;
if ( !( err = _wfopen_s( &pFile, g_LogPath, L"at" ) ) )
{
if(detail == LOGGING_LOW)
fwprintf( pFile, L"ThreadId %i - [Imp] - ", GetCurrentThreadId()); // low == very important messages
else if(detail == LOGGING_MEDIUM)
fwprintf( pFile, L"ThreadId %i - {P/D} - ", GetCurrentThreadId()); // medium == program details
else if(detail == LOGGING_HIGH)
fwprintf( pFile, L"ThreadId %i - {X/D} - ", GetCurrentThreadId()); // high == more program details (extra}
else if(detail == LOGGING_DEBUG)
fwprintf( pFile, L"ThreadId %i - Debug - ", GetCurrentThreadId()); // debug == only show up in debug builds (Debug Only)
else
fwprintf( pFile, L"ThreadId %i - <N/A> - ", GetCurrentThreadId()); // should never happen
va_list arg;
va_start( arg, pFmt );
vfwprintf( pFile, pFmt, arg );
va_end( arg );
if ( pFmt[lstrlen( pFmt ) - 1] != '\n' )
fwprintf( pFile, L"\n" );
fclose( pFile );
}
}
}
//////////////////////////////////////////////////////////////////////
// Func: log()
// Desc: Logs the window title text to the Log File
// Prms: HWND, handle to a window
// str, custom string to log
//
// Note: GetWindowText doesn't always return TRUE, if this function
// gets called during the WndProc it will return False
//////////////////////////////////////////////////////////////////////
void log(LoggingDetail detail, HWND hWnd, wchar_t* str)
{
if(g_LoggingDetail >= detail)
{
wchar_t Title[MAX_PATH + 1] = {0};
if (GetWindowText(hWnd,Title,MAX_PATH))
log(detail, L"Window - %s - %s", Title, str);
}
}
//////////////////////////////////////////////////////////////////////
// Func: clearLog()
// Desc: clears the log file (used at startup) - Only Clears if Logging is enabled
//////////////////////////////////////////////////////////////////////
void clearLog()
{
if(g_LoggingDetail != LOGGING_NONE)
{
FILE* pFile = NULL;
errno_t err = 0;
if( !( err = _wfopen_s( &pFile, g_LogPath, L"w" ) ) )
fclose( pFile );
}
}

47
Hooks/ButtonHook/Stdafx.h Normal file
View File

@@ -0,0 +1,47 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#pragma once
// Compiler Error Messages that we want to disable:
#pragma warning ( disable : 4793 ) // Compiling functions as native code
#pragma warning ( disable : 4996 ) // 'strncpy': This function or variable may be unsafe
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
//////////////////////////////////////////////////////////////////////
//********************************************************************
// Global Enums
//********************************************************************
//////////////////////////////////////////////////////////////////////
// Logging Detail Settings
typedef enum _LoggingDetail{LOGGING_NONE,LOGGING_LOW,LOGGING_MEDIUM,LOGGING_HIGH,LOGGING_DEBUG} LoggingDetail;
// Enable Logging and if so, which detail (default = none)
static LoggingDetail g_LoggingDetail = LOGGING_NONE;
static wchar_t g_LogPath[MAX_PATH + 1] = {0};
static const wchar_t g_LOG_FILE_NAME[] = L"ButtonHook.log"; // Log File for now is just hardcoded
//////////////////////////////////////////////////////////////////////
//********************************************************************
// Global Functions
//********************************************************************
//////////////////////////////////////////////////////////////////////
// Logs to Ooganizer.log in temporary folder if no log path is set
// %USERPROFILE%\AppData\Local\Temp\Ooganizer.log
//void log(LoggingDetail detail, char * pFmt, ... );
void log( LoggingDetail detail, HWND hWnd, wchar_t* str); // Logs Window Text
void log( LoggingDetail detail, wchar_t * pFmt, ... );
// At Startup we clear the log
void clearLog();
// Set the global (for this dll instance) Logging Detail Setting
void SetLoggingDetail(LoggingDetail detail, wchar_t* logPath);
// Get Logging Detail for custom debug behavior
_LoggingDetail GetLoggingDetail();

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,171 @@
#pragma once
#include "thread.h"
#ifdef _DEBUG
#import "..\\..\\Target\\Debug\\ButtonWPForm.tlb"
#else
#import "..\\..\\Target\\Release\\ButtonWPForm.tlb"
#endif
using namespace ButtonWPForm;
namespace Ooganizer
{
enum BUTTON_STATE
{
// These are the states that coincide with the states defined
// in ButtonWPFormCCW
BUTTON_NONE = 1,
BUTTON_DOWN = 2, // BUTTON_ADD
BUTTON_TOGGLED = 3, // BUTTON_DELETE
// Button Up is the Hover image (Used on Mouse Over),
// it is NOT DEFINED in BHInteracter
BUTTON_UP = 1000
};
////
// ButtonThemeSetting, this static holds our current Button Theme Setting
// ~This structure can be reloaded when a ThemeChange occured (WM_THEMECHANGED)
////
struct ButtonThemeSetting
{
// Init Flags
bool bIsInitialized;
bool bIsChanged;
// Int Button Dimension/Location
long Top;
long Right;
long Height;
long Width;
// String Button Locations
_bstr_t bstrBUTTON_UP;
_bstr_t bstrBUTTON_DOWN;
_bstr_t bstrTOGGLE_UP;
ButtonThemeSetting()
{
Top = 0;
Right = 0;
Height = 0;
Width = 0;
bIsInitialized = false;
bIsChanged = false;
}
};
class CWHPaccess;
class WPFCaller;
#define BLANK_HookWndItem(n) HookWndItem n = {NULL,NULL,NULL,NULL}
//////////////////////////////////////////////////////////////////////
// Strc: HookWndItem
// Desc: Hook Item is used in the HookedWndList. Each HookWndItem keeps track
// of all the addresses needed for each hook for each Windows,
// as well as each Window's WPFCaller.
//////////////////////////////////////////////////////////////////////
struct HookWndItem
{
HWND hWnd;
WNDPROC HookWndProc;
WNDPROC DefWndProc;
WPFCaller* wpfcaller;
};
//////////////////////////////////////////////////////////////////////
// Clss: WPFCaller
// Desc: This class is responsible for overriding wndproc draw routines
// and communicate to the WPF COM object
//////////////////////////////////////////////////////////////////////
class WPFCaller : Thread
{
public:
// All Windows Messages *Except NCDestroy & UnHook* enter here
virtual LRESULT OnDefault (HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam);
WPFCaller(HookWndItem Item, HINSTANCE hInstance);
~WPFCaller();
// Each WPFCaller is mapped to a HookWndItem (Hooked Window)
HWND m_hWnd;
WNDPROC m_HookWndProc;
WNDPROC m_DefWndProc;
HINSTANCE m_hInst;
// Window W32 State Settings
// ~we are keeping track of the Hooked W32 sizes
int m_wndHeight;
int m_wndWidth;
RECT m_wndRECT;
// We need to keep track of the Button State in order
// to know what to draw
BUTTON_STATE m_ButtonState;
BUTTON_STATE m_ButtonToggledState; // We can overwrite buttonDown state
// with another state. this allows us to
// specify which state to use to overwrite.
BUTTON_STATE m_ButtonStateLastSaved;
BUTTON_STATE m_ButtonToggledStateLastSaved;
bool m_bButtonIsArtificiallyHidden_MOVE;
bool m_bButtonIsMinimized;
bool m_bButtonIsBeingRestored;
// Transparency / Fade Effect
BYTE GetAlpha();
void SetAlpha(BYTE bAlpha);
void StartRestoreEventFadeTimer();
// Client Events
void StartCloseButNotDestroyTimer();
int m_StartCloseButNotDestroyTimerCount;
// Drag N' Dropped Files
int m_nDragDroppedFilesCount;
_bstr_t m_bstrDragDroppedFilesSemiColonSep;
// OpenFile or FileSaveAs Dialog Prms Passing
wchar_t m_strFileNameLocationBuf[MAX_PATH + 1];
wchar_t m_strFileTypesBuf[MAX_PATH + 1];
// WPFProc Will load the Button Settings via COM which
// we'll use to draw the Icon
ButtonThemeSetting m_ButtonThemeSetting;
// Window Handles
HWND m_hwndWPForm; // passed back to us by ButtonWPForm
HWND m_hwndW32Window; // our w32 Button
// ThreadStuff (WPFComThread)
bool m_bThreadIsReady;
HANDLE m_thread;
DWORD m_threadID;
private:
// OnDefault() uses this function to possible send messages
// to the EventDispatcher in C# for further processing
void EventDispatcherHandler(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam);
// We don't need to right now, but we may need it more in the future.
// Office passes in startup file prms via DDE (other apps may too)
void HandleDDEMessages(HWND hWnd, UINT Msg,WPARAM wParam,LPARAM lParam);
// Win32 Button Window * Created for better speed *
// Responsible for setting up the WNDCLASSEX struct and register the Window
BOOL InitApplication(HINSTANCE hInstance);
// Responsible for Creating and Showing a new Window Class Instance
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow);
// Thread Entry
int WINAPI threadproc(HINSTANCE hinstance, HINSTANCE hPrevInstance, void* vArg, int nCmdShow);
// Thread Entry
virtual DWORD Run(LPVOID vArg)
{
return(threadproc(m_hInst,NULL,vArg,TRUE));
}
};
}

View File

@@ -0,0 +1,15 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by ButtonHook.rc
//
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

100
Hooks/ButtonHook/thread.h Normal file
View File

@@ -0,0 +1,100 @@
#pragma once
namespace Ooganizer
{
// Generic Thread Class!
class Thread
{
public:
// Starts the thread
// This function starts the thread pointed by m_pThreadFunc with default attributes
DWORD Start( void* arg = NULL )
{
m_ThreadCtx.m_pUserData = arg;
m_ThreadCtx.m_hThread = CreateThread(NULL, 0, m_pThreadFunc, this, 0, &m_ThreadCtx.m_dwTID);
m_ThreadCtx.m_dwExitCode = (DWORD)-1;
return GetLastError();
}
// Stops the thread.
// This function stops the current thread
DWORD Stop ( bool bForceKill = false )
{
log(LOGGING_HIGH, L"Hidden Wnd Thread Stopped()");
if ( m_ThreadCtx.m_hThread )
{
GetExitCodeThread(m_ThreadCtx.m_hThread, &m_ThreadCtx.m_dwExitCode);
if ( m_ThreadCtx.m_dwExitCode == STILL_ACTIVE && bForceKill )
TerminateThread(m_ThreadCtx.m_hThread, DWORD(-1));
m_ThreadCtx.m_hThread = NULL;
}
return m_ThreadCtx.m_dwExitCode;
}
// Returns Thread Exit Code
DWORD GetExitCode() const
{
if ( m_ThreadCtx.m_hThread )
GetExitCodeThread(m_ThreadCtx.m_hThread, (LPDWORD)&m_ThreadCtx.m_dwExitCode);
return m_ThreadCtx.m_dwExitCode;
}
// Attaches a Thread Function
// Used primarily for porting but can serve in developing generic thread objects
void Attach( LPTHREAD_START_ROUTINE lpThreadFunc ){
m_pThreadFunc = lpThreadFunc;
}
// Detaches the Attached Thread Function
// Detaches the Attached Thread Function, If any.
void Detach( void ){
m_pThreadFunc = Thread::EntryPoint;
}
Thread(){ m_pThreadFunc = Thread::EntryPoint; /*Can call Detach Also*/ }
//plug-in constructor
Thread(PTHREAD_START_ROUTINE lpExternalRoutine){Attach(lpExternalRoutine);}
~Thread(){ if(m_ThreadCtx.m_hThread) Stop(true);}
protected:
// Std Template: Override if you are sure of what you are doing
static DWORD WINAPI EntryPoint( LPVOID pArg)
{
Thread *pParent = reinterpret_cast<Thread*>(pArg);
pParent->ThreadCtor();
pParent->Run( pParent->m_ThreadCtx.m_pUserData );
pParent->ThreadDtor();
return STILL_ACTIVE;
}
// Override this method with the body/code of your thread
virtual DWORD Run( LPVOID /*arg */){return m_ThreadCtx.m_dwExitCode;}
// override this function to provide your extra initialization
virtual void ThreadCtor(){}
// Override this function to provide your extra destruction
virtual void ThreadDtor(){}
////
// Thread Context Inner Class (UserData Pointer, Handle, Thread ID)
////
class CThreadContext
{
public:
CThreadContext(){memset(this, 0, sizeof(this));}
// Attributes
public:
HANDLE m_hThread; // The Thread Handle
DWORD m_dwTID; // The Thread ID
LPVOID m_pUserData; // The user data pointer
LPVOID m_pParent; // The this pointer of the parent CThread object
DWORD m_dwExitCode; // The Exit Code of the thread
} m_ThreadCtx; // The Thread Context Member
LPTHREAD_START_ROUTINE m_pThreadFunc; // The Worker Thread Function Pointer
};
}