Click here to Skip to main content
15,897,334 members
Articles / Desktop Programming / Win32

Selection Overlay DLL

Rate me:
Please Sign up or sign in to vote.
5.00/5 (7 votes)
18 Jun 2012Public Domain9 min read 31.8K   832   17  
API which shows a Selection Overlay and notifies the caller when it's resizing and notifies the final rectangle.
#ifndef SELECTION_OVERLAY
#define SELECTION_OVERLAY

/*
 *   Used tools/technics:
 *
 *   Reduced DLL Size with LIBCTINY.LIB  
 *
 *   Src: MSDN Oktober 2001, Under The Hood: Reduce EXE and DLL Size with LIBCTINY.LIB 
 *
 *   Reduced Release DLL Size even further with making use of UPX (Flags -9 --best)
 *
 *   Src: Http://upx.sourceforge.net
 *
 *   Vorlath - Project V: Advanced Alpha Blending
 *
 *   Src: Http://my.opera.com/Vorlath/blog/2006/12/20/project-v-advanced-alpha-blending
 */

#ifdef SELECTIONOVERLAY_EXPORTS
#define SELECTIONOVERLAY_API __declspec(dllexport)
#else
#define SELECTIONOVERLAY_API __declspec(dllimport)
#endif

/*
 * Our window procedure notification identifiers
 */
typedef enum tagSelectionOverlayNotifications
{
	/*
	 * Will be sent when:
	 * On each mouse movement which causes an selection overlay window change
	 *
	 * hWnd:	Handle of recieving window
	 * Message: WM_ONMOVE
	 * wParam:	Tag supplied in SELECTIONOVERLAYDATA
	 * lParam	RECT of Selection Overlay on screen
	 */
	WM_ONMOVE = 0x4235,

	/*
	 * Will be sent when:
	 * After the mouse button went up and the selection overlay is closing
	 *
	 * hWnd:	Handle of recieving window
	 * Message: WM_ONEND
	 * wParam:	Tag supplied in SELECTIONOVERLAYDATA
	 * lParam	RECT of Selection Overlay on screen
	 *
	 * On no movement the rect will contain alls nills
	 */
	WM_ONEND,

	/*
	 * Will be sent when:
	 * Selection Overlay 32 bit bitmap (alpha colors) is being drawn,
	 * On returning 1 drawing of DLL will be skipped and assumed,
	 * user has filled the bitmap.
	 *
	 * hWnd:	Handle of recieving window
	 * Message: WM_ON_FILL_ALPHA
	 * wParam:	Tag supplied in SELECTIONOVERLAYDATA
	 * lParam	hBitmap (DIB)
	 *
	 */
	WM_ON_FILL_ALPHA,

	/*
	 * Will be sent when:
	 * In the occations 32 bitmap alpha is not possible.
	 * On returning 1 drawing of DLL will be skipped and assumed,
	 * user has filled the DC.
	 *
	 * hWnd:	Handle of recieving window
	 * Message: WM_ONEND
	 * wParam:	SizeTag (see tagSizeTag)
	 * lParam	hDC
	 *
	 * On no movement the rect will contain alls nills
	 */
	WM_ON_FILL_RGB
} SelectionOverlayNotifications;

typedef struct tagSize
{
	short Width;
	short Height;
} Size;

typedef struct tagSizeTag
{
	Size  Size;
	void* Tag;
} SizeTag;

/*
 * Mouse Button we can operate with
 */
typedef enum tagVKKeys
{
	LBUTTON		= 1,					//Left Mouse button
	RBUTTON		= 2,					//Right Mouse button
	MBUTTON		= 4,					//Middle Mouse button
	XBUTTON1	= 5,					//The first x mouse button (five-button mouse)
	XBUTTON2	= 6						//The second x mouse button (five-button mouse)
} VKKeys;

