I am using the following code and it's working perfectly for windows XP.
The game I am creating this for is known as Dransik.
What this does is when I my character gets poisoned. My program automatically cures
this issue using basic macro's.
The problem is my program is not working for vista.
In my code below. My HWND is initialized to the games window, and then sends keys using sendmessage\postmessage. It does everything perfectly on XP.
Whenever I close the games window my program displays a message box saying the games window has been closed, and it terminates itself.
On vista my user reports nothing is working at all other than a message box stating this program runs invisible. No keys are sent to the game on vista, the auto healing is not working etc..
It seems to be a problem with FindWindow. I am not sure whats going on here. I get no error message stating the game window cannot be found or meaning FindWindow failed.
What am I doing wrong ? ignore the additional headers I was troubleshooting code and so forth.
#include <windows.h>
#include <stdlib.h>
#include <Winuser.h>
#include <iostream>
//#include "DC.h"
//DC dc;
HWND hwndDC = FindWindow(0,"Dransik (c)opyright 2010 Iron Will Games, LLC.");
HDC hdcDC = GetDC(hwndDC);
COLORREF cr;
COLORREF cr2;
COLORREF cr3;
COLORREF cr4;
static COLORREF crGetHit = RGB(252,252,84);
static COLORREF crCheckMark = RGB(40,184,28);
static COLORREF crGreaterHeal = RGB(172,172,172);
static COLORREF crMassScroll = RGB(236,124,124);
static COLORREF NeedHeal = RGB(0,0,0);
static COLORREF crChatPoisoned = RGB(0,252,0);
// Get color for CR chat diseased when possible
static COLORREF crPoisoned = RGB(184,240,148);
static COLORREF crDiseased = RGB(200,176,136);
static COLORREF crMinorCure = RGB(240,112,0);
static COLORREF Cure = RGB(208,192,156);
static COLORREF RedDot = RGB(255,0,0);
static int my = 175;
int CurePot();
int MinorCurePot();
int MassHeal();
int CheckChatBox();
int CheckBody();
int GreaterHeal();
int CheckForHit();
int TurnOffReuse();
////////////////Start of Windows Main /////////////////////////
int main()
{
SetWindowPos(hwndDC, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
BringWindowToTop(hwndDC);
ShowWindow(hwndDC,SW_SHOW);
///////ERROR CHECK TO SEE IF DRANSIK WINDOW IS OPEN
if(hwndDC == 0)
{
MessageBox(hwndDC,"Dransik Window Is not open program is terminating","v1.2 by: MANEGARD", MB_OK|MB_ICONINFORMATION);
return 0;
};
TurnOffReuse();
MessageBox(hwndDC,"AUTO CURE\\HEALER note: This runs invisible","v1.2 by: MANEGARD", MB_OK|MB_ICONINFORMATION);
////////////Forever Loop /////////////////////
for(;;)
{
HWND hwndDC = FindWindow(0, "Dransik (c)opyright 2010 Iron Will Games, LLC.");
if(hwndDC == 0)
{
MessageBox(hwndDC,"Dransik Window Is Not Open Program is Closing","v1.2 by: MANEGARD", MB_OK|MB_ICONINFORMATION);
return 0;
};
CheckChatBox();
CheckChatBox();
CheckBody();
CheckForHit();
// MassHeal(); //<---- This need not be commented out if used for mage
};
end:
return 0;
};
/////////////////BELOW IS ALL THE FUNCTION DEFINITIONS
int CurePot()
{
for(int bpy = 150; bpy != 400; bpy++)
{
for(int bpx = 350; bpx != 480; bpx++)
{
cr = GetPixel(hdcDC,bpx,bpy);
if(cr == Cure)
{
SendMessage(hwndDC,WM_LBUTTONDBLCLK,0,MAKELPARAM(bpx,bpy));
SendMessage(hwndDC,WM_LBUTTONDOWN,0,MAKELPARAM(bpx,bpy));
SendMessage(hwndDC,WM_LBUTTONUP,0,MAKELPARAM(bpx,bpy));
Sleep(800);
GreaterHeal();
return 0;
};
//SetPixel(hdcDC,bpx,bpy,RedDot);
};
};
return 0;
};
int MinorCurePot()
{
for(int bpy = 150; bpy != 400; bpy++)
{
for(int bpx = 350; bpx != 480; bpx++)
{
cr = GetPixel(hdcDC,bpx,bpy);
if(cr == crMinorCure)
{
SendMessage(hwndDC,WM_LBUTTONDBLCLK,0,MAKELPARAM(bpx,bpy));
SendMessage(hwndDC,WM_LBUTTONDOWN,0,MAKELPARAM(bpx,bpy));
SendMessage(hwndDC,WM_LBUTTONUP,0,MAKELPARAM(bpx,bpy));
GreaterHeal();
return 0;
};
//SetPixel(hdcDC,bpx,bpy,RedDot);
};
};
return 0;
};
/* //OBSOLETE CODE UNLESS USING FOR MAGE SCROLL SEARCH\MASS HEAL
int MassHeal()
{
cr4 = GetPixel(hdcDC,347,100);
if(cr4 == NeedHeal)
{
for(int bpmhy = 150; bpmhy != 400; bpmhy++)
{
for(int bpmhx = 350; bpmhx != 480; bpmhx++)
{
cr2 = GetPixel(hdcDC,bpmhx,bpmhy);
if(cr2 == RGB(236,124,124)) //Mass Scroll Color
{
SendMessage(hwndDC,WM_LBUTTONDBLCLK,0,MAKELPARAM(bpmhx,bpmhy));
};
//SetPixel(hdcDC,bpx,bpy,RedDot);
};
};
};
return 0;
};
*/
int GreaterHeal()
{
cr4 = GetPixel(hdcDC,347,80); //Check energy bar for energy level
if(cr4 == NeedHeal)
{
for(int bpmhy = 150; bpmhy != 400; bpmhy++)
{
for(int bpmhx = 350; bpmhx != 480; bpmhx++)
{
cr2 = GetPixel(hdcDC,bpmhx,bpmhy);
if(cr2 == crGreaterHeal) //Greater Heal potion color
{
SendMessage(hwndDC,WM_LBUTTONDBLCLK,0,MAKELPARAM(bpmhx,bpmhy));
Sleep(600);
SendMessage(hwndDC,WM_LBUTTONDBLCLK,0,MAKELPARAM(bpmhx,bpmhy));
Sleep(400);
SendMessage(hwndDC,WM_LBUTTONDBLCLK,0,MAKELPARAM(bpmhx,bpmhy));
Sleep(300);
SendMessage(hwndDC,WM_LBUTTONDOWN,0,MAKELPARAM(bpmhx,bpmhy));
SendMessage(hwndDC,WM_LBUTTONUP,0,MAKELPARAM(bpmhx,bpmhy));
return 0;
};
//SetPixel(hdcDC,bpx,bpy,RedDot);
};
};
};
return 0;
};
int CheckForHit()
{
//////////Checks for body flash
for(int mx = 170; mx <= 180; mx++)
{
cr = GetPixel(hdcDC,mx,my);
if(cr == crGetHit)
{
//Use Minor Cure Potion
GreaterHeal();
return 0;
};
//SetPixel(hdcDC,mx,my,RedDot);
};
return 0;
};
int CheckBody()
{
//////////Checks for body flash
for(int mx = 170; mx <= 180; mx++)
{
cr = GetPixel(hdcDC,mx,my);
if(cr == crPoisoned || cr == crDiseased) //For ripper avatar cannot add cdDiseased or runs in loop
{
//Use Minor Cure Potion
MinorCurePot();
CurePot();
GreaterHeal();
return 0;
};
//SetPixel(hdcDC,mx,my,RedDot);
};
return 0;
};
int CheckChatBox()
{
//Check chat box for disease message
for(int y = 350; y <= 470; y++)
{
for(int x = 10; x<= 150; x++)
{
cr3 = GetPixel(hdcDC,x,y);
if(cr3 == crChatPoisoned)
{
MinorCurePot();
CurePot();
GreaterHeal();
return 0;
};
if(cr3 == crDiseased)
{
CurePot();
GreaterHeal();
return 0;
};
//SetPixel(hdcDC,x,y,RedDot);
};
};
return 0;
};
int TurnOffReuse()
{
SetWindowPos(hwndDC, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
Sleep(500);
PostMessage(hwndDC,WM_KEYDOWN,VK_ESCAPE,0);
PostMessage(hwndDC,WM_KEYUP,VK_ESCAPE,0);
Sleep(300);
for(int i=0; i != 500;i++)
{
for(int my = 152; my <= 159; my++)
{
for(int mx = 355; mx <= 370;mx++)
{
cr = GetPixel(hdcDC,mx,my);
if(cr == crCheckMark)
{
//Send Click to Uncheckmark the box
Sleep(800);
SendMessage(hwndDC,WM_LBUTTONDOWN,0,MAKELPARAM(mx,my));
SendMessage(hwndDC,WM_LBUTTONUP,0,MAKELPARAM(mx,my));
};
//SetPixel(hdcDC,mx,my,RedDot);
};
};
if(i == 500)
{
i = 0;
goto next;
};
};
next:
for(int i=0; i != 500;i++)
{
for(int my = 70; my <= 78; my++)
{
for(int mx = 520; mx <= 535;mx++)
{
cr = GetPixel(hdcDC,mx,my);
if(cr == crCheckMark)
{
//Send Click to Uncheckmark the box
Sleep(800);
SendMessage(hwndDC,WM_LBUTTONDOWN,0,MAKELPARAM(mx,my));
SendMessage(hwndDC,WM_LBUTTONUP,0,MAKELPARAM(mx,my));
};
//SetPixel(hdcDC,mx,my,RedDot);
};
};
if(i == 500)
{
i = 0;
goto next1;
};
};
next1:
Sleep(1000);
Sleep(300);
PostMessage(hwndDC,WM_KEYDOWN,VK_ESCAPE,0);
Sleep(300);
PostMessage(hwndDC,WM_KEYUP,VK_ESCAPE,0);
return 0;
};