Getpixel and push button. - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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 Posts: 3,711Member
    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 Posts: 3Member
    : 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 Posts: 6,519Member
    : 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.