0

I'm sorry if a similar post exists but I couldn't find it. I have been learning to use the windows.h library for 2 days. I have problems with the GetPixel function returns 0 on google chrome but returns the good values on applications installed on my computer. Here is my code:

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



void handleGame(HWND& _window) {
    LPCWSTR windowClass = L"Chrome_WidgetWin_1";
    LPCWSTR windowName = L"Stack Overflow - Where Developers Learn, Share, & Build Careers - Google Chrome";
    _window = FindWindow(windowClass, windowName);
    while (_window == NULL) {
        std::cout << "failed" << std::endl;
        _window = FindWindow(windowClass, windowName);
        Sleep(1000);
    }
}
int main() {
    HWND window = NULL;
    while (true)
    {
        handleGame(window);
        
    
        if (GetAsyncKeyState(VK_NUMPAD1)) {

            HDC hdc = GetDC(window);
            COLORREF color;
            COLORREF characteristic_color = 5460819;
            RECT rect = {};
            GetClientRect(window, &rect);

            for (int i = rect.left; i < rect.right; i++) {
                for (int j = rect.top; j < rect.bottom; j++) {
                    color = GetPixel(hdc, i, j);
                    std::cout << color << std::endl;
                    if (color == characteristic_color) {
                        std::cout << "FOUND!" << std::endl;
                        SetCursorPos(i, j);
                        ReleaseDC(window, hdc);
                        break;
                    }
                }
            }

            ReleaseDC(window, hdc);
            std::cout << "not found..!" << std::endl;
            break;
            
            
        }
    }
    std::cout << "end" << std::endl;
    return 0;
}

I tried to follow some tutorials and I search several hours for this problem but I can't find a good answer. I have seen the BITMAP structure but I don't know how to use it and I don't think it will solve my problem. For example my code works well on "paint" but there is a bug on google chrome.

I tried to use the mouse to get the pixel but it returns 0 too. I tried to use the function GetDC(NULL) and it works well, but I need to get just the window of the web browser, not all my screen. The goal of the program is to find a specific COLORREF but it returns always 0 on google chrome.

I apologize for my ignorance and hope someone can help me!

Thank you!

PsyKozZ09
  • 21
  • 3

0 Answers0