typedef struct tagSELECTIONOVERLAYDATA
{
	HWND		Parent;					//HWND where the selection overlay should stay above
	COLORREF	OverlayColor;			//Color of the main square
	COLORREF	BorderColor;			//Color of the border
	long		BorderWidth;			//Width (in pixels) of the border
	BYTE		AlphaLevel;				//Transparency alpha level of the main square (in case alpha blending per pixel fails will also be applied on border)
	BYTE		BorderAlphaLevel;		//Transparency alpha level of the border
	void*		Tag;					//Tag, will be passed through onto the WM_ONMOVE and WM_ONEND notification
	VKKeys		ButtonLead;				//Which mouse button we operate with (on start this mouse button must be in down state), if 0 will be directed to LBUTTON
	HWND		Listener;				//HWND reciever of our notifcations on 0 will be redirected to Parent
} SELECTIONOVERLAYDATA;


/*
 * Shows an selection overlay as long as the required mouse button is still down
 * Rectangle adjusts on mouse movement
 *
 * Incoming: Specification for our selection overlay
 */
SELECTIONOVERLAY_API void _stdcall SelectionOverlay(SELECTIONOVERLAYDATA& Data);

/*
 * Callback variant
 */
typedef void _stdcall OnMove(void* Tag, RECT Overlay);
typedef void _stdcall OnEnd(void* Tag, RECT Overlay);
typedef bool _stdcall OnFillAlpha(void* Tag, HBITMAP BitmapDIBHandle);
typedef bool _stdcall OnFillRGB(void* Tag, HDC hDC, int Width, int Height);

typedef struct tagSELECTIONOVERLAYDATA_CB
{
	HWND			Parent;				//HWND where the selection overlay should stay above
	COLORREF		OverlayColor;		//Color of the main square
	COLORREF		BorderColor;		//Color of the border
	long			BorderWidth;		//Width (in pixels) of the border
	BYTE			AlphaLevel;			//Transparency alpha level of the main square (in case alpha blending per pixel fails will also be applied on border)
	BYTE			BorderAlphaLevel;	//Transparency alpha level of the border
	void*			Tag;				//Tag, will be passed through onto the WM_ONMOVE and WM_ONEND notification
	VKKeys			ButtonLead;			//Which mouse button we operate with (on start this mouse button must be in down state), if 0 will be directed to LBUTTON
	long			Dummy;				//Unused in our callback version, implemented to be compatible for our normal variant
	OnMove*			Move;				//Function callback may be 0
	OnEnd*			EndCall;			//Function callback MANDATORY
	OnFillAlpha*	FillAlpha;			//Function callback to draw the 32 alpha bitmap yourself
	OnFillRGB*		FillRgb;			//Function callback to draw the hdc yourself in case 32 alpha bitmap drawing fails
} SELECTIONOVERLAYDATA_CB;

SELECTIONOVERLAY_API void _stdcall SelectionOverlay(SELECTIONOVERLAYDATA_CB& Data);

/*
 * Callback to C++ Class Interface
 */
class ISelectionOverlay
{
public:
	virtual bool OnFillAlpha(void* Tag, HBITMAP BitmapDIBHandle) { return false; }
	virtual bool OnFillRGB(void* Tag, HDC hDC, int Width, int Height) { return false; }
	virtual void OnMove(void* Tag, RECT Overlay){}
	virtual void OnEnd(void* Tag, RECT Overlay) = 0;
};

typedef struct tagSELECTIONOVERLAYDATA_CLASS
{
	HWND				Parent;			//HWND where the selection overlay should stay above
	COLORREF			OverlayColor;	//Color of the main square
	COLORREF			BorderColor;	//Color of the border
	long				BorderWidth;	//Width (in pixels) of the border
	BYTE				AlphaLevel;		//Transparency alpha level of the main square (in case alpha blending per pixel fails will also be applied on border)
	BYTE				BorderAlphaLevel;//Transparency alpha level of the border
	ISelectionOverlay*	Destination;	//Object to be called MANDATORY
	VKKeys				ButtonLead;		//Which mouse button we operate with (on start this mouse button must be in down state), if 0 will be directed to LBUTTON
} SELECTIONOVERLAYDATA_CLASS;

SELECTIONOVERLAY_API void _stdcall SelectionOverlay(SELECTIONOVERLAYDATA_CLASS& Data);


