开发者

can't find what's wrong with my code :(

开发者 https://www.devze.com 2022-12-27 13:41 出处:网络
the point of my code is for me to press f1 and it will scan 500 pixels down and 500 pixels and put them in a array (it just takes a box that is 500 by 500 of the screen). then after that when i hit en

the point of my code is for me to press f1 and it will scan 500 pixels down and 500 pixels and put them in a array (it just takes a box that is 500 by 500 of the screen). then after that when i hit end it will click on only on the color black or... what i set it to. anyway it has been doing odd stuff and i can't find why:

#include <iostream>
#include <windows.h>

using namespace std;

COLORREF rgb[499][499];
HDC hDC = GetDC(HWND_DESKTOP);

POINT main_coner;

BYTE rVal;
BYTE gVal;
BYTE bVal;

int red;  
int green;
int blue; 

int ff = 0;

int main()
{
for(;;)
{
    if(GetAsyncKeyState(VK_F1))
    {
        cout << "started";
        int a1 = 0;
        int a2 = 0;

        GetCursorPos(&main_coner);

        int x = main_coner.x;
        int y = main_coner.y;

        for(;;)
        {
            //cout << a1 << "___" << a2 << "\n";
            rgb[a1][a2] = GetPixel(hDC, x, y);
            a1++;
            x++;

            if(x > main_coner.x + 499)
            {
                y++;
                x = main_coner.x;
                a1 = 0;
                a2++;

            }
            if(y > main_coner.y + 499)
            {
                ff = 1;
                break;
            }
        }

        cout << "done";
        break;
    }
    if(ff == 1)
      break;

}

for(;;)
{
        if(GetAsyncKeyState(VK_END))
        {
            GetCursorPos(&main_coner);

            int x = main_coner.x;
            int y = main_coner.y;

            int a1 = -1;
            int a2 = -1;

            for(;;)
            {
                x++;
                a1++;
                rVal = GetRValue(rgb[a1][a2]);
                gVal = GetGValue(rgb[a1][a2]);
                bVal = GetBValue(rgb[a1][a2]);

                red   = (int)rVal;   // get the colors into __int8
                green = (int)gVal;   // get the colors into __int8
                blue  = (int)bVal;   // get the colors into __int8

                if(red == 0 && green == 0 && blue == 0)
                {

                    SetCursorPos(main_coner.x + x, main_coner.y + y);

                    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                    Sleep(10);
                    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
                    Sleep(100);

                }

                if(x > main_coner.x + 499)
                {
                    a1 = 0;
                    a2++;
                }

                if(y > main_coner.y + 499)
                {
   开发者_如何学Go                 Sleep(100000000000);

                    break;
                }
                if(GetAsyncKeyState(VK_CONTROL))
                {
                    Sleep(100000);
                    break;
                }

            }

        }
}

for(;;)
{


    if(GetAsyncKeyState(VK_END))
    {
        break;
    }

}

return 0;
}

anyone see what's wrong with my code :( (feel free to add tags)


If you want your rgb array to have 500x500 entries (numbered [0][0] to [499][499]), you'll need to declare it as COLORREF rgb[500][500];

Also, make sure you don't try to access rgb[a1][a2] where a2 == -1

0

精彩评论

暂无评论...
验证码 换一张
取 消