I need to use the GetRValue macro but it gives me the wrong values. Same with the GetBValue and GetGValue. They all give me 255 as the colour value which is totally wrong. Any ideas?
This is a discussion on GetRValue within the Windows Programming forums, part of the Platform Specific Boards category; I need to use the GetRValue macro but it gives me the wrong values. Same with the GetBValue and GetGValue. ...
I need to use the GetRValue macro but it gives me the wrong values. Same with the GetBValue and GetGValue. They all give me 255 as the colour value which is totally wrong. Any ideas?
Chances are you are passing the wrong values....Originally posted by cppdude
I need to use the GetRValue macro but it gives me the wrong values. Same with the GetBValue and GetGValue. They all give me 255 as the colour value which is totally wrong. Any ideas?
You would normally pass a COLORREF into each of these macros and in return you would get an 8bit BYTE valure representing the colour value......
Can you give a little more code to show what you are really doing?
COLORREF rc1 = GetRValue(pixelcolourFF);
COLORREF gc1 = GetGValue(pixelcolourFF);
COLORREF bc1 = GetBValue(pixelcolourFF);
that is what i was doing
No.....pass the COLORREF into the Macro;
The return is an 8bit variable (BYTE) which of course only had 256 possible values...this is each individual colourCode:COLORREF myColAbsolute = RGB(35,56,97);//Create a defined colourref cout << "Red - " << (int)GetRValue(myColAbsolute) << endl; cout << "Green - " << (int)GetGValue(myColAbsolute) << endl; cout << "Blue - " << (int)GetBValue(myColAbsolute) << endl;
hang on sorry - that wasnt what i was doing. I was doing this:
int rc1 = GetRValue(myCOLORREF);
and it doesnt work.
yes you guys are meant to reply to this plz. I keep getting the wrong int R or G or B integer.
Oh...I thought this was sorted......Originally posted by cppdude
yes you guys are meant to reply to this plz. I keep getting the wrong int R or G or B integer.
I suggest you post more code to give an idea where this could be failing....
ScreenDC = GetDC(GetForegroundWindow()); //during initialisation - get a DC to the game window
pixelcolourFF = GetPixel(ScreenDC, (GetDeviceCaps(ScreenDC,HORZRES) / 2) -2, (GetDeviceCaps(ScreenDC,VERTRES) / 2) -1); //during a WM_TIMER message
int rc1 = GetRValue(pixelcolourFF); //also during WM_TIMER to check for target
int gc1 = GetGValue(pixelcolourFF);
int bc1 = GetBValue(pixelcolourFF);
/* as you might have guessed this is for an autofire bot. I check the int values and they are all 255 all the time. very frustrating.
Have you tried casting the actual return as I did in my example earlier?
I havent tested it mind you...give it a go and come back with the resultCode:ScreenDC = GetDC(GetForegroundWindow()); //during initialisation - get a DC to the game window pixelcolourFF = GetPixel(ScreenDC, (GetDeviceCaps(ScreenDC,HORZRES) / 2) -2, (GetDeviceCaps(ScreenDC,VERTRES) / 2) -1); //during a WM_TIMER message int rc1 = (int)GetRValue(pixelcolourFF); //also during WM_TIMER to check for target int gc1 = (int)GetGValue(pixelcolourFF); int bc1 = (int)GetBValue(pixelcolourFF);
made no difference. GetRValue( returns an iteger anyway so the int cast is pointless. should i post my entire code? its not that long.
No....GetRValue returns a BYTE....not an int......Originally posted by cppdude
made no difference. GetRValue( returns an iteger anyway so the int cast is pointless. should i post my entire code? its not that long.
Ah well...yeah you could post the code...the I will try load it and have a closer look
That message box stuff in WM_TOGGLE is how i check the GetRValue return values.Code:#include <windows.h> #include "resource.h" #include <stdio.h> //for sprintf - puts integers into strings #define UFOVTIMER 1 BOOL CALLBACK DialogProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); BOOL CALLBACK AboutProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char * cmdParam, int cmdShow); char buffer[11]; //used for lots of things int onoff = 0; //whether the Scope is on HINSTANCE hInst; HDC ScreenDC; HWND g_hwnd; COLORREF pixelcolour1, pixelcolour2, pixelcolourFF = RGB(0,0,0); int rc1, gc1, bc1, rc2, gc2, bc2 , errorcode; //-------------------------------------------------------------------------------------------- BOOL CALLBACK DialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: { SetDlgItemText(hwnd, IDC_STATUS, "Inactive"); SetDlgItemText(hwnd, IDC_HOTKEY, "F12"); SetTimer(hwnd, UFOVTIMER, 200, NULL); g_hwnd = hwnd; return TRUE; } case WM_TOGGLE: { if(onoff) { SetDlgItemText(hwnd, IDC_STATUS, "Inactive"); ReleaseDC(GetForegroundWindow(), ScreenDC); onoff = 0; //sprintf(buffer, "%i", errorcode); //MessageBox(NULL, buffer, "NOTE", MB_OK); sprintf(buffer, "red %i", rc1); MessageBox(NULL, buffer, "NOTE", MB_OK); sprintf(buffer, "green %i", gc1); MessageBox(NULL, buffer, "NOTE", MB_OK); sprintf(buffer, "blue %i", bc1); MessageBox(NULL, buffer, "NOTE", MB_OK); } else { SetDlgItemText(hwnd, IDC_STATUS, "Active"); ScreenDC = GetDC(GetForegroundWindow()); onoff = 1; } SetTimer(g_hwnd, UFOVTIMER, 200, NULL); //slow so toggle block does not run millions of times with one press return TRUE; } case WM_COMMAND: { switch (LOWORD(wParam)) { case IDQUIT: { PostQuitMessage(0); break; } case IDCANCEL: { PostQuitMessage(0); break; } case IDABOUT: { DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hwnd, (DLGPROC)AboutProc); break; } case IDC_HOTKEY: { break; } } //switch loword(wParam) return TRUE; } //case WM_COMMAND case WM_QUIT: { KillTimer(g_hwnd, UFOVTIMER); ReleaseDC(GetForegroundWindow(), ScreenDC); EndDialog(g_hwnd,NULL); return TRUE; } case WM_TIMER: { switch(wParam) { case UFOVTIMER: { if(onoff) { pixelcolourFF = GetPixel(ScreenDC, (GetDeviceCaps(ScreenDC,HORZRES) / 2) -2, (GetDeviceCaps(ScreenDC,VERTRES) / 2) -1); rc1 = (int)GetRValue(pixelcolourFF); gc1 = (int)GetGValue(pixelcolourFF); bc1 = (int)GetBValue(pixelcolourFF); if((rc1 < 256) && (rc1 > 180) && (gc1 < 11) && (gc1 >= 0) && (bc1 < 11) && (bc1 >= 0)) //if centre is red then break; { MessageBox(NULL,"RED!!!", "NOTE", MB_OK); mouse_event(MOUSEEVENTF_LEFTDOWN, 1, 1, 0,0); return TRUE; } } //if(onoff) if(GetFocus() == g_hwnd) //check if the keyboard focus is on our dialog. GetFocus returns null if focus is on another application, inwhich case we set the focus to our dialog { SetFocus(g_hwnd); //so the async thingy will work } if(GetAsyncKeyState(VK_F12)) { SendMessage(g_hwnd, WM_TOGGLE,0,0); } else { SetTimer(hwnd, UFOVTIMER, 1, NULL); //to send the next timer message - fast so that drawing on screen is good } } //case UFOVTIMER } //switch(wParam) } //case WM_TIMER } //(switch(message) return FALSE; } //-------------------------------------------------------------------------------------------- BOOL CALLBACK AboutProc(HWND habout, UINT message, WPARAM wParam, LPARAM lParam) //message handler for the about box { switch(message) { case WM_COMMAND: { if (LOWORD(wParam) == IDOK || IDCANCEL) { EndDialog(habout, LOWORD(wParam)); return TRUE; } return FALSE; } } return FALSE; } //-------------------------------------------------------------------------------------------- int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char * cmdParam, int cmdShow) { DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG), 0, (DLGPROC)DialogProc); return TRUE; }
Can you post the resource too.....
Hmm....havent worked out your code yet totally....
But I added a little error error catch;
And the messagebox apperaed....therefore the error is most likely not with GetRValue and the others..........Code:if(pixelcolourFF == CLR_INVALID) MessageBox(0,"Invalid","",MB_OK);
I will try to look further to catch the error.....but you would use time more wisely to look at other possible errors