/*
 * ClientRect versions of the api-calls above,
 * instead of the call supplying the client rect where the overlay needs to 
 * stay between (screen coordinates), u supply them yourself.
 */
typedef struct tagSELECTIONOVERLAYRECT
{
	RECT		ClientRect;				//Rectangle on the desktop we have to stay between
	HWND		Parent;					//HWND where the selection overlay belongs to
	COLORREF	OverlayColor;			//Color of the main square
	COLORREF	BorderColor;			//Color of the border
	long		BorderWidth;			//Width (in pixels) of the border
	BYTE		AlphaLevel;				//Transparency alpha level of the main square (in case alpha blending per pixel fails will also be applied on border)
	BYTE		BorderAlphaLevel;		//Transparency alpha level of the border
	void*		Tag;					//Tag, will be passed through onto the WM_ONMOVE and WM_ONEND notification
	VKKeys		ButtonLead;				//Which mouse button we operate with (on start this mouse button must be in down state), if 0 will be directed to LBUTTON
	HWND		Listener;				//HWND reciever of our notifcations on 0 will be redirected to Parent
} SELECTIONOVERLAYRECT;

SELECTIONOVERLAY_API void _stdcall SelectionOverlay(SELECTIONOVERLAYRECT& Incoming);

typedef struct tagSELECTIONOVERLAYRECT_CB
{
	RECT			ClientRect;			//Rectangle on the desktop we have to stay between
	HWND			Parent;				//HWND where the selection overlay belongs to
	COLORREF		OverlayColor;		//Color of the main square
	COLORREF		BorderColor;		//Color of the border
	long			BorderWidth;		//Width (in pixels) of the border
	BYTE			AlphaLevel;			//Transparency alpha level of the main square (in case alpha blending per pixel fails will also be applied on border)
	BYTE			BorderAlphaLevel;	//Transparency alpha level of the border
	void*			Tag;				//Tag, will be passed through onto the WM_ONMOVE and WM_ONEND notification
	VKKeys			ButtonLead;			//Which mouse button we operate with (on start this mouse button must be in down state), if 0 will be directed to LBUTTON
	long			Dummy;				//Unused in our callback version, implemented to be compatible for our normal variant
	OnMove*			Move;				//Function callback may be 0
	OnEnd*			EndCall;			//Function callback MANDATORY
	OnFillAlpha*	FillAlpha;			//Function callback to draw the 32 alpha bitmap yourself
	OnFillRGB*		FillRgb;			//Function callback to draw the hdc yourself in case 32 alpha bitmap drawing fails
} SELECTIONOVERLAYRECT_CB;

SELECTIONOVERLAY_API void _stdcall SelectionOverlay(SELECTIONOVERLAYRECT_CB& Incoming);

typedef struct tagSELECTIONOVERLAYRECT_CLASS
{
	RECT				ClientRect;		//Rectangle on the desktop we have to stay between
	HWND				Parent;			//HWND where the selection overlay should stay above
	COLORREF			OverlayColor;	//Color of the main square
	COLORREF			BorderColor;	//Color of the border
	long				BorderWidth;	//Width (in pixels) of the border
	BYTE				AlphaLevel;		//Transparency alpha level of the main square (in case alpha blending per pixel fails will also be applied on border)
	BYTE				BorderAlphaLevel;//Transparency alpha level of the border
	ISelectionOverlay*	Destination;	//Object to be called MANDATORY
	VKKeys				ButtonLead;		//Which mouse button we operate with (on start this mouse button must be in down state), if 0 will be directed to LBUTTON
} SELECTIONOVERLAYRECT_CLASS;

SELECTIONOVERLAY_API void _stdcall SelectionOverlay(SELECTIONOVERLAYRECT_CLASS& Incoming);

/*
 * Creates an Alpha Color from a RGB value together with alpha level
 *
 * Color: RGB Value
 * Alpha: Alpha level
 *
 * Returns: Alpha Color
 */
SELECTIONOVERLAY_API COLORREF _stdcall CreateAlphaColor(COLORREF Color, unsigned char Alpha);
#endif SELECTION_OVERLAY

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions