Code:
#include <windows.h>
#include "resource.h"
#include <stdio.h> //for sprintf - puts integers into strings
#define UFOVTIMER 1
BOOL CALLBACK DialogProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK AboutProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char * cmdParam, int cmdShow);
char buffer[11]; //used for lots of things
int onoff = 0; //whether the Scope is on
HINSTANCE hInst;
HDC ScreenDC;
HWND g_hwnd;
COLORREF pixelcolour1, pixelcolour2, pixelcolourFF = RGB(0,0,0);
int rc1, gc1, bc1, rc2, gc2, bc2 , errorcode;
//--------------------------------------------------------------------------------------------
BOOL CALLBACK DialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
SetDlgItemText(hwnd, IDC_STATUS, "Inactive");
SetDlgItemText(hwnd, IDC_HOTKEY, "F12");
SetTimer(hwnd, UFOVTIMER, 200, NULL);
g_hwnd = hwnd;
return TRUE;
}
case WM_TOGGLE:
{
if(onoff)
{
SetDlgItemText(hwnd, IDC_STATUS, "Inactive");
ReleaseDC(GetForegroundWindow(), ScreenDC);
onoff = 0;
//sprintf(buffer, "%i", errorcode);
//MessageBox(NULL, buffer, "NOTE", MB_OK);
sprintf(buffer, "red %i", rc1);
MessageBox(NULL, buffer, "NOTE", MB_OK);
sprintf(buffer, "green %i", gc1);
MessageBox(NULL, buffer, "NOTE", MB_OK);
sprintf(buffer, "blue %i", bc1);
MessageBox(NULL, buffer, "NOTE", MB_OK);
}
else
{
SetDlgItemText(hwnd, IDC_STATUS, "Active");
ScreenDC = GetDC(GetForegroundWindow());
onoff = 1;
}
SetTimer(g_hwnd, UFOVTIMER, 200, NULL); //slow so toggle block does not run millions of times with one press
return TRUE;
}
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDQUIT:
{
PostQuitMessage(0);
break;
}
case IDCANCEL:
{
PostQuitMessage(0);
break;
}
case IDABOUT:
{
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hwnd, (DLGPROC)AboutProc);
break;
}
case IDC_HOTKEY:
{
break;
}
} //switch loword(wParam)
return TRUE;
} //case WM_COMMAND
case WM_QUIT:
{
KillTimer(g_hwnd, UFOVTIMER);
ReleaseDC(GetForegroundWindow(), ScreenDC);
EndDialog(g_hwnd,NULL);
return TRUE;
}
case WM_TIMER:
{
switch(wParam)
{
case UFOVTIMER:
{
if(onoff)
{
pixelcolourFF = GetPixel(ScreenDC, (GetDeviceCaps(ScreenDC,HORZRES) / 2) -2, (GetDeviceCaps(ScreenDC,VERTRES) / 2) -1);
rc1 = (int)GetRValue(pixelcolourFF);
gc1 = (int)GetGValue(pixelcolourFF);
bc1 = (int)GetBValue(pixelcolourFF);
if((rc1 < 256) && (rc1 > 180) && (gc1 < 11) && (gc1 >= 0) && (bc1 < 11) && (bc1 >= 0)) //if centre is red then break;
{
MessageBox(NULL,"RED!!!", "NOTE", MB_OK);
mouse_event(MOUSEEVENTF_LEFTDOWN, 1, 1, 0,0);
return TRUE;
}
} //if(onoff)
if(GetFocus() == g_hwnd) //check if the keyboard focus is on our dialog. GetFocus returns null if focus is on another application, inwhich case we set the focus to our dialog
{
SetFocus(g_hwnd); //so the async thingy will work
}
if(GetAsyncKeyState(VK_F12))
{
SendMessage(g_hwnd, WM_TOGGLE,0,0);
}
else
{
SetTimer(hwnd, UFOVTIMER, 1, NULL); //to send the next timer message - fast so that drawing on screen is good
}
} //case UFOVTIMER
} //switch(wParam)
} //case WM_TIMER
} //(switch(message)
return FALSE;
}
//--------------------------------------------------------------------------------------------
BOOL CALLBACK AboutProc(HWND habout, UINT message, WPARAM wParam, LPARAM lParam) //message handler for the about box
{
switch(message)
{
case WM_COMMAND:
{
if (LOWORD(wParam) == IDOK || IDCANCEL)
{
EndDialog(habout, LOWORD(wParam));
return TRUE;
}
return FALSE;
}
}
return FALSE;
}
//--------------------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char * cmdParam, int cmdShow)
{
DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG), 0, (DLGPROC)DialogProc);
return TRUE;
}
That message box stuff in WM_TOGGLE is how i check the GetRValue return values.