Hi! I'm trying to make a program that detects a pixel color at the mouse position but it always returns 4294967. I've tried making clipping regions and bitmaps but I don't know if I'm doing it properly or I've somehow offended GetPixel() and now it is doing this to spite me. Just WHAT IS WRONG WITH MY CODE? Sorry and thank you for any help! - #include <iostream>
-
#include <Windows.h> // Sleep, GetAsyncKeyState, etc.
-
#include <Windef.h>
-
//#include <opencv2\opencv.hpp>
-
-
using namespace std;
-
-
int main() {
-
while (true) {
-
-
LPCWSTR window_title = L"World of Warcraft";
-
HWND hWND = FindWindow(NULL, window_title);
-
-
-
RECT rWindow;
-
RECT rClient;
-
-
HRGN hRgnWindow;
-
HRGN hRgnClient;
-
HRGN hNCRgn;
-
-
//C: Get the window and client rectangles for the window.
-
GetWindowRect(hWND, &rWindow);
-
GetClientRect(hWND, &rClient);
-
-
//C: Translate the Client rectangle into screen coordinates.
-
POINT p = { 0,0 };
-
MapWindowPoints(hWND, NULL, &p, 1);
-
OffsetRect(&rClient, p.x, p.y);
-
-
//C: Create regions from these two rectangles.
-
hRgnWindow = ::CreateRectRgnIndirect(&rWindow);
-
hRgnClient = ::CreateRectRgnIndirect(&rClient);
-
hNCRgn = ::CreateRectRgn(0, 0, 0, 0);
-
-
//C: Subtract the client region from the window region.
-
CombineRgn(hNCRgn, hRgnWindow, hRgnClient, RGN_DIFF);
-
-
while (hWND == NULL) {
-
hWND = FindWindowA(NULL, "World of Warcraft");
-
cout << "start game!" << endl;
-
Sleep(1000);
-
}
-
Sleep(10);
-
if (GetAsyncKeyState(VK_SHIFT)) { // MousePosition
-
//HDC hDC = GetDC(hWND);
-
POINT p;
-
GetCursorPos(&p);
-
ScreenToClient(hWND, &p); // actually only needs window title not HDC but will need for color
-
//ReleaseDC(hWND, hDC);
-
cout << "(" << p.x << ","<< p.y << ")" << endl;
-
Sleep(1000);
-
}
-
Sleep(10);
-
if (GetAsyncKeyState(VK_LBUTTON)) { // pixelColor
-
HDC hDC, hCDC;
-
HBITMAP hbwin;
-
HRGN RrGN = CreateRectRgn(30, 5, 1277, 690);
-
int height, width;
-
hDC = GetDC(hWND);
-
hCDC = CreateCompatibleDC(hDC);
-
SetStretchBltMode(hCDC, COLORONCOLOR);
-
-
RECT winsize;
-
GetClientRect(hWND, &winsize);
-
SetWindowRgn(hWND, RrGN, TRUE);
-
SelectClipRgn(hDC, RrGN);
-
GetClipRgn(hDC, RrGN);
-
-
POINT p;
-
GetCursorPos(&p);
-
-
hbwin = CreateCompatibleBitmap(hDC, p.x, p.y);
-
SelectObject(hCDC, hbwin);
-
-
COLORREF color = GetPixel(hCDC, p.x, p.y);
-
-
cout << " | Color: " << color << endl;
-
/*cout<< //"(" << p.x << "," << p.y << ")" << " R: " << (int)GetRValue(color)
-
<< " | G: " << (int)GetGValue(color) << " | B: "
-
<< (int)GetBValue(color) << endl;
-
BOOL EndPaint(hWND, CONST PAINTSTRUCT * lp);*/
-
Sleep(10);
-
cout << " | Color: " << color << endl;
-
DeleteObject(hbwin);
-
DeleteDC(hCDC);
-
ReleaseDC(hWND, hDC);
-
DeleteObject(RrGN);
-
Sleep(1000);
-
}
-
/*if (GetAsyncKeyState(VK_CONTROL)) {
-
HDC hDC = GetDC(hWND);
-
COLORREF color; //could have the choice of which zone or
-
COLORREF characteristic_ color = ; //color of fishing bobber? --> How to find in different zones
-
Sleep(1000);
-
}*/
-
if (GetAsyncKeyState(VK_MENU)) { // Exit Game
-
return 0;
-
}
-
DeleteObject(hRgnWindow);
-
DeleteObject(hRgnClient);
-
DeleteObject(hNCRgn);
-
}
-
return 0;
-
-
}
0 1671 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rene van Hoek |
last post by:
Hi,
I am using Xalan 1.8.0 and Xerces 2.6.0 in C++.
I have an XML document which I first transform into an other XML
document using an XSL styelsheet. Then I want to parse with
XPathEvaluator...
|
by: Sergio Geralnik |
last post by:
I am trying to use this method to get a MethodInfo object
but the method always returns a null.
See my sample code below:
this.button1 = new System.Windows.Forms.Button();
this.button1.Click +=...
|
by: Aslam |
last post by:
We have an abstract class FieldBase and FooFieldBase is extended from FieldBase
We are checking, if the FooFieldBase is a subclass of FieldBase with the following line of code
return...
|
by: Brian |
last post by:
This is causing me to not be able to create a relation in my dataset.
Here's my code:
dc1 = ds.Tables .Columns ;
dc2 = ds.Tables .Columns ;
dr1 = new System.Data.DataRelation...
|
by: Tim |
last post by:
Hello All,
I am writing a program that checks for the NumLock status and turns the NumLock on if it is off.
I'm not sure what I'm overlooking at this point, but the code will compile and run, but...
|
by: Tim |
last post by:
Hello All,
I am writing a program that checks for the NumLock status and turns the NumLock on if it is off.
I'm not sure what I'm overlooking at this point, but the code will compile and run, but...
|
by: Lyle Fairfield |
last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp
"If the value of the variant argument is Null, the Nz function returns
the number zero or a...
|
by: Joe Rattz |
last post by:
I am trying to create an XmlReader using XmlReader.Create, but it always
returns {None}. I have tried several examples from the web, and Create
always returns "{None}".
Here is my code:
...
|
by: Michi Henning |
last post by:
I'm running the following code in Safari 2.0.4:
document.cookie = 'MyCookie=1';
if(document.cookie == '')
alert('document.cookie is empty!');
document.cookie always returns the empty string,...
|
by: yogeshmk |
last post by:
I'm writing an application which is required to function with many
languages and also compile on Linux & windows. Here's how I find the
locale ..
# include <stdio.h>
# include <locale.h>
int...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |