Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Getpixel and push button.

Hi. I'm trying to make a program that will push a virtual button if a certain pixel has a certain color.

The problem I got is that it only works sometimes. Is it because my function is too slow or why does this happend? Really annoying.

Check out my code:
[code]#include "stdafx.h"
using namespace std;

void findPic();
void hittaPixel();

int _tmain(int argc, _TCHAR* argv[])
{
findPic();
}

void findPic()
{
BYTE redValue = 0;

HDC hDDC = GetDC( GetDesktopWindow() );
HDC hCDC = CreateCompatibleDC(hDDC);

while (true)
{
HBITMAP hBitmap = CreateCompatibleBitmap(hDDC, 1600, 1200);
SelectObject(hCDC,hBitmap);
BitBlt(hCDC, 949, 794, 2, 2, hDDC, 949, 794, SRCCOPY|CAPTUREBLT);

//GetPixel f

Comments

  • LundinLundin Member Posts: 3,711
    I'm just guessing here, but I suspect it is because the desktop might not be the Windows that has focus. keybd_event doesn't know about such, it is a low-level function. Try SetFocus and see if it solves anything.
  • fragmadfragmad Member Posts: 3
    : I'm just guessing here, but I suspect it is because the desktop
    : might not be the Windows that has focus. keybd_event doesn't know
    : about such, it is a low-level function. Try SetFocus and see if it
    : solves anything.

    I'm always keeping my window as the top window. It's so weird, it works about 60% of the time..? :o
  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : Hi. I'm trying to make a program that will push a virtual button if
    : a certain pixel has a certain color.
    :
    : The problem I got is that it only works sometimes. Is it because my
    : function is too slow or why does this happend? Really annoying.
    :
    : Check out my code:
    : [code]: #include "stdafx.h"
    : using namespace std;
    :
    : void findPic();
    : void hittaPixel();
    :
    : int _tmain(int argc, _TCHAR* argv[])
    : {
    : findPic();
    : }
    :
    : void findPic()
    : {
    : BYTE redValue = 0;
    :
    : HDC hDDC = GetDC( GetDesktopWindow() );
    : HDC hCDC = CreateCompatibleDC(hDDC);
    :
    : while (true)
    : {
    : HBITMAP hBitmap = CreateCompatibleBitmap(hDDC, 1600, 1200);
    : [color=Red]HGDIOBJ h1=[/color]SelectObject(hCDC,hBitmap);
    : BitBlt(hCDC, 949, 794, 2, 2, hDDC, 949, 794, SRCCOPY|CAPTUREBLT);
    :
    : //GetPixel f
Sign In or Register to comment.