Projects

Find all our projects in development below.
All source code is GNU General Public License (GPL)

Red Dot Plus

Browsing reddotplus.cpp (6.49 KB)



#include <windows.h>
#include <winuser.h>
//#include <stdio.h>
//#include <stdlib.h>

#define WIN32_LEAN_AND_MEAN

#define IDC_STATIC 1000

static HINSTANCE hInstance = NULL;
char szClassName[] = "RedDotPlus";

static HWND hwndMain;
static HWND hwndStatic;

int iAtom_SmallRedDot = 0;
int iAtom_MedRedDot = 0;
int iAtom_LargeRedDot = 0;
int iAtom_NoRedDot = 0;
int iAtom_TerminateRedDot = 0;

const int DrawRedDotTimerID = 100;
int iDrawRedDotTimer = 0;

int ScreenWidth = 0;
int ScreenHeight = 0;

HBRUSH DrawBrush = CreateSolidBrush(RGB(255,0,0));

RECT DrawRectV[3];
RECT DrawRectH[3];

int DrawRectIndex = 1;

HDC ScreenDC = NULL;


void SetRect(RECT rc, int X, int Y, int CX, int CY)
{
	rc.left = X;
	rc.top = Y;
	rc.right = CX;
	rc.bottom = CY;
}

void SetDrawRects()
{
	SetRect(&DrawRectV[0], (ScreenWidth/2)-2, (ScreenHeight/2)-1, (ScreenWidth/2)+2, (ScreenHeight/2)+1);
	SetRect(&DrawRectH[0], (ScreenWidth/2)-1, (ScreenHeight/2)-2, (ScreenWidth/2)+1, (ScreenHeight/2)+2);
	SetRect(&DrawRectV[1], (ScreenWidth/2)-3, (ScreenHeight/2)-2, (ScreenWidth/2)+3, (ScreenHeight/2)+2);
	SetRect(&DrawRectH[1], (ScreenWidth/2)-2, (ScreenHeight/2)-3, (ScreenWidth/2)+2, (ScreenHeight/2)+3);
	SetRect(&DrawRectV[2], (ScreenWidth/2)-4, (ScreenHeight/2)-3, (ScreenWidth/2)+4, (ScreenHeight/2)+3);
	SetRect(&DrawRectH[2], (ScreenWidth/2)-3, (ScreenHeight/2)-4, (ScreenWidth/2)+3, (ScreenHeight/2)+4);
}

void UnregisterHotkeys()
{
	UnregisterHotKey(hwndMain, iAtom_SmallRedDot);
    GlobalDeleteAtom(iAtom_SmallRedDot);
    UnregisterHotKey(hwndMain, iAtom_MedRedDot);
    GlobalDeleteAtom(iAtom_MedRedDot);
    UnregisterHotKey(hwndMain, iAtom_LargeRedDot);
    GlobalDeleteAtom(iAtom_LargeRedDot);
    UnregisterHotKey(hwndMain, iAtom_NoRedDot);
    GlobalDeleteAtom(iAtom_NoRedDot);
	UnregisterHotKey(hwndMain, iAtom_TerminateRedDot);
    GlobalDeleteAtom(iAtom_TerminateRedDot);
}

bool MutexExists(char * pMutexName)
{
	// Attempt to create defualt mutex owned by process
	CreateMutex(NULL, true, pMutexName);

	// Check success
	if (GetLastError() == ERROR_ALREADY_EXISTS)
		// Mutex was not created
		return true;
	else
		// Mutex was created
		return false;
}

void SetDefaultFont(int identifier, HWND hwnd){
    SendDlgItemMessage(hwnd, identifier, WM_SETFONT,
		(WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0));
}

HWND CreateStaticEx(char* tempText, int x, int y, int width, int height,
				  int identifier, HWND hwnd){
    HWND hStaticTemp;
    
    hStaticTemp = CreateWindowEx(0, "STATIC", tempText, WS_CHILD | WS_VISIBLE, 
		x, y, width, height, hwnd, (HMENU)identifier, hInstance, NULL);
	// set the font
	SetDefaultFont(identifier, hwnd);
    return hStaticTemp;
}

LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, 
								 WPARAM wParam, LPARAM lParam){
	switch(message){

	case WM_CREATE:
		// create a static label
		hwndStatic = CreateStaticEx("RedDotPlus written in C++", 
			6, 6, 180, 20, IDC_STATIC, hwnd);

		break;

	case WM_HOTKEY:
		if((int)wParam == iAtom_SmallRedDot)
		{
			DrawRectIndex = 0;
			if(iDrawRedDotTimer == 0) iDrawRedDotTimer = SetTimer(hwndMain, DrawRedDotTimerID, 1, NULL);
		}
		if((int)wParam == iAtom_MedRedDot)
		{
			DrawRectIndex = 1;
			if(iDrawRedDotTimer == 0) iDrawRedDotTimer = SetTimer(hwndMain, DrawRedDotTimerID, 1, NULL);
		}
		if((int)wParam == iAtom_LargeRedDot)
		{
			DrawRectIndex = 2;
			if(iDrawRedDotTimer == 0) iDrawRedDotTimer = SetTimer(hwndMain, DrawRedDotTimerID, 1, NULL);
		}
		if((int)wParam == iAtom_NoRedDot)
		{
			if(iDrawRedDotTimer)
			{
				iDrawRedDotTimer = KillTimer(hwndMain, DrawRedDotTimerID);
				iDrawRedDotTimer = 0;
			}
		}
		if((int)wParam == iAtom_TerminateRedDot)
		{
			DestroyWindow(hwndMain);
		}
		break;

	case WM_DISPLAYCHANGE:
		ScreenWidth = LOWORD(lParam);
		ScreenHeight = HIWORD(lParam);
		SetDrawRects();
		break;

	case WM_TIMER:
		if(wParam == DrawRedDotTimerID)
		{
			ScreenDC = GetDC(NULL);
			FillRect(ScreenDC, &DrawRectV[DrawRectIndex], DrawBrush);
			FillRect(ScreenDC, &DrawRectH[DrawRectIndex], DrawBrush);
			ReleaseDC(NULL, ScreenDC);
		}
		break;

	case WM_DESTROY:
		UnregisterHotkeys();
		DeleteObject(DrawBrush);
		if(iDrawRedDotTimer) iDrawRedDotTimer = KillTimer(hwndMain, DrawRedDotTimerID);
		PostQuitMessage(0);
		break;

	default:
		return DefWindowProc(hwnd, message, wParam, lParam);
		break;
	}
	return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
				   LPSTR lpszArgument, int nCmdShow){
	
	if (MutexExists("RedDotPlus"))
	{
		MessageBox(NULL, "RedDotPlus is already running!", "RedDot Drawing System", MB_OK | MB_ICONERROR);
		return 0;
	}

	// set parameters for the main window
	MSG messages;
	WNDCLASSEX wincl;
	wincl.hInstance = hInstance;
	wincl.lpszClassName = szClassName;
	wincl.lpfnWndProc = WindowProcedure; 
	wincl.style = CS_DBLCLKS;
	wincl.cbSize = sizeof(WNDCLASSEX);
	wincl.hIcon = LoadIcon(NULL, IDI_WINLOGO);
	wincl.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
	wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
	wincl.lpszMenuName = NULL;
	wincl.cbClsExtra = 0;
	wincl.cbWndExtra = 0;
	wincl.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
	
	if(!RegisterClassEx(&wincl)) return 0;
	
	// create the main window
	hwndMain = CreateWindowEx(
		0,
		szClassName,
		"",
		WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		200,
		80,
		HWND_DESKTOP,
		NULL,
		hInstance,
		NULL
		);
	
	// show the window
	//ShowWindow(hwnd, nCmdShow);

	RECT rc;
	GetWindowRect(GetDesktopWindow(), &rc);

	ScreenWidth = rc.right;
	ScreenHeight = rc.bottom;

	SetDrawRects();

	iAtom_SmallRedDot = GlobalAddAtom("SmallRedDot Hotkey");
	RegisterHotKey(hwndMain, iAtom_SmallRedDot, MOD_SHIFT, VK_F1);

	iAtom_MedRedDot = GlobalAddAtom("MedRedDot Hotkey");
	RegisterHotKey(hwndMain, iAtom_MedRedDot, MOD_SHIFT, VK_F2);

	iAtom_LargeRedDot = GlobalAddAtom("LargeRedDot Hotkey");
	RegisterHotKey(hwndMain, iAtom_LargeRedDot, MOD_SHIFT, VK_F3);

	iAtom_NoRedDot = GlobalAddAtom("NoRedDot Hotkey");
	RegisterHotKey(hwndMain, iAtom_NoRedDot, MOD_SHIFT, VK_F4);

	iAtom_TerminateRedDot = GlobalAddAtom("TerminateRedDot Hotkey");
	RegisterHotKey(hwndMain, iAtom_TerminateRedDot, MOD_SHIFT | MOD_CONTROL, VK_F4);

	iDrawRedDotTimer = SetTimer(hwndMain, DrawRedDotTimerID, 1, NULL);

	while(GetMessage(&messages, NULL, 0, 0))
	{
		TranslateMessage(&messages);
		DispatchMessage(&messages);
	}

	return messages.wParam;
}

Download reddotplus.cpp

Back to file list


Back to project page